summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2007-07-24 04:56:27 +0200
committerGuillaume Seguin <guillaume@segu.in>2007-07-24 04:56:27 +0200
commita9d0c54a31af96bc46e9f2ec10d276678a6e918c (patch)
tree4031d4d02867bad4870a938284acd0f09d6c0e2a
parent7c47de1c9b40faf52eaf939f5e67fc7b19b6b686 (diff)
downloadtictactoe-a9d0c54a31af96bc46e9f2ec10d276678a6e918c.tar.gz
tictactoe-a9d0c54a31af96bc46e9f2ec10d276678a6e918c.tar.bz2
* Fix AI -_-
-rwxr-xr-xtictactoe.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/tictactoe.py b/tictactoe.py
index b83b169..53e22be 100755
--- a/tictactoe.py
+++ b/tictactoe.py
@@ -118,46 +118,54 @@ class gtkTicTacToe (gtk.DrawingArea):
xv1 = self._map[i][0]
xv2 = self._map[i][1]
yv1 = self._map[0][i]
- yv2 = self._map[0][1]
- if xv1 == COMPUTER_ID and xv1 == xv2:
+ yv2 = self._map[1][i]
+ if xv1 == COMPUTER_ID and xv1 == xv2 and not self._map[i][2]:
self._map[i][2] = COMPUTER_ID
return
- elif xv1 == COMPUTER_ID and self._map[i][2] == xv1:
+ elif xv1 == COMPUTER_ID and self._map[i][2] == xv1 \
+ and not self._map[i][1]:
self._map[i][1] = COMPUTER_ID
return
- elif xv2 == COMPUTER_ID and self._map[i][2] == xv2:
+ elif xv2 == COMPUTER_ID and self._map[i][2] == xv2 \
+ and not self._map[i][0]:
self._map[i][0] = COMPUTER_ID
return
- if yv1 == COMPUTER_ID and yv1 == yv2:
+ if yv1 == COMPUTER_ID and yv1 == yv2 and not self._map[2][i]:
self._map[2][i] = COMPUTER_ID
return
- elif yv1 == COMPUTER_ID and self._map[2][i] == yv1:
+ elif yv1 == COMPUTER_ID and self._map[2][i] == yv1 \
+ and not self._map[1][i]:
self._map[1][i] = COMPUTER_ID
return
- elif yv2 == COMPUTER_ID and self._map[2][i] == yv2:
+ elif yv2 == COMPUTER_ID and self._map[2][i] == yv2 \
+ and not self._map[0][i]:
self._map[0][i] = COMPUTER_ID
return
for i in range (3):
xv1 = self._map[i][0]
xv2 = self._map[i][1]
yv1 = self._map[0][i]
- yv2 = self._map[0][1]
- if xv1 == PLAYER_ID and xv1 == xv2:
+ yv2 = self._map[1][i]
+ if xv1 == PLAYER_ID and xv1 == xv2 and not self._map[i][2]:
self._map[i][2] = COMPUTER_ID
return
- elif xv1 == PLAYER_ID and self._map[i][2] == xv1:
+ elif xv1 == PLAYER_ID and self._map[i][2] == xv1 \
+ and not self._map[i][1]:
self._map[i][1] = COMPUTER_ID
return
- elif xv2 == PLAYER_ID and self._map[i][2] == xv2:
+ elif xv2 == PLAYER_ID and self._map[i][2] == xv2 \
+ and not self._map[i][0]:
self._map[i][0] = COMPUTER_ID
return
- if yv1 == PLAYER_ID and yv1 == yv2:
+ if yv1 == PLAYER_ID and yv1 == yv2 and not self._map[2][i]:
self._map[2][i] = COMPUTER_ID
return
- elif yv1 == PLAYER_ID and self._map[2][i] == yv1:
+ elif yv1 == PLAYER_ID and self._map[2][i] == yv1 \
+ and not self._map[1][i]:
self._map[1][i] = COMPUTER_ID
return
- elif yv2 == PLAYER_ID and self._map[2][i] == yv2:
+ elif yv2 == PLAYER_ID and self._map[2][i] == yv2 \
+ and not self._map[0][i]:
self._map[0][i] = COMPUTER_ID
return
cells = self.empty_cells ()