diff --git a/state.py b/state.py index 9440eaf..3af08e5 100644 --- a/state.py +++ b/state.py @@ -46,13 +46,22 @@ def piece(self, row, col): return self.board[row][col] def removePiece(self, row, col): - self.board[row][col] = None + self.board[row][col] = ' ' def placePiece(self, row, col, color): if(not self.board[row][col]): self.board[row][col] = color else: print("Error: attempted to place piece on occupied spot") + + def movePiece(self, from_position, to_position): + piece_color = piece(from_position[0],from_position[1]) + row_range = range(from_position[0], to_position[0]) + column_range = range(from_position[1], to_position[1]) + for x in row_range: + for y in column_range: + self.removePiece(x,y) + placePiece(to_position[0], to_position[1], piece_color) def __str__(self): string = "" @@ -143,7 +152,7 @@ def generate_moves(self, board, color): #Is there a blank space where we need to jump, and is there an opponent's piece to jump over? if (board[jump_to[0]][jump_to[1]] == ' ' and board[jump_to[0]+1][jump_to[1]] != ' '): #Append move if possible - possible_moves.append((row, col, jump_to[0], jump_to[1])) + possible_moves.append(((row, col), (jump_to[0], jump_to[1]))) #Update how far it'll jump next time (for multiple jumps) curr_pos = jump_to else: @@ -157,7 +166,7 @@ def generate_moves(self, board, color): #Is there a blank space where we need to jump, and is there an opponent's piece to jump over? if (board[jump_to[0]][jump_to[1]] == ' ' and board[jump_to[0]-1][jump_to[1]] != ' '): #Append move if possible - possible_moves.append((row, col, jump_to[0], jump_to[1])) + possible_moves.append(((row, col), (jump_to[0], jump_to[1]))) #Update how far it'll jump next time (for multiple jumps) curr_pos = jump_to else: @@ -172,7 +181,7 @@ def generate_moves(self, board, color): #Is there a blank space where we need to jump, and is there an opponent's piece to jump over? if (board[jump_to[0]][jump_to[1]] == ' ' and board[jump_to[0]][jump_to[1]-1] != ' '): #Append move if possible - possible_moves.append((row, col, jump_to[0], jump_to[1])) + possible_moves.append(((row, col,) (jump_to[0], jump_to[1]))) #Update how far you'll jump next time (for multiple jumps) curr_pos = jump_to else: @@ -186,13 +195,20 @@ def generate_moves(self, board, color): #Is there a blank space where we need to jump, and is there an opponent's piece to jump over? if (board[jump_to[0]][jump_to[1]] == ' ' and board[jump_to[0]][jump_to[1]+1] != ' '): #Append move if possible - possible_moves.append((row, col, jump_to[0], jump_to[1])) + possible_moves.append(((row, col), (jump_to[0], jump_to[1]))) #Update how far it'll jump next time (for multiple jumps) curr_pos = jump_to else: break return possible_moves + #Generate successors for moves, needs implemented + def generate_successors(self, board, color): + successors = [] + #for move in self.generate_moves(board, color): + + return successors + #Evaluation function def eval(self, board, playerColor, opponentColor): player_moves = self.generate_moves(playerColor)