Arimaa Forum (http://arimaa.com/arimaa/forum/cgi/YaBB.cgi)
Arimaa >> Bot Development >> Chimaera : An Arimaa engine written in C#
(Message started by: chimaera on Nov 10th, 2009, 6:10pm)

Title: Chimaera : An Arimaa engine written in C#
Post by chimaera on Nov 10th, 2009, 6:10pm
http://www.wwddfd.com/arimaa/

I have been working on an Arimaa game-playing engine in C#. The engine is pretty much feature-complete, and I've moved on to the API and GUI. I've already implemented a basic GUI. I've just obtained a license from Omar Syed, so I'm releasing it to the world for the first time today. This project is provided with the written authorization of Arimaa.com and in compliance with Section III of the Arimaa Public License.

Here's a screenshot of my (primitive) GUI. Notice how it depicts frozen pieces and shows legal moves for the selected piece.
http://www.wwddfd.com/arimaa/guisample1.png

And here's a list of all the "illegal move" reasons (the game can tell you exactly why a move is illegal - see the screenshot above - notice how it doesn't even offer Eg3n as a valid move).


Code:
msExplanations[(int)ae.InvalidMove.Null] = "";
msExplanations[(int)ae.InvalidMove.GameStateInvalid] = "The Game state is invalid.";
msExplanations[(int)ae.InvalidMove.MoveObjectInvalid] = "The Move object is invalid.";
msExplanations[(int)ae.InvalidMove.OutOfTurn] = "It is not your turn to move.";
msExplanations[(int)ae.InvalidMove.CannotMoveEnemyPiece] = "You cannot move this enemy piece.";
msExplanations[(int)ae.InvalidMove.InvalidStartPosition] = "The intended start position of this piece is invalid.";
msExplanations[(int)ae.InvalidMove.PieceNotFound] = "The indicated piece was null or not found.";
msExplanations[(int)ae.InvalidMove.OriginSquareNotFound] = "The origin square of the move was null or not found.";
msExplanations[(int)ae.InvalidMove.DestinationSquareNotFound] = "The destination square of the move was null or not found.";
msExplanations[(int)ae.InvalidMove.OriginSquareIncorrect] = "The residing square of the piece did not agree with the origin square of the move.";
msExplanations[(int)ae.InvalidMove.SquaresNotAdjacent] = "The origin and destination squares are not adjacent.";
msExplanations[(int)ae.InvalidMove.DestinationSquareOccupied] = "The destination square is currently occupied.";
msExplanations[(int)ae.InvalidMove.InsufficientMovesRemaining] = "Not enough moves remaining in turn to complete this move.";
msExplanations[(int)ae.InvalidMove.MustFollowThroughOnPush] = "You must follow through on the in-progress push by moving into the square vacated by the enemy piece.";
msExplanations[(int)ae.InvalidMove.PieceFrozen] = "The piece you are attempting to move is frozen in place by an adjacent enemy piece.";
msExplanations[(int)ae.InvalidMove.PieceTypeMovementRestricted] = "The piece you are attempting to move is not allowed to move in that direction.";
msExplanations[(int)ae.InvalidMove.CannotPushEnemyPieceWithThisPiece] = "You cannot follow through on the push with this piece, because it is too weak.";
msExplanations[(int)ae.InvalidMove.NoAdjacentPiecesCanPushThisPiece] = "There are no adjacent pieces capable of pushing the enemy piece that you are trying to move.";
msExplanations[(int)ae.InvalidMove.AllAdjacentPiecesForPushingAreFrozen] = "All adjacent pieces capable of pushing this piece are currently frozen.";
msExplanations[(int)ae.InvalidMove.CannotRepeatPreviousBoardPosition] = "You cannot make this move because it would repeat a previous board position an illegal number of times.";
msExplanations[(int)ae.InvalidMove.MustChangeBoardPosition] = "You cannot make this move because it would duplicate the board position from the beginning of your turn.";


The engine was written in C# and runs under version 2.0 of the .NET framework. I have tested it under the latest Mono runtime and it works (although it's ugly when running in Mono under Linux due to bad drawing of the PNG's alpha channels). It looks a lot better in Windows at the moment. The GUI is very rough, anyway (and probably very inefficient); it's intended only to demonstrate the features of the game-playing engine. I didn't implement bitboards or anything like that; the engine is designed to be very easy to understand and use, and anyone with a bit of know-how should be able to radically alter many of the rules with minimal effort.

Keep in mind that this is alpha-quality and I have a lot of work left to do.

The GUI "game" is at "Chimaera/Chimaera/bin/Release/Chimaera.exe" Extract all files from the zip archive to test it out (it needs to load some settings and graphics).

The project ZeroGravitas is the actual game engine.

The project NUnitZeroGravitas is a series of NUnit test cases to test the game engine's respect for the rules of Arimaa.

The "TestZeroGravitas" project crashes when you run it, but it's designed to do that. It's what I use to step through my NUnit test cases as I'm writing them. The particular test case it runs at the moment is the 3-move repeat rule. The engine throws an exception when the test tries to make an illegal move.

