2

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 versus a move that will win in 8 moves. The problem I'm having is the branch that returns a optimal score from minimax/AB prunning will possibly win in 8 moves so it prunes off possibly a branch that will win in 4 moves.

I've ran across a couple ideas such as killer heuristic, transposition tables, and iterative deepening search. Any ideas would be great

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 3
    Winning tic-tac-toe needs at least 5 moves: 3 from winner, 2 from loser. Right? – o.k.w Nov 24 '09 at 02:52
  • 3
    Not if your little brother looks away and you put down and extra X – SwDevMan81 Nov 24 '09 at 02:55
  • Okay, I was using 8 and 4 as examples i realize that one person can only move either 5 or 4 times depending on whose X or O. It was only a case. –  Nov 24 '09 at 03:38

7 Answers7

1

A way you can do:

Do your search with a max depth of 2, if no win are find, then increase your depth limit, until you find a win.

For tic-tac-toe, killer heuristic , transposition table , it's maybe bit to much since, you can keep in memory all board possibilities.

In my project I use the Proof-Number Search . But there's so much algorithm that you can use. You can find idea in this site too, but even if it's about chess, most of ideas can be use for your project.

Nettogrof
  • 2,116
  • 2
  • 15
  • 22
  • So are you suggesting I abandon my Alpha-Beta Pruning? I know that with a standard tic tac toe game, not pruning a game tree isn't that harsh on my computers memory; however, this basic game is more of a first step to creating a quantum tic tac toe game which has alot more moves than basic. –  Nov 24 '09 at 03:46
  • Keep Alpha-beta Pruning, it's useful in most case, even your's. But you can program a depth limit – Nettogrof Nov 24 '09 at 04:41
1

I would look more into iterative deepening. This would help you find the 4 move win before the 8 move win.

aubreyrhodes
  • 777
  • 4
  • 16
1

Your evaluation should rate winning game states more highly when there are fewer moves taken. This should be pretty easy to implement. Let's say you usually assign all winning game states a value of 100. For a size 9 board, just add the quantity (9 - turns) to this. So a winning board after 8 turns would evaluate to 101 and a winning board after 5 turns would evaluate to 104.

PeterAllenWebb
  • 10,319
  • 3
  • 37
  • 44
  • I would also add that the easiest way to track how many moves have been taken is to track the depth of your recursion with alpha-beta search. – Zefira Apr 29 '15 at 22:01
0

I believe tictactoe has actually been "solved" in the sense that there's an algorithm that will guarantee a win or draw, at least form the initial state so a alpha-beta search seems excessive. (unless you're just learning to implement it on a simpler game than chess or whatever)

olliej
  • 35,755
  • 9
  • 58
  • 55
  • It's a precursor to developing a quantum tic-tac-toe game –  Nov 24 '09 at 04:48
  • Why? Alpha beta is just easy way to implement brute force for game like this. It is not so trivial to write recursive tree searching algorithm even for TIC-TAC-TOE. Use the alphabeta whit dept= remaining spots. – Luka Rahne Nov 25 '09 at 22:20
0

(Wanted to include this in a comment, but it became too lengthy)

Iterative deepening would probably be the easiest "fix" for this question. Simply stick the alpha-beta search into a loop that steadily increases the depth that alpha-beta goes to. You can include a couple tests within your loop to get it to terminate early (e.g. a winning move found).

ex:

while (!win_found && depth < 8)
{
    alphaBetaSearch(win_found, depth);
    depth++;
}

Iterative deepening may seem wasteful because states are generated multiple times, but it turns out this is not that costly. The reason for this is that in a search tree with the same (or nearly same branching factor at each level, most of the nodes are in the bottom level so it does not matter much that the upper levels are generated multiple times.

AndyG
  • 39,700
  • 8
  • 109
  • 143
0

If you write in compiled language you can search the whole tree from 1st move whitout any heuristics in less than second (just alpha beta and eval function which return -1,0,+1), othervise it should not take more than 5 seconds for first move and much less for other moves.

Luka Rahne
  • 10,336
  • 3
  • 34
  • 56
0

At the beginning of the alpha beta pruning function, I assume you have something like this:

function alphabeta(node, α, β, maximizingPlayer) is
    if node is a terminal node then
        return 100

Instead, if you are in a terminal node, calculate the number of empty squares and add it to the value of the node.

function alphabeta(node, α, β, maximizingPlayer) is
    if node is a terminal node then
        bonus = count_empty_squares(node)
        return 100 + bonus

The alpha beta algorithm will favor the fastest win.

JSB
  • 1
  • 2