Commit be0af1a5 authored by Brendan Taylor's avatar Brendan Taylor

couple of quick bugfixes

parent d15b9dea
......@@ -23,7 +23,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
# the other party terminated the session. we'll keep the control around, though.
stanza_session.EncryptedStanzaSession.acknowledge_termination(self)
self.control.session = None
if self.control:
self.control.session = None
# remove events associated with this session from the queue
def remove_events(self, types):
......
......@@ -253,6 +253,7 @@ class TicTacToeBoard:
self.setup_window()
# check if the last move (at row r and column c) won the game
def check_for_strike(self, p, r, c, strike):
# number in a row: up and down, left and right
tallyI = 0
......@@ -268,36 +269,31 @@ class TicTacToeBoard:
c -= 1
for d in xrange(-strike, strike):
r_in_range = 0 <= r+d < self.rows
c_in_range = 0 <= c+d < self.cols
# vertical check
try:
if r_in_range:
tallyI = tallyI + 1
if self.board[r+d][c] != p:
tallyI = 0
except IndexError:
pass
# horizontal check
try:
if c_in_range:
tally_ = tally_ + 1
if self.board[r][c+d] != p:
tally_ = 0
except IndexError:
pass
# diagonal checks
try:
if r_in_range and c_in_range:
tallyL = tallyL + 1
if self.board[r+d][c+d] != p:
tallyL = 0
except IndexError:
pass
try:
if r_in_range and 0 <= c-d < self.cols:
tallyF = tallyF + 1
if self.board[r+d][c-d] != p:
tallyF = 0
except IndexError:
pass
if any([t == strike for t in (tallyL, tallyF, tallyI, tally_)]):
return True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment