[ProgClub list] ai-checkers in jj5-test
sanguinev at progsoc.org
sanguinev at progsoc.org
Wed Oct 19 16:09:22 AEDT 2011
-----BEGIN PGP SIGNED MESSAGE-----
On 16/10/2011 9:01 PM, John Elliot wrote:
> On 16/10/2011 4:04 PM, sanguinev at progsoc.org wrote:
>> I don't have time to read the code in detail (specially with limited
> Well I've commented the code now, so you can't use that as your only
> You might need to press Ctrl+F5 in your browser to force a reload of
that web page. The caching seems to be fairly aggressive in ViewVC.
I can always find more excuses to avoid getting too involved in said
project. The comments have helped understand what is going on, but my
interest in solving the problem in C is not so great.
> This is a pretty good excuse to learn a little about C. If you're
interested in working on the code what I'm up to is:
> * determining if 'jumps' can be made, and if so requiring them as the
> * making sure that after a jump that you jump again if you can during
your current move
> Those two things are each a little tricky and will require a
remodelling of the code. I have four passing unit tests that test for
simple moves, and one failing test that tests for a complicated king
jump (that is test_5).
I decided to play around a little myself and see what I could code up in
OCaml. I haven't commented because (i) I'm lazy about commenting my own
code, and (ii) I have tried to make it fairly readable, and (iii) I am
going to mention the "interesting" functions here. Code is available at:
The board is modelled as a 32 element array of pieces (Empty '.', Red
'x', RedKing 'X', White 'o', WhiteKing 'O'). You can obtain an
"emptyboard()" and then "setpiece board position piece", or have the
starting board via "startboard()". Also finding what piece is at a
position is "getpiece board position". (Note that positions are 0-31 and
run left-to-right then top-to-bottom.)
If you want you can use "board2string board" to convert to a string and
"parseboard str" to turn a string into a board. "printboard board"
displays a board nicely on the screen. Note that string representation
is 64 characters and includes the unused places.
Once you have a board the interesting functions are:
A - "findmoves board position" (e.g. "findmoves myboard 22") to produce
a list of moves from that position.
B - "findallmoves board colour" (e.g. "findallmoves myboard Red") to
produce a list of all position/move pairs for moves of that colour.
C - "domove board position move" (e.g. "domove myboard 22 (Skip
DownLeft)") to execute a move from a position on a board, assumes move
D - "safemove board position move" as above but only executes the move
if it is valid.
There are also a couple of tests (and supporting functions) to show what
At this point I think everything is set to use the "game.ml" module as a
basis and start implementing the AI/search/algorithm/game interface of
your choice. I have no issues with multiple skips, forcing skip moves,
upgrading pieces to kings or any of that (not that I have thoroughly
- - SanguineV
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
-----END PGP SIGNATURE-----
More information about the list