[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-----
Hash: SHA1
 
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
>> comments)
>
> Well I've commented the code now, so you can't use that as your only
excuse. :)
>
> http://www.progclub.org/pcrepo/jj5-test/trunk/ai-checkers/checkers.c?view=markup
>
> 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
next moves
> * 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:
http://progsoc.org/~sanguinev/files/game.ml
 
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
is valid.
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
works.
 
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
tested though).
 
- - SanguineV
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
 
iQIcBAEBAgAGBQJOnluBAAoJEI+NvFGSwhPnnYIP/RlkC7ugQNhe+rSCrLuy/ui/
67TxmmVmtYuxACWJ3S0VsDJHCgeD1LpSimHfNAqG/EG8iCFKEI8Ck9Wg/h82l4wT
uVd82lG4IBW0MSb2ke/2mXpo4s5PRB4oxexhW4mqHSfuexv27EwfytUXGHWRtFcL
kkF2PLITIaYq+xVUGJ7/dzHNRpAO0cDYOyc8y0AkShlbmxrYCgWRUY+4ozRgZIGF
uFAwuMvw64VHr52lWx7wESx4KlY4GeprFS+S5XmDkRLTFOqfxziNqf0JUWuu8Hjt
ypXuRa6AWxcy1wkoah2I5ChsxdhFTFYLPUZiWGUJFtH/5BtwUqZN2tLRMmN2elua
F+0rucS+gPcZUtkgTBONYKg/Xtw8CRP5f+RBPAefhOF6QYpQ/qsdRXsQqmEA6NSy
N/jqmfZg7jTnLpW36E4N2o1H6i9GAVuuDFe+MNcTzQ1Ke3s+idCiMO1/Alpk2Kos
a9IfPMfHMjYw5GHbsd+S8WZ1Mma9ksOJMHljG7L3wxilTzfyg4yPef0zfgWrbWIf
AL9Lr+wppVUpRVozA/cralMh1QlV8b7TyOYZN/N+1VGcaYoAx6Y8czeHPfhwT/Ts
neDL7BNlP6joctYCct/NZUo4zlUjbac2w/I3sg+SqOAJcaUMDeuRqQvdSiLO0lTO
47+JX95wGnjhzLFhNeV/
=oz4A
-----END PGP SIGNATURE-----



More information about the list mailing list