0
\$\begingroup\$

I'm developing a program for a Line of Action game (see specs here: http://www.boardspace.net/loa/english/index.html)

For the AI, I've created a game tree, pretty similar to most game tree algorithms, and it seems to work.

Now, I just am kinda unsure on how to create the heuristic -- basically what happens when the depth at which you're searching for good moves is zero.

It's basically a function that's supposed to help me evaluate the "score" of the move.

Based on the specs, I've made a few different factors in my function, but I'm not sure how to weigh them.

Here's what I'm considering (by the way, I'm optimizing for white player):

  • is the game over? if so, return the winner, or 0 if it's a tie
  • compare the biggest region sizes of both players, favoring WP
  • How many regions of contiguous pieces do both players have? The more, the worse, so numRegionsBP - numRegionsWP
  • how many pieces are left? The more the better.
  • the legal moves possible with the current board. I iterate through and check if any lead to BP or WP having all its piecescontiguous (again, optimizing for WP)

Here is my code to find the score. Unfortunately it always results in a tie, when it should be optimizing one side. Should I change my factors or the weights? I'd appreciate some guidance:

    private int staticScore(Board board) {
        if(board.gameOver() && board.winner()!=null) {
            if(board.winner().equals(WP)){
                return WINNING_VALUE;
            }
            else if(board.winner().equals(BP)) {
                return -WINNING_VALUE;
            }
            else {
                return 0;
            }
        }
        //factor for contiguous regions size
        List whiteRegions = board.getRegionSizes(WP);
        List blackRegions = board.getRegionSizes(BP);
        int maxW = (int) Collections.max(whiteRegions);
        int maxB = (int) Collections.max(blackRegions);
        int contigRegions = maxW - maxB;

        //factor for number of contiguous regions
        int regionsNumW = whiteRegions.size();
        int regionsNumB = blackRegions.size();
        int regionsNumDifference = regionsNumB - regionsNumW;

        //factor for number of pieces left - maybe delete
        int numW = board.getNum(WP);
        int numB = board.getNum(BP);
        int numDif = numW - numB;

        //account for moves to get me
        int piecesContig = 0;
        for (Move mv : getBoard().legalMoves()) {
            getBoard().makeMove(mv);
            if ((getBoard().piecesContiguous(BP))) {
                piecesContig = -1;
                break;
            }
            else if((getBoard().piecesContiguous(WP))){
                piecesContig = 1;
                break;
            }
            getBoard().retract();
        }
        return 20*contigRegions + 10*regionsNumDifference + 20*piecesContig;
    }

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.