From c972bcd4fe5f9a3bf35f16c0160afdc4d4698cbf Mon Sep 17 00:00:00 2001 From: Theo Voss Date: Wed, 26 Aug 2015 06:22:03 -0400 Subject: [PATCH] initial thoughts for tracking moves going to have to combine one_away and two_away into one aggregator function so a pawn can move either on their first turn. --- chess/board/chess_board.py | 1 + chess/chess_game.json | 2 +- chess/movement.py | 7 +++++++ chess/piece/piece.py | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/chess/board/chess_board.py b/chess/board/chess_board.py index e9918d7..8342f6a 100644 --- a/chess/board/chess_board.py +++ b/chess/board/chess_board.py @@ -59,6 +59,7 @@ def move(self, start_location, end_location): if end_location in possible_moves: self.board[end_location] = self.board[start_location] self.board[start_location] = None + self.board[end_location].num_moves += 1 return True return False diff --git a/chess/chess_game.json b/chess/chess_game.json index c59331d..6684ab0 100644 --- a/chess/chess_game.json +++ b/chess/chess_game.json @@ -3,7 +3,7 @@ "pawn": { "moves": [{ "directions": [[0, 1]], - "conditions": ["distance_of_one", "doesnt_land_on_piece", "distance_of_two_if_first_move", "away_from_start"] + "conditions": ["distance_of_one", "doesnt_land_on_piece", "distance_of_two_if_first_move", "away_from_start", "cant_jump_pieces"] }, { "directions": [[1, 1], [-1, 1]], diff --git a/chess/movement.py b/chess/movement.py index e340723..abf1287 100644 --- a/chess/movement.py +++ b/chess/movement.py @@ -12,6 +12,13 @@ def get_all_potential_end_locations(start, directions, board): return ends +def distance_of_two_if_first_move(board, start, directions, potential_end_locations): + if board[start].num_moves == 0: + two_away = [tuple(map(operator.add, tuple(map(operator.add, move, move)), start)) for move in directions] + return [x for x in two_away if x in potential_end_locations] + return [] + + def distance_of_one(board, start, directions, potential_end_locations): return [x for x in get_one_move_away(start, directions) if x in potential_end_locations] diff --git a/chess/piece/piece.py b/chess/piece/piece.py index 9315260..fe02390 100644 --- a/chess/piece/piece.py +++ b/chess/piece/piece.py @@ -6,6 +6,7 @@ def __init__(self, piece_name, piece_color, moves): self.kind = piece_name self.color = piece_color self.moves = moves + self.num_moves = 0 def __str__(self): return "{} {}".format(self.color, self.kind)