This is a tool that understands the board game Ataxx, and generates moves for it based on a board. Before using the tool, make it (and other included scripts, see below) executable
$ chmod +x main.py board.py play
The input should have separated by newlines a height, width, playing token, and rows of the board. For example:
The spec provided by Adoxography perscribes the first 2 lines be height and width,
but they are discarded since we aren't going to do any allocation ahead of time.
With this, we might get something like:
4
4
X
_ _ _ O
_ X _ _
_ _ _ O
_ _ _ X
main.py
is primarially used to make a move on an ataxx board. It's usage is
usage: main.py [-h] [-b] [-p] [-f FILE] [-i]
optional arguments:
-h, --help show this help message and
exit
-b, --best try to choose the best move
-p, --playable write results so that they can
be understood by this program
-f FILE, --file FILE read the board from this file
instead of stdin
-i, --interactive run interactive and do nothing
in main()
It understands boards given to it in the format mentioned.
By default, given some token that should move token
and a board board
,
It will return a board for ever move doable by token
,
where each board is board
with that move haven been done.
For example given the following board
4
4
X
X O _ _
_ _ O _
_ _ O _
_ _ X _
it should produce a list of boards
$ cat board ./main.py
X O _ _
X _ O _
_ _ O _
_ _ X _
X O _ _
_ X O _
_ _ O _
_ _ X _
_ O _ _
_ _ O _
X _ O _
_ _ X _
...and so on (in this case, 10 moves) If there are no available moves (no tokens present, full board, or just blocked) then nothing is returned
If -b | --best
is passed, it will return what it thinks is the best move to make
Following the board from the last example, it should produce
_ X X _
_ _ O _
_ _ O _
_ _ X _
The basic flow for determining a "good" board is to generate possible boards, score them, and pick the top scoring board. If there is a tie for top scoring boards, pick a random one of those to add variety
The scoring algorithm looks at:
- The population of the playing token
- The population of opponent tokens
- The number of times that the playing token may jump an opponent
- The number of times that the playing token may be jumped by an opponent
If -p | --playable
is passed, the same things happen
but the board(s) returned is able to be understood by this script.
This is useful for feeding results into the program again.
The returned token
represents the next token that should play
Using the same board from before, we could
$ cat board | ./main.py -bp | ./main.py -bp
4
4
X
_ X X _
_ _ O _
_ _ O O
_ _ X _
-f | --file [file]
can be used to read a board from a file instead of stdin
$ ./main.py -f board
-i | --interactive
can be used when you are starting the script interactively
$ python -i main.py -i
>>>
board.py
is a tool for generating random boards at random game states.
It does not try to generate valid game states, but rather
randomly populates a board with tokens. This was used for testing.
It's usage is
usage: board.py [-h] [-l LENGTH] [-w WIDTH] [-p POPULATION] [tokens [tokens ...]]
positional arguments:
tokens token pool
optional arguments:
-h, --help show this help message and exit
-l LENGTH, --length LENGTH
board length
-w WIDTH, --width WIDTH
board width
-p POPULATION, --population POPULATION
token population
It can be used like below, and it's out put right into main.py
8
8
X
_ _ _ O O _ _ _
_ _ _ _ O _ _ X
_ _ _ _ _ _ _ O
_ X _ O X X _ O
_ _ _ O _ _ _ _
_ O _ O _ _ _ _
_ _ _ _ _ _ _ O
X _ O O X _ O X
play
is a small tool that will use board.py
to generate a random board
and use it to have main.py
play with itself
Its arguments map to ./board.py -l$1 -w$2 -p$3
$ ./play 4 4 4
4
4
X
O O _ _
X _ _ _
_ _ O _
_ _ _ _
4
4
O
O O _ _
X _ _ _
X _ O _
_ _ _ _
...
4
4
X
O O O O
X O O O
X X _ O
X X X X
4
4
O
O O O O
X O O O
X X X O
X X X X