Title: Re: Chimaera : An Arimaa engine written in C#
Post by Fritzlein on Nov 10th, 2009, 6:30pm
Awesome.  Thank you for contributing your GUI to the community.

How does the Arimaa Public License work if someone wishes to improve/extend what you have done?

Title: Re: Chimaera : An Arimaa engine written in C#
Post by chimaera on Nov 10th, 2009, 6:39pm
My project is open source within the limits of the Arimaa Public License. If someone wishes to extend the project and distribute their changes, they will have to either submit their changes to me or obtain a separate written license from Omar Syed.

It may be legally possible for you to diff your source files against my base files and distribute the diff (much as the LAME mp3 encoder started out as a diff against the ISO mp3 encoder's source).

Title: Re: Chimaera : An Arimaa engine written in C#
Post by chimaera on Nov 10th, 2009, 7:05pm
Oh, and I just noticed that one of the NUnit test cases fails because I recently implemented a new check when attempting to end a turn early. I think the engine is actually correct and the moves I am making in the test case are wrong.

Title: Re: Chimaera : An Arimaa engine written in C#
Post by omar on Nov 10th, 2009, 10:11pm
Wow, the GUI looks very nice. Are you using the AEI to communicate between the GUI and the game engine?

Title: Re: Chimaera : An Arimaa engine written in C#
Post by chimaera on Nov 11th, 2009, 2:49pm
I haven't implemented an API for communication yet. The GUI is just loading the game engine's DLL, creating a "Game" object, and calling functions on it directly. I've been busy lately and haven't made many improvements in the past few weeks, but I'll try to do some more work on it now that I can distribute it.

Title: Re: Chimaera : An Arimaa engine written in C#
Post by Janzert on Nov 11th, 2009, 9:41pm
I'd be glad to give any help you need with understanding AEI. A GUI that can use AEI is something I would really like to see. I've actually started a writing one a few times, but the combination of a) I do this for fun and b) I really can't stand GUI programming means I've never completed anything.

Janzert

Title: Re: Chimaera : An Arimaa engine written in C#
Post by omar on Nov 12th, 2009, 12:30pm
If you have the GUI use the AEI then other developers will also be able to use it to control their engines.

Title: Re: Chimaera : An Arimaa engine written in C#
Post by chimaera on Nov 12th, 2009, 3:02pm
My main concern up to this point has been tweaking the game-playing engine. I'll start looking into AEI this weekend.

Title: Re: Chimaera : An Arimaa engine written in C#
Post by FireBorn on Nov 12th, 2009, 5:20pm
I like this engine because it checks for illegal moves and stuff. I couldn't figure out if the gameroom does that, but I think it just forfeits the game when it receives an illegal move. This engine will be helpful for evolving my bots.

Do other bot developers write their own representation of the game and its rules in order to generate and play legal moves? That seems like a lot of unnecessarily repeated work. If so, this engine could save a lot of time and effort for new developers. Thanks, Chimaera!

Title: Re: Chimaera : An Arimaa engine written in C#
Post by omar on Nov 12th, 2009, 7:44pm

on 11/12/09 at 17:20:54, FireBorn wrote:
Do other bot developers write their own representation of the game and its rules in order to generate and play legal moves? That seems like a lot of unnecessarily repeated work. If so, this engine could save a lot of time and effort for new developers. Thanks, Chimaera!

Developers often write their own bots from scratch. There are several sample bots available on the downloads page and some developers have used these also.

I just added Chimaera to the downloads page.

Scott, have you tried compiling Chimaera under linux yet?

Title: Re: Chimaera : An Arimaa engine written in C#
Post by chimaera on Nov 12th, 2009, 7:47pm

on 11/12/09 at 19:44:59, omar wrote:
Scott, have you tried compiling Chimaera under linux yet?


Yes, and it works great aside from the lack of alpha blending on the PNG images I'm using (probably due to the retarded way I'm drawing the screen - using a grid of PictureBox objects). It's targeting the .NET 2.0 platform, which is almost perfectly supported by Mono.

Title: Re: Chimaera : An Arimaa engine written in C#
Post by chimaera on Nov 12th, 2009, 9:27pm
I have updated the zip on my site with a few fixes to the repeat-rule checking and game initialization. I'll be spending the next few days trying to improve the GUI (so you can start with a blank board and place pieces) and looking into the AEI protocol.

Title: Re: Chimaera : An Arimaa engine written in C#
Post by camelback on Nov 16th, 2009, 8:47pm
Very nice GUI, thanks chimaera

Title: Re: Chimaera : An Arimaa engine written in C#
Post by omar on Nov 24th, 2009, 1:00pm

on 11/12/09 at 19:47:07, chimaera wrote:
It's targeting the .NET 2.0 platform, which is almost perfectly supported by Mono.


Cool. I'll try compiling it on Aamir's ubuntu system.



Arimaa Forum » Powered by YaBB 1 Gold - SP 1.3.1!
YaBB © 2000-2003. All Rights Reserved.