javaminimaxgomoku

A good Minimax representation in Gomoku?


I am trying to code a Gomoku (five in a row) game in Java as an individual project. For the AI, I understand that the use of a Minimax function with Alpha-beta Pruning is a good way to approach this. However, I'm having a little trouble envisioning how this would work.

My question is this: what is a good representation for a node in a minimax tree?

I'm thinking my evaluation function will "weight" all the empty spaces on the board. It will then take the best value from that board as the node of the minmax decision tree. Am I on the right direction?

And any other tips are also welcome! Thanks in advance!


Solution

  • The state space search is through the different states of the board. There are a lot of moves, since you can place a stone anywhere unoccupied. Each state can be represented as a e.g. 9x9 matrix, with 3 values -- white, black, or unoccupied. With a 9x9 board, there are therefore 3 ^ 81 possible board states.

    From any board state, the number of moves is the number of unoccupied vertices. You can place a stone on any of these vertices. You can only play your own color. So, at most there are 81 possible moves .. 81 for the first move, 80 for the second, and so on. So you can search to depth 5 reasonably, and possibly more .. not too bad.

    The proper representation is, as mentioned, a 2D matrix -- this can just be a 2D array of ints, with values e.g. 0 for unoccupied, 1 for white, 2 for black. ... int[9,9].

    Your evaluation function doesn't sound very good. Instead, I would give points for the following:

    -- get 5 in a row -- basically give it the max score for this one, since it's a win -- 4 in a row with 2 open ends -- also max score, since opponent can't block you from getting 5. -- 4 in a row with 1 open end -- still a very threatenning position, since opponent has to play in one spot to block. -- 3 in a row with 2 open ends -- very high score again --- 4, 3, 2, 1 with both closed ends -- 0, since can't ever make 5 in a row.

    and so on.

    Then, you just apply the standard minimax algorithm -- i.e. alpha beta pruning -- it would be exactly the same as chess, but you have a different state space generator and evaluation function.