Getting started: Download 'ConnectK.jar'. You can run it as is: java -jar ConnectK.jar Without any additional command line parameters, it will default to two player mode (human vs human). Download 'DummyAI.class'. Now run: java -jar ConnectK.jar DummyAI.class You can now play against the (stupid) AI. It's a trivial implementation just for example purposes. Download 'DummyAI.java'. Now you have starter code to write your own AI. Make sure to change the name from 'DummyAI.java' to something else. You should give your AI class a unique name, probably your UCI net username (e.g. "Panteater.class" for the user "Peter Anteater"). Converting from the earlier version (Java source code rather than .jar): The early starter code had the AI in the"connectK" package, but changed to require it be in the default package (no package declaration). It was supposed to make some parts easier, but it does require a minor change (maybe save your files somewhere first): Select your AI java file in eclipse and right click, selecting "refactor" then move. Select "default" package and confirm. Also, delete any of the starter files in eclipse (ConnectK.java, BoardModel.java... anything you didn't write). Now right click on your project and go to "build path" and select "configure build path". The "libraries" tab should show "ConnectK.jar" if you've added it already. If not, select "add external jar", navigate to "ConnectK.jar" and select it. Writing an AI: Students should extend the CKPlayer abstract class to make their own AI. It is constructed with its player number (1 or 2), and a blank example BoardModel which contains the rules of the current game (width, height...). The fact that the constructor receives a blank board does not indicate that the player will be going first. Player 1 always goes first (in the tournament, two games are played between A and B AIs: one where A_AI is player 1 and B_AI is player 2, and one where A_AI is player 2 and B_AI is player 1). The AI will have getMove(BoardModel state, long deadline) called. You can use the getLastMove() method to determine what the opponent's move was (unless it is the first move). The argument 'deadline' in the two parameter version is how long you have to make a move, in milliseconds (e.g. deadline=1000 means 1 second). It should return a move in the form of a java.awt.Point(). There is also a 'teamName' field to which you should store your team name. You are not allowed to modify any files in the connectK package; the source is just a convenience. The game state: The BoardModel contains information about the current state of the game, including rules (width, height, k, gravity), and piece locations. There are get() methods for the rules of the game (width, height...). To obtain a model with a new piece inserted, call the placePiece(Point p, byte player) method. This returns a new BoardModel object with a piece in the desired location (or as if it were dropped at the desired location when gravity is on). The pieces are stored in a 2D array (called 'pieces') of bytes and can be retrieved with the getSpace(int x, int y) method, which returns a byte 1 for player 1, 2 for player 2, or 0 when empty. The major index (i) indicates the column; the minor index (j) the row. Enumeration starts at the lower left corner from 0 ((0,0) is the lower left corner). So, for a 7x6 (width,height) board, lower left=(0,0), upper right=(6,5), upper left=(0,5), lower right=(6,0). There are conveniece methods hasMovesLeft() and winner() which you may use. equals() is also implemented. It will return true when the game *state* is the same. The lastMove field is not considered part of the state. --Note: most of the BoardModel member variables are currently public. This was intended for simplicity and speed, but was probably a bad choice and will likely be removed in the future. It is recommended to use the 'get' methods such as 'getSpace(int x, int y) instead of directly accessing 'pieces[x][y]'. That is, any direct member access is depricated, and will only remain for the Winter quarter. GUI: 'ConnectK.jar' is the standard GUI shell. To run it: java -jar ConnectK.jar This will launch with no AI, in 2 human player mode. To run the shell with the DummyAI: java -jar ConnectK.jar DummyAI.class To run the shell with your AI: java -jar ConnectK.jar YourAI.class Replace 'YourAI.class' with your AI class filename. This assumes your AI class file is in the current directory and is not part of a package. Absolute paths also work. You can also compile a C++ AI and use that prefixed with “cpp:”. There is also a "new" menu in the game. You can add your AI to the dropdown of AI options by clicking the "Add AI" button. This way you can play one AI against another and watch. Right now this (the menu) does not support C++ AIs. Tournament: You can also test your AI in a tournament fashion against other versions. java -jar CKTournament.jar AI1.class cpp:AI2 AI3.class If your AI is written in C++, prefix it with “cpp:”. Each version will have to be in a different class. Keep in mind that if you're using helper classes which are shared between versions that any static variables are also shared. You can watch the games happen. After all the games are played (n^2 - n games), the scores will be printed for each player (higher is better). Any questions, feel free to email me: 'avanbusk@uci.edu' -Alex