|
|
Writing an AI for HexThe Quick Guide:Extend: HexAI Override the following methods:
This is the board: protected Cell[][] cells Call this method to make your move: protected void makeMove(int x, int y) Check this to see what direction you should be going: Orientation getOrientation() Place the class files or a jar file in the plugins directory inside the Jaige installation directory. The Detailed Guide:The first step is to extend HexAI. You must have the Jaige jar file in your classpath. This can be done with the -classpath flag, or by including it in your IDE’s libraries. Below is the list of methods and fields that you will have to use or override for your AI to work properly.Player - Every Jaige game uses this class to represent a player. Orientation getOrientation() This is important when creating your AI. Hex uses HORIZONTAL and VERTICAL to determine what direction the bridge needs to be built. Color getColor() This is not essential. You can override this method to always be the same color. Otherwise your color will be the color set in the Game Options in the Preferences panel. void setName(String name) This sets the name of your Player. Calling super() sets this to getAIName() automatically for you. It can be set to something different if you like, and is used in the GUI. Implementing TurnListener void processTurnEvent (TurnEvent event) Implement this method to know when it is your turn. The event manager will only call this method when it is your turn, so there is no need to check to see who’s turn it really is. AI - This class is used to identify that the Player is an AI in Jaige. Please use the initialize method to construct your fields and load your AI. Loading 100 AI implementations that each load up a large amount of memory will kill the system. Therefore, only do this in the initialize method, and make sure that you remove your fields and any other memory the implementation uses in the uninitialize method. String getAIName () Override this method! It identifies your AI with a name. String getAuthor () Override this method! This lets you have your name associated with your AI. This is very useful if two different authors use the same name for their AI, like MyHexAI. String getInfo () Override this method! This lets you put any additional information about your AI here. Your AI strategy might be something to include here. Version getVersion () Override this method! This is used to determine the version of the AI playing. If you were to have 2 class files of the same class in your plugins directory, but with each having a different version, this will allow you to identify the differences. This is helpful for testing enhancements to your AI in newer versions. This may return a simple ‘new Version(1,0);’. Make sure you import it from jaige.* protected void makeMove (int x, int y) Call this to make your move! HexAI protected Cell [][] cells These are the cells that represent the board. It is a 10x10 matrix. However, since the cells are hexagon shaped, movement between cells is not the same as if they were square. Understanding the relationship between each cell is a major piece of the puzzle. The cells have an X and Y coordinate that should reflect it’s position in on the board and in the matrix. It also has the Player that owns that space, and the color of the space. You can set the color for debugging purposes, but only with cells that have no Player associated with it. You cannot set the Player to yourself. It is cheating, and you will get an exception if you try. Note that if you find any other ways to cheat, please inform the Jaige development team. Here is a sample AI called RandomAI. Note that it does not check it’s orientation, thus it does not have any shots at winning a match. GeSHi © 2004, Nigel McNie
Parsed in 0.050 seconds The simplest way to get your AI working is to place your class files in the plugins directory inside the Jaige installation directory. It is better to put you classfiles into a jar file. Directions on how to do this is located here. You can also use an IDE to do this (Eclipse requires the fatjar plugin). You may be able to use winzip, and name the output file with the .jer extension, although there are no promises that it will work. |
|