couple of quick bugfixes
This commit is contained in:
parent
d15b9dea6e
commit
be0af1a56b
|
@ -23,6 +23,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
# the other party terminated the session. we'll keep the control around, though.
|
# the other party terminated the session. we'll keep the control around, though.
|
||||||
stanza_session.EncryptedStanzaSession.acknowledge_termination(self)
|
stanza_session.EncryptedStanzaSession.acknowledge_termination(self)
|
||||||
|
|
||||||
|
if self.control:
|
||||||
self.control.session = None
|
self.control.session = None
|
||||||
|
|
||||||
# remove events associated with this session from the queue
|
# remove events associated with this session from the queue
|
||||||
|
|
|
@ -253,6 +253,7 @@ class TicTacToeBoard:
|
||||||
|
|
||||||
self.setup_window()
|
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):
|
def check_for_strike(self, p, r, c, strike):
|
||||||
# number in a row: up and down, left and right
|
# number in a row: up and down, left and right
|
||||||
tallyI = 0
|
tallyI = 0
|
||||||
|
@ -268,36 +269,31 @@ class TicTacToeBoard:
|
||||||
c -= 1
|
c -= 1
|
||||||
|
|
||||||
for d in xrange(-strike, strike):
|
for d in xrange(-strike, strike):
|
||||||
|
r_in_range = 0 <= r+d < self.rows
|
||||||
|
c_in_range = 0 <= c+d < self.cols
|
||||||
|
|
||||||
# vertical check
|
# vertical check
|
||||||
try:
|
if r_in_range:
|
||||||
tallyI = tallyI + 1
|
tallyI = tallyI + 1
|
||||||
if self.board[r+d][c] != p:
|
if self.board[r+d][c] != p:
|
||||||
tallyI = 0
|
tallyI = 0
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# horizontal check
|
# horizontal check
|
||||||
try:
|
if c_in_range:
|
||||||
tally_ = tally_ + 1
|
tally_ = tally_ + 1
|
||||||
if self.board[r][c+d] != p:
|
if self.board[r][c+d] != p:
|
||||||
tally_ = 0
|
tally_ = 0
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# diagonal checks
|
# diagonal checks
|
||||||
try:
|
if r_in_range and c_in_range:
|
||||||
tallyL = tallyL + 1
|
tallyL = tallyL + 1
|
||||||
if self.board[r+d][c+d] != p:
|
if self.board[r+d][c+d] != p:
|
||||||
tallyL = 0
|
tallyL = 0
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
if r_in_range and 0 <= c-d < self.cols:
|
||||||
tallyF = tallyF + 1
|
tallyF = tallyF + 1
|
||||||
if self.board[r+d][c-d] != p:
|
if self.board[r+d][c-d] != p:
|
||||||
tallyF = 0
|
tallyF = 0
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if any([t == strike for t in (tallyL, tallyF, tallyI, tally_)]):
|
if any([t == strike for t in (tallyL, tallyF, tallyI, tally_)]):
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue