Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions chess/board/chess_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion chess/chess_game.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
7 changes: 7 additions & 0 deletions chess/movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
1 change: 1 addition & 0 deletions chess/piece/piece.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down