Caylus Bot Writer's Guide
The Caylus AI engine allows any number of AI personalities (called "Bots") to be created to play the game of Caylus. The engine allows you to change AI personalities when starting a new game or even in the middle of a game by selecting Edit -> Bot from the Caylus menu bar.
Each AI personality is implemented by a .lua file in the "ai" subdirectory of the Caylus folder.
A very minimal personality would have the following form. (See also the "random.lua" example personality.)
local ai = {}
function ai.select_move()
-- TO IMPLEMENT: look at the current state of the game and determine -- the best move "m"
return m end
return ai
The variable "m" referred to above is simply a string such as "claim 8" or "pass". At this time a comprehensive guide to all the different movement strings is not available, but if you load a Caylus saved game (.caylus file) in Notepad, you will be able to see these same strings recorded in the file.
So, the next question is, how do you examine the current state of the game? What follows is a list of variables and functions that are available to the AI personality to examine the state of the game.
all_available_moves()
Generates and returns a list of all legal moves. If you don't know what move to return, then this function is helpful because it will give you a list of moves, any of which is valid.
current_phase()
Returns one of the following constants to indicate what sort of move is expected.
The current player is expected to place a worker or pass.
The current player is expected to move the provost up to three spaces or pass.
The current player is expected to move the worker he/she placed on the Gate.
The current player's worker is on a craft building, and is expected to pick up resources according to what that craft building produces.
The current player's worker is on the carpenter, mason, architect, or lawyer, so the current player is expected to build a building.
The current player's worker is in the castle, and is expected to contribute some batches to the castle.
The current player is expected to select a favor.
The current player is expected to perform an action specific to the current building (e.g. Market or Peddler).
Identifies by position number which building is currently activated. 1 == gate, 2 == trading post, etc.
current_turn()
local pid = current_turn()
Returns the player ID of the current player.
This is a structure (with elements "money", "food", "wood", etc.) that keeps track of how many of each resource the player currently has in possession.
Example: to see how much food the current player has
local whoami = current_turn() local num_food = state.players[whoami].resources.food
The current location of the provost. The first building after the Bridge is number 8, so therefore the smallest value this property can be is 8.
The current location of the bailiff. See also state.provost.