-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE - Negamax for Tic-Tac-Toe #1
FEATURE - Negamax for Tic-Tac-Toe #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! I suggest some places you could use const for facilitating debugging and to make sure compiler uses the raw value instead of a pointer whenever possible.
|
||
for (int x = 0; x < 9; x++) | ||
{ | ||
if ((board & mask) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a constant
{ | ||
if ((board & mask) == 0) | ||
{ | ||
int score = getMinTreeScore(board | mask, alpha, beta); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest make this bitshift operation a constant variable inside the loop so it is easier to debug its value
int state = getState(board); | ||
if (state != Playing) return getScore(state); | ||
|
||
int bestScore = INT_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it const. It can make the compiler use the raw value instead of a pointer to a variable
if (state != Playing) return getScore(state); | ||
|
||
int bestScore = INT_MAX; | ||
int mask = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here. Make it const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't make this field constant because we are using it on bitshift operations inside this method.
What is it about?
This PR introduces the adversarial search context by sharing a specific Negamax logic that solves the Tic-Tac-Toe game. The Negamax is a variant of the Minimax algorithm that performatively prunes nodes that are not important for the final result.
More details about this implementation are going to be described at the SoloGameDevBlog in the near future. You could read about the threoretical description of the Minimax algorithm at [Teoría] Adversarial Search: Minmax.
The complete game (Minimax vs Minimax) is taking 2ms total to run; sometimes it takes less than that.