There are some piles of tokens, every turn can remove any number of token from a pile, the player loose if he remove the last token from the last pile.
Sunada wrote the following script that permits you to play against your PC:
How it works?
Well, you can find a very good documentation here: http://www.rebol.org/documentation.r?script=nim-engine.r
I'll just explain it shortly, launch nim-engine/play-game:
Enter moves as a pair!
eg 3x7 means take from pile 3. The number of counters taken is 7
game type: common ... lose if you take the last counter
starting position: [7 3 4 3 1]
It shows the situation as a block, every item of the block is the number of tokens in the pile.
You have to give a pair! to indicate "pile X tokens" to remove.
This script is also a nim engine to create cool games with GUI, just launch it with /move refinement, and you'll obtain an object with the PC move:
>> a: nim-engine/move "common" [3 4 5]
>> ? a
A is an object of value:
game-type string! "common"
game-over? logic! false
winner? none! none
move pair! 1x2
piles block! length: 3
winning? string! "nim-engine"
This is the object explained:
|game-over?||true/false depending on whether more moves are possible|
|winner?||who won ("human" or "nim-engine") if the game is over|
|move||(assuming the game wasn't over when you made the call) the move nim-engine is making. A pair: 1x2 means taking 2 from pile 1|
|piles||the updated position block|
|winning?||which player is winning|
Can you create a GUI for this game?