Skip to content

Commit

Permalink
Reduced the amount of checking going on in Board.play.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbradberry committed Feb 3, 2015
1 parent d3318f2 commit 4cca938
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions t3/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ def play(self, state, play):
state = list(state)
state[-1] = 3 - player
state[board_index + player_index] |= self.positions[(r, c)]
updated_board = state[board_index + player_index]

full = (state[board_index] | state[board_index+1] == 0x1ff)
if (full or any(state[board_index] & w == w for w in self.wins)):
if any(updated_board & w == w for w in self.wins):
state[18 + player_index] |= self.positions[(R, C)]
elif full:
state[18] |= self.positions[(R, C)]
if (full or any(state[board_index+1] & w == w for w in self.wins)):
state[19] |= self.positions[(R, C)]

if (state[18] | state[19]) & self.positions[(r, c)]:
Expand Down

0 comments on commit 4cca938

Please sign in to comment.