[Tutor] Dots-And-Boxes
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Sun, 2 Jun 2002 18:53:52 -0700 (PDT)
> > > P.S.: There is one point, which is not completely clear to me:
> > > Danny's algorithm always assigns only one square to the player who
> > > did the last move, even if his draw completes two squares, So in the
> > > end the sum of the points may be less than (w-1)*(h-1). Is this
> > > according to the rules of the game?
> > >
> >
> > no. If your move boxes in any number of squares you get all of them.
>
> Yikes, that's a bug in my program then! I completely forgot about
> double-cross moves. I'll try to fix this tonight; thanks for reminding me
> about this!
Ok, fixed, I think. I took Gregor's suggestions, and now my
_isSquareMove() returns a list of squares instead of just one potential
square.
At most 2 squares can be created by a move, via a "double-crossed" move.
The following play shows how this can be done:
###
dyoo@coffeetable:~/dots-and-boxes$ python board.py
Turn 1 (Player 0)
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
Move? (0, 0), (0, 1)
Turn 2 (Player 1)
+ + + + +
+ + + + +
+ + + + +
+ + + + +
|
+ + + + +
Move? (0, 1), (1, 1)
Turn 3 (Player 0)
+ + + + +
+ + + + +
+ + + + +
+--+ + + +
|
+ + + + +
Move? (1, 1), (2, 1)
Turn 4 (Player 1)
+ + + + +
+ + + + +
+ + + + +
+--+--+ + +
|
+ + + + +
Move? (2, 1), (2, 0)
Turn 5 (Player 0)
+ + + + +
+ + + + +
+ + + + +
+--+--+ + +
| |
+ + + + +
Move? (2, 0), (1, 0)
Turn 6 (Player 1)
+ + + + +
+ + + + +
+ + + + +
+--+--+ + +
| |
+ +--+ + +
Move? (1, 0), (0, 0)
Turn 7 (Player 0)
+ + + + +
+ + + + +
+ + + + +
+--+--+ + +
| |
+--+--+ + +
Move? (1, 1), (1, 0)
Square completed.
Turn 8 (Player 0)
+ + + + +
+ + + + +
+ + + + +
+--+--+ + +
|0 |0 |
+--+--+ + +
###
So this should fix things properly now. I've updated my source code, so
you can download it again:
http://hkn.eecs.berkeley.edu/~dyoo/python/dots-and-boxes/board.py
Thanks again!