Skip to content
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

Merged
merged 13 commits into from
Sep 4, 2019

Conversation

andreimesquita
Copy link
Member

@andreimesquita andreimesquita commented May 19, 2019

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.

@andreimesquita andreimesquita added the Feature New feature label May 19, 2019
Copy link

@marciovmf marciovmf left a 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)

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

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;

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;

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

Copy link
Contributor

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.

@andreimesquita andreimesquita changed the title Feature / Negamax for Tic-Tac-Toe [FEATURE] - Negamax for Tic-Tac-Toe May 27, 2019
@andreimesquita andreimesquita changed the title [FEATURE] - Negamax for Tic-Tac-Toe FEATURE - Negamax for Tic-Tac-Toe May 27, 2019
@AndreiSchuch AndreiSchuch merged commit 2a23cde into development Sep 4, 2019
@AndreiSchuch AndreiSchuch deleted the feature/adversarial-search/minmax-tictactoe branch September 4, 2019 21:35
@andreimesquita andreimesquita linked an issue Aug 3, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Templated Minimax
3 participants