Hi all,
I'm doing a simple TicTacToe so that I can implement a Negamax algorithm which I can later use for other abstract games. However I'm encountering problems whereby the AI doesn't play the best move, and it loses constantly. My suspect is the static evaluation function. Here it is:
public int getScore()
{
int score = 0;
CellState state = CellState.Empty;
if ((cells[0] == cells[1] || cells[1] == cells[2]) && (cells[1] != CellState.Empty))
state = cells[1];
if ((cells[6] == cells[7] || cells[7] == cells[8]) && (cells[7] != CellState.Empty))
state = cells[7];
if ((cells[0] == cells[3] || cells[3] == cells[6]) && (cells[3] != CellState.Empty))
state = cells[3];
if ((cells[2] == cells[5] || cells[5] == cells[8]) && (cells[5] != CellState.Empty))
state = cells[5];
if (((cells[3] == cells[4] || cells[4] == cells[5]) && (cells[4] != CellState.Empty)) ||
((cells[1] == cells[4] || cells[4] == cells[7]) && (cells[4] != CellState.Empty)) ||
((cells[0] == cells[4] || cells[4] == cells[8]) && (cells[4] != CellState.Empty)) ||
((cells[2] == cells[4] || cells[4] == cells[6]) && (cells[4] != CellState.Empty)))
{
state = cells[4];
}
if (state == currentPlayer)
score = getMaxScoreValue();
else if (state == currentPlayer.getOpponent())
score = -getMaxScoreValue();
return score;
}
Cells is just an array of size 9 that represent the board positions. CellState is just an enum with values {Empty(0), Player(1), Opponent(2)}. getmaxScoreValue just returns the highest score (65536),
Is this static function complete or am I missing other conditions?
Thanks,
C