Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/chess.py
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2012-07-25 09:56:24 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-07-25 09:56:24 (GMT)
commit526847bc2c4b939ecbc825fbdc63aa7ea00f1984 (patch)
tree9ef06c294949bc50de9bb2a504f1e270fc050e1a /chess.py
parentb9ed2a744835c961b25a86efbcb2a12e86603371 (diff)
add thinking cursor when computer is thinking
Diffstat (limited to 'chess.py')
-rw-r--r--chess.py81
1 files changed, 43 insertions, 38 deletions
diff --git a/chess.py b/chess.py
index fac17d7..c3243a2 100644
--- a/chess.py
+++ b/chess.py
@@ -176,6 +176,7 @@ class Gnuchess():
hint = output[len(ROBOT_MOVE):find(output, '\n')]
self._activity.status.set_label(hint)
self._parse_move(hint)
+ self._activity.restore_cursor()
return
elif 'Illegal move' in output:
self._activity.status.set_label(_('Illegal move'))
@@ -198,6 +199,7 @@ class Gnuchess():
else:
self._activity.white_entry.set_text(robot_move)
self._activity.black_entry.set_text('')
+ self._activity.restore_cursor()
elif my_move is not None:
if 'wins' in output or 'loses' in output:
self.checkmate = True
@@ -217,8 +219,7 @@ class Gnuchess():
output = output[find(output, target):]
output = output[find(output, '\n'):]
if len(output) < 136:
- self._activity.status.set_label(_('bad board output'))
- _logger.debug('bad board output')
+ self._activity.status.set_label('???')
else:
self._load_board(output)
@@ -415,6 +416,7 @@ class Gnuchess():
self.black[4].get_xy())])
if self._activity.playing_robot and not self.checkmate:
+ self._activity.set_thinking_cursor()
self._activity.status.set_label('Thinking')
gobject.timeout_add(500, self.move, ROBOT)
@@ -435,6 +437,7 @@ class Gnuchess():
def hint(self):
# TODO: Lock out while robot is playing
+ self._activity.set_thinking_cursor()
self._activity.status.set_label('Thinking')
gobject.timeout_add(500, self.move, HINT)
@@ -581,7 +584,8 @@ class Gnuchess():
if piece in 'pP':
source_file, source_rank = self._search_for_pawn(
- piece, source_file, source_rank, capture_file, capture_rank)
+ piece, source_file, source_rank, capture_file, capture_rank,
+ capture=capture)
elif piece in 'rR':
source_file, source_rank = self._search_for_rook(
piece, source_file, source_rank, capture_file, capture_rank)
@@ -602,41 +606,10 @@ class Gnuchess():
self._flash_tile(tiles)
def _search_for_pawn(
- self, piece, source_file, source_rank, capture_file, capture_rank):
- # Check for first move
- if piece == 'p' and capture_rank == '5':
- i = self._file_and_rank_to_index('%s7' % (capture_file))
- x, y = self._index_to_xy(i)
- for p in range(8):
- pos = self.black[8 + p].get_xy()
- if x == pos[0] and y == pos[1]:
- return capture_file, '7'
- elif piece == 'P' and capture_rank == '4':
- i = self._file_and_rank_to_index('%s2' % (capture_file))
- x, y = self._index_to_xy(i)
- for p in range(8):
- pos = self.white[8 + p].get_xy()
- if x == pos[0] and y == pos[1]:
- return capture_file, '2'
- # Check for previous space
- if piece == 'p':
- i = self._file_and_rank_to_index('%s%s' % (
- capture_file, RANKS[RANKS.index(capture_rank) + 1]))
- x, y = self._index_to_xy(i)
- for p in range(8):
- pos = self.black[8 + p].get_xy()
- if x == pos[0] and y == pos[1]:
- return capture_file, RANKS[RANKS.index(capture_rank) + 1]
- elif piece == 'P':
- i = self._file_and_rank_to_index('%s%s' % (
- capture_file, RANKS[RANKS.index(capture_rank) - 1]))
- x, y = self._index_to_xy(i)
- for p in range(8):
- pos = self.white[8 + p].get_xy()
- if x == pos[0] and y == pos[1]:
- return capture_file, RANKS[RANKS.index(capture_rank) - 1]
+ self, piece, source_file, source_rank, capture_file, capture_rank,
+ capture=False):
# Check for capture
- if piece == 'p':
+ if capture and piece == 'p':
if source_file == capture_file:
f = FILES.index(capture_file)
if f > 0:
@@ -666,7 +639,7 @@ class Gnuchess():
if x == pos[0] and y == pos[1]:
return source_file, \
RANKS[RANKS.index(capture_rank) + 1]
- if piece == 'P':
+ if capture and piece == 'P':
if source_file == capture_file:
f = FILES.index(capture_file)
if f > 0:
@@ -696,6 +669,38 @@ class Gnuchess():
if x == pos[0] and y == pos[1]:
return source_file, \
RANKS[RANKS.index(capture_rank) - 1]
+ # Check for first move
+ if piece == 'p' and capture_rank == '5':
+ i = self._file_and_rank_to_index('%s7' % (capture_file))
+ x, y = self._index_to_xy(i)
+ for p in range(8):
+ pos = self.black[8 + p].get_xy()
+ if x == pos[0] and y == pos[1]:
+ return capture_file, '7'
+ elif piece == 'P' and capture_rank == '4':
+ i = self._file_and_rank_to_index('%s2' % (capture_file))
+ x, y = self._index_to_xy(i)
+ for p in range(8):
+ pos = self.white[8 + p].get_xy()
+ if x == pos[0] and y == pos[1]:
+ return capture_file, '2'
+ # Check for previous space
+ if piece == 'p':
+ i = self._file_and_rank_to_index('%s%s' % (
+ capture_file, RANKS[RANKS.index(capture_rank) + 1]))
+ x, y = self._index_to_xy(i)
+ for p in range(8):
+ pos = self.black[8 + p].get_xy()
+ if x == pos[0] and y == pos[1]:
+ return capture_file, RANKS[RANKS.index(capture_rank) + 1]
+ elif piece == 'P':
+ i = self._file_and_rank_to_index('%s%s' % (
+ capture_file, RANKS[RANKS.index(capture_rank) - 1]))
+ x, y = self._index_to_xy(i)
+ for p in range(8):
+ pos = self.white[8 + p].get_xy()
+ if x == pos[0] and y == pos[1]:
+ return capture_file, RANKS[RANKS.index(capture_rank) - 1]
return capture_file, capture_rank
def _search_for_rook(