jeudi 14 juillet 2016

If statement not working as intended with altering variables

I am making a Mancala-playing AI. My problem is that the contents of the If-statement with conditions of "botChoice<=5&&usedBoardState[botChoice]==1&&usedBoardState[12-botChoice]>=1" is not running even though in many instances it should be. If you have any questions about my code, feel free to ask, for I am a beginner amateur coder.

    int[] staticBoardState = new int[14];
    for(int f = 0; f <= 13; f++) {
        staticBoardState[f] = boardState[f];
    }

    double[] movePoints = new double[6];
    int scorePoints;
    int freeTurnPoints;
    int buildupPoints;
    int emptyPoints;
    int capturePoints;

    double bestMovePoints;
    int bestMove;

    for(int f = 0; f <= 5; f++) {

        capturePoints = 0;

        int[] usedBoardState = new int[14];
        for(int g = 0; g <= 13; g++) {
            usedBoardState[f] = staticBoardState[f];
        }

        int initialScore = usedBoardState[6];

        int botChoice = f;
        int botHole = usedBoardState[botChoice];
        usedBoardState[botChoice] = 0;

        for(int g = 0; g < botHole; g++) {

            botChoice++;
            if(botChoice>12) {
                botChoice = 0;
            }

            usedBoardState[botChoice]++;
        }

        if(botChoice<=5&&usedBoardState[botChoice]==1&&usedBoardState[12-botChoice]>=1) {
            capturePoints += usedBoardState[12 - botChoice] + 1;
            usedBoardState[6] += usedBoardState[12 - botChoice] + 1;

            usedBoardState[botChoice] = 0;
            usedBoardState[12 - botChoice] = 0;
        }

        scorePoints = usedBoardState[6] - initialScore;
        if(botChoice==6) {
            freeTurnPoints = 1;
        } else {
            freeTurnPoints = 0;
        }
        if(usedBoardState[botChoice]==0) {
            emptyPoints = -100;
        } else {
            emptyPoints = 0;
        }

        movePoints[f] = scorePoints + capturePoints + (3 * freeTurnPoints) + emptyPoints;
    }

    for(int f = 0; f <=5; f++) {
        System.out.println(movePoints[f] + " ");
    }

    bestMovePoints = movePoints[0];
    bestMove = 0;
    for(int f = 1; f <= 5; f++) {
        if(movePoints[f]>bestMovePoints) {
            bestMovePoints = movePoints[f];
            bestMove = f;
        }
    }

    return bestMove;

Any help is appreciated. Thanks!

Aucun commentaire:

Enregistrer un commentaire