Recursive minimax routine
- I've been writing a program to play connect4 using a recursive minimax
routine to choose the best move. It doesn't seem to work properly.
Is there a limit to how much recursion is supported with Chipmunk
Basic? Even if I set the depth parameter to 2 it quickly seems to
become stupid and simply returns x=1 for the best move.
If it's useful, here's the routine I've written:
6000 sub minimax(depth,player,smax,smin,pmax,pmin,score,m,sc)
6005 loopcount = loopcount+1
6010 smax = -10000000 : smin = 10000000 : pmax = 1 : pmin = 1 : score = 0
6020 for m = 1 to 7
6030 if board(m,6) <> 0 then goto 6100
6040 call setboard(m,player,0)
6050 if depth = 0 then sc = boardeval()
6060 if depth > 0 then sc = minimax(depth-1,3-player)
6070 if sc > smax then smax = sc : pmax = m
6080 if sc < smin then smin = sc : pmin = m
6090 call eraseboard(m)
6100 next m
6110 if player = 1 then score = smin : position = pmin
6120 if player = 2 then score = smax : position = pmax
6130 return (score)
The loopcount variable is a global, which I've been using to get an
idea of how many times the procedure gets called. 1957 seems to be
the maximum for a single move, whatever depth I specify.
- I've now realised there is no problem with the algorithm - it works
just fine. The problem was in another part of the program where I'd
made some extremely simple mistakes which were hard to spot because
they were so stupid! All fixed now, and with a depth of 4 I've not
been able to beat my own program at Connect4 - probably because I'm
rubbish at connect4!