English 中文(简体)
哪些算法可以解开Tic Tac Toe?
原标题:Which algorithms are available to solve Tic Tac Toe?

What algorithms are available to solve Tic Tac Toe? Especially with board size 4 * 4 or bigger instead of 3 * 3? I tried 4 * 4 with Minimax & alpha-beta pruning but the pc seems to hang and throws exceptions on stack overflow. I saw these source code written in javascript but I don t know which algorithm it uses, could anyone clarify it for me? http://js-x.com/page/javascripts__example.html?view=153

问题回答

试着在一定深度上切分... 我不认为你需要超过4或5度深度 才能做出完美的举动

(3*3个一迪米板的喷射深度):

int minimax(int turn, int depth) { // turn(side to move) is 1 or -1
    int val = -turn; // worst value for that turn 
    int result = NULVAL;
    if (wins()) return turn; // evaluate board (board is a field)
    if (depth == 0) return DRAW;
    for (int i = 0; i < 9; i++) {
        if (board[i] == EMPTY) {
            board[i] = turn; // make move
            result = minimax(-turn, depth - 1);
            board[i] = EMPTY; // delete move
            if (result == turn) 
                return turn; // sees win
            if (result == DRAW)
                val = result;
        }
    }
    // if result keeps NULVAL: couldn t make a move (board is full)
    if (result == NULVAL) return DRAW;
    return val;
}




相关问题
How to break the while loop?

So I have been coding tic tac toe, but the issue is once one side gets 3, the function won t register and the code continues. Can anyone give me insight to why this is happening? I ran the code ...

TicTacToe strategic reduction

I decided to write a small program that solves TicTacToe in order to try out the effect of some pruning techniques on a trivial game. The full game tree using minimax to solve it only ends up with ...

Detect winning game in nought and crosses

I need to know the best way to detect a winning move in a game of noughts and crosses. Source code doesn t matter, I just need a example or something I can start with. The only thing I can come up ...

look for evaluation function in tictactoe 3d game

I m trying to apply minimax algorithm for the game tictactoe 3D in c++. I m struggling to find a good evaluation function for it. Does anybody know where has good resource to find the evaluation ...

Code Golf: Tic Tac Toe

Post your shortest code, by character count, to check if a player has won, and if so, which. Assume you have an integer array in a variable b (board), which holds the Tic Tac Toe board, and the moves ...

Pruning Tic Tac Toe Moves

I ve written a tic tac toe code that fine to a point. I have Alpha-Beta Pruning working also. I ve ran across a problem that I need ideas, NOT CODE. How can I choose a move that will win in 4 moves ...

热门标签