Ion

Challenge

For any given position in a game of chess, compute the best move for the next player.

Solution

Ion is a web-hosted chess engine that can find the best move from a FEN string describing the game state. By evaluating the game state along every possible line of moves, Ion can find the move that results in the best outcome for the next player.

First, the game tree is constructed. We start at the current position, and the first level down contains all the possible moves the current player can make. For each of those moves at level 1, we look at all the moves the other player can make from the resulting position. This continues on and on until a suitable depth is reached, which is usually 12-13 for under 2-second computation time.

Once we reach the bottom of the tree, we evaluate every position using an evaluation function that follows chess theory and strategy. The scores are then bubbled back up through the tree and we select the path that results in the maximum score.Obviously though, looking at every possible chess position would take forever. So instead of looking at every position, we look at favorable moves for both players. If we expect the best response to any move chosen, we have more information about the path of best moves that can be made.

Ultimately, an implementation of the Principal Variation Search algorithm is used in conjunction with a move ordering function and a transposition table to find the best move.

Ion finding a forced checkmating sequence