-- goofy2.wz - An example Lua script for Tick5 -- Copyright (C) 2006 XMartin Yao -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ---------------------------------------------------------------------------- -- This is a simple example of AI engine built using Lua script for Tick5. -- It is to teach users how to build an AI engine that can play the game. -- -- See the example in script goofy.wz for the very basics of the AI -- function tick5think(board). -- -- In this example, the AI does "think" a little bit: it randomly -- picks up the coordinates of a vacant spot. Although it runs fast, -- anyone who knows the game rules can defeat it wihtout any effort. -- Better to let it beat itself. :-) ---------------------------------------------------------------------------- function tick5think( board ) -- set random number seed math.randomseed( os.time() ) -- query the game board's dimension local dim = board:dimension() -- the upper bound of coordinates local bound = dim - 1 -- x and y are random numbers from 0 to bound local x = math.random( 0, bound ) local y = math.random( 0, bound ) -- generate coordinates until a vacant spot found while not board:isempty( x, y ) do x = math.random( 0, bound ) y = math.random( 0, bound ) end -- return the chosen coordinates return x, y end