• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

### #Actualcryobuzz75

Posted 04 March 2013 - 08:36 AM

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

### #2cryobuzz75

Posted 04 March 2013 - 08:35 AM

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;
}


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

### #1cryobuzz75

Posted 04 March 2013 - 08:35 AM

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 fucntion. 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;
}


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

PARTNERS