0

Currently I'm trying to implement heuristics for a 3D tic-tac-toe but it seems like my counter is way of it,f but I'm unsure where I've done wrong, I'm not gonna post all of the code since it's a lot, but here is a part:

public void countDiagonal(GameState gameState) {
        /*
         * yz-plane (negativ)
         */
        int z;
        for (int x = 0; x < GameState.BOARD_SIZE; x++) {
            for (int y = 0; y < GameState.BOARD_SIZE; y++) {
                z = y;
                if (gameState.at(x, y, z) == myPlayer) {
                    myCounter++;
                    opponentCounter = 0;
                }
                if (gameState.at(x, y, z) == opponentPlayer) {
                    opponentCounter++;
                    myCounter = 0;
                }
                if (gameState.at(x, y, z) == Constants.CELL_EMPTY) {
                    emptyCells++;
                }
            }
            evaluateBoard();
            myCounter = 0;
            opponentCounter = 0;
            emptyCells = 0;
        }

The evaluation is done here:

public void evaluateBoard() {
        if (myCounter == 1 && emptyCells == 3) {
            myScore = myScore + 5;
        }
        if (myCounter == 2 && emptyCells == 2) {
            myScore = myScore + 10;
        }
        if (myCounter == 3 && emptyCells == 1) {
            myScore = myScore + 20;
        }
        if (myCounter == 4) {
            myScore = myScore + 1000;
        }
        if (opponentCounter == 1 && emptyCells == 3) {
            opponentScore = opponentScore + 5;
        }
        if (opponentCounter == 2 && emptyCells == 2) {
            opponentScore = opponentScore + 10;
        }
        if (opponentCounter == 3 && emptyCells == 1) {
            opponentScore = opponentScore + 20;
        }
        if (opponentCounter == 4) {
            opponentScore = opponentScore + 1000;
        }
    }

When I try to run it, I use alpha-beta prune, but it seems like the calculation are done horrbly wrong, when I use the value, I take myScore - opponentScore and I use an alpha-beta tree with depth 1, but even after only playing one move, I'm down -15 in points, as I'm a noob in java, im therefore asking for help, is there an obvious mistake in my way of trying to evaluate the board?

Nicholas K
  • 15,148
  • 7
  • 31
  • 57
A.Maine
  • 117
  • 9
  • Can you give an example? As in show us a game state, your expected score, and what score you're actually getting. – mypetlion Sep 27 '18 at 18:11
  • I just did the implementation for a 2D tic-tac-toe and it was all working good, now it's not working at all, i realize that my heuristics are rather bad, but i mean, its completely malfunctioning, I cant really give a good example, but the counter can be at like -3600 after just one single sign, and I dont know what I've done wrong – A.Maine Sep 27 '18 at 18:25
  • Producing wrong output is not the same as "not working at all". You just did (sort of) provide an example, so I'm not sure why you say you can't. Where in the 3D board is the first sign placed to produce -3600 and what score would you expect to get? – mypetlion Sep 27 '18 at 18:29
  • I can see what you mean, i'm gonna try to make a long story short, I tried to make the same typ of implementation I'm doing right now for a 2D tic-tac-toe and I couldnt make it work, simply because my heuristics didnt work out, there I produced a tree with the depth 15, that means, I was looking at 15 gamestates ahead and could therefore predict the most beneficial state for me, for the 3D tic-tac-toe, I cant do that, I need some sort of heuristics since my algorithm would be way too slow, I have a way to see if my algorithm can win games, and It never wins a game – A.Maine Sep 27 '18 at 18:35
  • I've done some tests and the numbers doesn't really add up, therefore I posted just a bit of the heuristics, hoping that someone would see an obvious mistake alternatively maybe some advice for a better implementation. – A.Maine Sep 27 '18 at 18:38
  • I don't know how to be more clear about this. It will be impossible for us to help you unless you can provide at least one example of "When a player makes a move in square (x,y,z) I am expecting a score of but instead the program produces a score of ". Additionally, you only show us the method for scoring diagonal lines. Do you have similar methods for horizontal and vertical lines? – mypetlion Sep 27 '18 at 20:26
  • What does it look like when you call these methods? "The evaluation is done here", but where is that method called from? Do you call other methods first? What class is the `evaluateBoard` method in and what else is in that class? – mypetlion Sep 27 '18 at 20:28

0 Answers0