Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 这个评估函数在Connect 4游戏中是如何工作的?(爪哇)_Java_Minimax_Alpha Beta Pruning_Evaluation Function - Fatal编程技术网

Java 这个评估函数在Connect 4游戏中是如何工作的?(爪哇)

Java 这个评估函数在Connect 4游戏中是如何工作的?(爪哇),java,minimax,alpha-beta-pruning,evaluation-function,Java,Minimax,Alpha Beta Pruning,Evaluation Function,我正在探索一个极小极大算法如何在一个连接四个游戏中使用alpha-beta剪枝 因此,我查阅了有关Connect4播放器策略的源代码,发现了以下评估函数: /** * Get the score of a board */ public int score(){ int score = 0; for (int r= 0; r < ROWS; r++) { if (r <= ROWS-4) { for (int c = 0; c

我正在探索一个极小极大算法如何在一个连接四个游戏中使用alpha-beta剪枝

因此,我查阅了有关Connect4播放器策略的源代码,发现了以下评估函数:

/**
* Get the score of a board
*/
public int score(){
    int score = 0;
    for (int r= 0; r < ROWS; r++) {
        if (r <= ROWS-4) {
            for (int c = 0; c < COLS; c++) {
                score += score(r, c);
            }
        } else {
            for (int c = 0; c <= COLS-4; c++) {
                score += score(r, c);
            }
        }
    }
    return score;
}


/**
* Helper method to get the score of a board
*/
public int score(int row, int col){
    int score = 0;
    boolean unblocked = true;
    int tally = 0;
    //int r, c;
    if (row < ROWS-3) {
        //check up
        unblocked = true;
        tally = 0;

        for (int r=row; r<row+4; r++) {
            if (board[r][col] == CHECKERS[1-playerToMoveNum]) {
                unblocked = false;
            }
            if (board[r][col] == CHECKERS[playerToMoveNum]) {
                tally ++;
            }
        }
        if (unblocked == true) {
            score = score + (tally*tally*tally*tally);
        }
        if (col < COLS-3) {
            //check up and to the right
            unblocked = true;
            tally = 0;
            for (int r=row, c=col; r<row+4; r++, c++) {
                if (board[r][c] == CHECKERS[1-playerToMoveNum]) {
                    unblocked = false;
                }
                if (board[r][c] == CHECKERS[playerToMoveNum]) {
                    tally ++;
                }
            }
            if (unblocked == true) {
                score = score + (tally*tally*tally*tally);
            }
        }
    }
    if (col < COLS-3) {
        //check right
        unblocked = true;
        tally = 0;
        for (int c=col; c<col+4; c++) {
            if (board[row][c] == CHECKERS[1-playerToMoveNum]) {
                unblocked = false;
            }
            if (board[row][c] == CHECKERS[playerToMoveNum]) {
                tally ++;
            }
        }
        if (unblocked == true) {
            score = score + (tally*tally*tally*tally);
        }
        if (row > 2) {
            //check down and to the right
            unblocked = true;
            tally = 0;
            for (int r=row, c=col; c<col+4; r--, c++) {
                if (board[r][c] == CHECKERS[1-playerToMoveNum]) {
                    unblocked = false;
                }
                if (board[r][c] == CHECKERS[playerToMoveNum]) {
                    tally ++;
                }
            }
            if (unblocked == true) {
                score = score + (tally*tally*tally*tally);
            }
        }
    }
    return score;
}
/**
*得分
*/
公共整数分数(){
智力得分=0;
对于(int r=0;r如果(r这里有一个一般性的答案:

评估应该为更好的位置提供更好的值。在游戏中,通常通过以下方式计算分数来评估位置:增加理想配置/事件的分数,减少不理想配置/事件的分数。决定评估的功能应该改变值的多少(=平衡权重)这可能非常困难

如果我们将此应用于连接四个,那么一个特征可能是存在的威胁数量。但是对于一个真正好的算法(解决7x6),您必须查看获胜的移动是在奇数线上还是在偶数线上。还有一些规则,如“如果第二个玩家有两个偶数威胁,他就赢得了比赛”(归根结底,当填满棋盘并强制移动时,给出的规则有点简化:如果第二个玩家无法填满其他列,那么第二个玩家必须杀死一个偶数威胁,如果第一个玩家在那里有一个奇数威胁)

给出规则的简单示例(O=第一名玩家,X=第二名玩家),X赢:

曾经有一篇关于它的非常详细的科学论文。目前我能找到的最接近的: 我应该给你一些想法

顺便说一句,打开书本(通常以任何形式预先定义的智慧,如joseki、fuseki)和特殊的游戏结束评估器可以极大地提高minimax的性能

  * X X X *
O   O X O   O
1 2 3 4 5 6 7