What's new About Download License Screenshots Manual Tutorial sf.net page Contact |
The AI Programming Interface
This section introduces you Tick5's AI Programming Interface. The example Lua scripts included in this section will not help you to build a sophisticated AI, but illustrate the AI Programming Interface and the basics of an AI engine written in Lua script. To build your own superior AI for Tick5, you need to get yourself familiar with AI and the game by either reading some books or googling the Internet. Tick5 is built using Lua 5.0.
You can find the Lua 5.0
Reference Manual
here. The book Programming In Lua
by Lua's chief architect
Roberto Ierusalimschy
can be find here.
Its first edition is available for online
reading.
The example Lua script
files included in this manual are named as filename.wz, rather
than the conventional filename.lua,
to avoid to mix these written
specially for Tick5 with those that can run with the official
Lua interpreter. Furthermore, the game is called wuziqi in my native
language. However, you are free to choose the
extension name. ;-)
Happy AI programming! And don't forget to share your superior AI with me and others. ;-) The
|
tick5think(
board ) |
tick5think(
board
),
it passes in a game board. The
function tick5think(
board
)
needs to return two integers
which are the x-
and
y-coordinate of a move. Tick5
retrieves the x- and
y-coordinate returned by tick5think(
board
), verifies them, and places a
stone on the spot if they are valid
x- and
y-coordinate.
tick5think(
board
)
doesn't do any "thinking". It
ignores the passed in board and simply returns the x- and y-coordinate
of the spot (3, 3). mycolor()
functionmycolor()
which allows you to query the color of the stone the script
is playing. mycolor () |
returns 1 for black stone;
return -1 for white stone.
|
tick5think(
board
)
is a copy of the game board at
the time the function is called. The AI Programming Interface
provides functions for you to query
and manipulate
the copy of the game board. You can use these functions to
get information you need to make the best possible
move. board:dimension() |
returns a integer
which is the width and height of the game board. |
board:isfull() |
returns true if the board is full; false, if not. |
board:isempty() |
returns true if the
board is empty; false, if not. |
board:isempty(x,y) |
returns true if the spot (x, y) is empty; false, if not. |
board:getstone(x,y) |
returns 1 if the stone on spot (x, y) is black; 0 if empty; -1 if white. |
board:plies() |
returns the number of moves both parties have made so far. |
board:inboard(x,y) | returns if the spot (x,y) is within board; otherwise, false. |
board:lastmove() | returns x-, y-coordinate and stone color of the last move, if any; otherwise, nils. |
Another example Lua script goofy2.wz can be found here.
In this example, the
function tick5think(
board
)
does a little bit "thinking." It
randomly picks a pair of x- and y-coordinate using Lua's math function math.random()
.
It queries the board object to see whether the spot (x, y) is empty or
not. It returns the coordinates if the spot is empty; it continues to
repeat the procedure, if not empty, and until an
empty spot is found.
board: putstone(x,y,c) |
put a stone of color c on spot
(x, y), returns true if it is successful; false, otherwise. c =
1, represents a black stone; c = -1, a white stone. |
board:
remove(x,y ) |
removes the stone on spot (x, y), returns false if no stone on the spot; true, otherwise. |
board:clean() |
removes all the stones from the
board, making it empty. |
board:set(x,y,c) | same as putstone(x,y,c), deprecated. |
board:reset(x,y) | same as reset(x,y), deprecated. |
clone()
function which allows you to
make a copy of the board. To call the
function, the board and
a colon must placed before the function. board:clone() |
returns a copy of the board object. |
set(x,y,c),
reset(x,y
)
or clean()
. You may need to make a copy of the board with the help of
function clone()
, before your Lua
script does whatever necessary to
the board when it is "thinking". clone()
is called to make a copy of the
board then the script masses up with the copy . The function clone()
is also utilized to
find the last move the opponent made. This example does the
same as
the previous one, except that it wanders around to explore the board
before it randomly picks up an empty spot.keeprunning()
which allows you to check the status of the game. keeprunning() |
returns false if the game is
going to
stop or an undo quest is sent to the game; returns true, otherwise.
|
keeprunning()
within loops. Exit the loop or
even tick5think(
board
)
function, if it
returns
false. Otherwise,
you will
not be able to stop the game properly or undo a move
immediately.tick5think(
board
)
function. Within the inifinite
loop, a
black and a white stone is respectively placed on each empty spot and removed, and no move is
made. However, the keeprunning()
function
is called within the infinite loop to determine whether it should
jump out of the loop or not.