🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Othello heuristic method

Started by
6 comments, last by LorenzoGatti 4 years, 2 months ago

I'm working on an Othello game that tries to use minimax?

I made a heuristic function for it:

    int getHeuristic() {
        // give each square a certain value
        // corners are most valuable

        int[][] values = {
                {10, 2, 7, 7, 7, 7, 2, 10},
                {2, -4, 1, 1, 1, 1, -4, 2},
                {7, 1, 1, 1, 1, 1, 1, 7},
                {7, 1, 1, 1, 1, 1, 1, 7},
                {7, 1, 1, 1, 1, 1, 1, 7},
                {7, 1, 1, 1, 1, 1, 1, 7},
                {2, -4, 1, 1, 1, 1, -4, 2},
                {10, 2, 7, 7, 7, 7, 2, 10}};

        int theHeuristic = 0;

        for (int y = 0; y < 8; y++)
            for (int x = 0; x < 8; x++) {
                if (boardColors[x][y] == 'b') theHeuristic += values[y][x];
                if (boardColors[x][y] == 'w') theHeuristic -= values[y][x];

            }

        return theHeuristic;
    }

Anyone know how to make this better?

Also, has anyone tried using a neural network to power the AI for Othello?

Advertisement

You could consider indexing the board etc by a counter 0..63 rather than all the x,y stuff, where you construct such a counter using board[y][x] on each access.

Functionally, nothing will change of course.

I don't know how to program othello, but I would be very surprised if the Internet has nothing about it. As a general rule, assume that if you think of something, someone else in the past in the world has had that thought already too.

As such, the answer to your final question is most likely “yes”, and the Internet can likely provide all the details and more.

@Alberth Why do you think a one-dimensional array is better?

Thanks.

Neural net would be serious overkill here. You would end up with largely the same rule-based system that can be hand-crafted but abdicate the ability to tune it.

Minimax would work but you need to also be able to play defensively as you have alluded to by not putting pieces where the other player can get edges and/or corners. One way of doing this is artificially punishing putting pieces in places that lead to the edges/corners. Another way is to run another ply beyond the move you are trying to calculate. That is, “if I move at XY in turn N, what could my opponent's move look like in N+1?” The interesting outflow of this is that, while you would avoid higher scoring moves that would yield better moves for your opponent in the next turn (thereby giving a net minus).

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

ms75214 said:

@Alberth Why do you think a one-dimensional array is better?

Thanks.

You asked for “better” without really specifying what that means, ie nicer code, faster, improved heuristic, etc.

I went for “nicer code”, and one of the things I noticed is the same [x][y] things everywhere (although values does [y][x], not sure why). If you merge both counters into one, you can compute the offset once, and use it everywhere, or even drop the computation completely since you have a fixed order of looping over the fields, so you can write a loop that simply produces the correct offset directly.

I don't know how to make a better heuristic function for Reversi. You can try to find the opinion of experts online.

Using a neural network for a board game like this makes perfect sense, and you can see how projects like Leela Zero (go) and Leela Chess Zero have done it.

The current breed of NN projects use MCTS instead of minimax, but there is no reason you can't get this working with minimax. A few years ago I trained a small neural network to play Spanish checkers using minimax and it worked really well.

A neural network could make sense because it can be good at recognizing board states, but don't go overboard with random and heuristic approaches because you still need to rely on exact planning for the endgame.

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement