Do it yourself

First I want to apologies for my bad english, but hope you understand what I'm trying to say.

The history
I wanted to write a Twixt AI, but how to write one if you can't display your moves? So I started to write a java programm called "MaraTwixt P&P" with a GUI. Then i thought, why don't make it public, so that everyone can try to write a strong Twixt AI? The code is unfortunately uncommented but all you got to know is explained in the next chapter. If you find any bugs just send me a message or feel free to correct them ;-).

MaraTwixt P&P
Download: (zipped source files) or MaraTwixtPP.jar (runnable, including source files)
Screenshot of MaraTwixt P&P

First steps

To run the program, either doubleclick the jar or use:
java -jar MaraTwixtPP.jar
MaraTwixt requires Java 5. Currently there is no AI implemented.

Download the zipped sourcefiles ( Extract all files and save them at the place you want. Now you can begin to work. If you haven't programmed java yet it would be very helpful if you make a java tutorial first. Here you can find more than you need ;-)

Don't like the colors?
You can change the colors in the class Constants in the gui package. This is the only documented code, so you shouldn't have any problems. The name of your Twixt AI you can change there too.

Write your own AI
Open the class AI in the ai package. There is only one function, that's where you can fill in your code:

public int[] getMove(int mycolor,
int[][] board,
Connections myConnections,
Connections opConnections,
boolean swap,
JProgressBar prog)

The arguments
  • mycolor: 1 = you playing from top to bottom, 2 = you playing from left to right.
  • board: Represents the board. With the following command you can get the information if there is a peg at (row, column), where 0 = no peg, 1 = peg, from player playing up-down, 2 = peg from player playing left-right:
    board[row ][column] //ATTENTION: values from 0 to 23, this means highest row = 0th row.
  • myConnections: Represents your connections.
  • opConnections: Represents your opponents connections.
  • swap: true if you can swap, otherwise false
  • prog: You can set a value from 0 to 100 to show the user how far your move calculation is. Only command needed:

        More about Connections
        A connection is represented by 4 integer values, where the first 2 give the startpoint, and the 2nd pair is the endpoint. With hasConnection(row1, col1, row2, col2) you can check if theres a specific connection from point1 to point2 (or point2 to point1). If you want to read all connections do it like this:
        for (int i = 0; i < myConnections.getSize(); ++i) {
        int[] c = myConnections.getConnection(i);
        // c[0] = row1, c[1] = col1, c[2] = row2, c[3] = col2

        How to make a move
        This is the easiest part. Just save the row you want to place your peg in point[0] and the column in point[1] after you finished your calculations. Return (0, 0) to swap.

        Start the programm
        Compile all files and start the Main class in the gui package. No idea what I mean? Click on the link in the first steps chapter.

        Click here for more information about Basic algorithms.

        More pages