Search code examples
algorithmartificial-intelligence2d-games

How to choose an algorithm?


I've to choose an algorithm for a given problem:

The game has two players: x and o. The players take alternate turns, with player x moving first at the beginning of each game.

Player x starts at position (1,1) while o starts at (8,8).

Each turn, a player can move like a queen in chess (in any of the eight directions) as long as her path does not cross a square already filled in or occupied. After moving, the space vacated by the player is designated as filled and cannot be moved to again. Notice that only the space that was occupied is filled, not the entire path.

The game ends when one player can no longer move, leaving the other player as the winner. Time given is 1 minute.

The coordinate (1 1) indicates the top left hand side of the board.

The board is specified as a list of rows. Each row is a list of entries:

  • is an empty square

  • is a filled in square

x is the current position of the x player

o is the current position of the o player

Would that be a local search algorithm or A*? It seems similar to chess, but at the same time I can't really see a goal of this game...

Loads of thanks!


Solution

  • This is a zero sum game, with two players, and each agent have full 'knowledge' of the world.

    The general approach to handle such problems is minimax algorithm.

    The algorithm idea in a nutshell is trying to find the maximal guaranteed "value" for each move. This is done by taking the "max" possibility in your turn and "min" possibility in the opponent's turn (it is assuming he is also trying to maximize his profit, so maximizing his profit is minimizing your profit).
    The algorithm looks recursively into all possible game states up to certain depth, and choose the best strategy you can take.

    You will likely need some heuristic function to evaluate each game state (since the algorithm is unlikely to be able to have the entire game tree, due to the large branch factor). The algorithm will use this heuristic to chose the best move for you, and for the oponent.