def update_available_placement(self, action): # to update the available actions in the placement phase we just need to read in the action made # remove this entry from the dictionary # add the entries of any eliminated positions in the dictionary elim = [] eliminated_pieces = self.board.eliminated_pieces_last_move( self.board.phase, self.board.move_counter, pop=False) #print("ELIMINATED: ",end='') #print(eliminated_pieces) #print("AVAILABLE: ",end='') #print(self.available_actions) for colour in (constant.WHITE_PIECE, constant.BLACK_PIECE): if Board.within_starting_area(action, colour): # remove the action from the entry of the dictionary if action in self.available_actions[colour]: self.available_actions[colour].pop(action) # add all the eliminated pieces to the available moves of the dictionary for piece in eliminated_pieces[colour]: elim.append(piece) for colour in (constant.WHITE_PIECE, constant.BLACK_PIECE): for piece in elim: if Board.within_starting_area(piece, colour): update_entry = {piece: constant.PLACEMENT_PHASE} self.available_actions[colour].update(update_entry)
def start_available_actions_placement(self): # get rid of all pieces that exist on the board for colour in (constant.BLACK_PIECE, constant.WHITE_PIECE): for piece in self.board.piece_pos[colour]: if piece in self.available_actions[constant.WHITE_PIECE]: if Board.within_starting_area(piece, constant.WHITE_PIECE): self.available_actions[constant.WHITE_PIECE].pop(piece) if Board.within_starting_area(piece, constant.BLACK_PIECE): self.available_actions[constant.BLACK_PIECE].pop(piece)
def init_available_placement_actions(self): # initialise the dictionary with the available placements on the board for row in range(constant.BOARD_SIZE): for col in range(constant.BOARD_SIZE): piece = col, row # print(col,row) for colour in (constant.WHITE_PIECE, constant.BLACK_PIECE): if Board.within_starting_area(piece, colour): temp = {piece: constant.PLACEMENT_PHASE} # print(temp) self.available_actions[colour].update(temp)
def action(self, turns): # print(self.board.piece_pos) # print(self.board.eliminated_pieces) # p rint("THIS BOARD REPRESENTATION") # self.board.print_board() # print("TURNS SO FAR ---------- " + str(turns)) # print("ACTION CALLED: BOARD REPRESENTATION COUNTER: " + str(self.board.move_counter)) if turns == 0 and self.board.phase == constant.PLACEMENT_PHASE: # then we are first person to move self.board.set_player_to_move(self.colour) if turns < 24 and self.board.phase == constant.PLACEMENT_PHASE: for colour in (constant.BLACK_PIECE, constant.WHITE_PIECE): for piece in self.board.eliminated_pieces[colour]: if (piece not in self.available_moves) and ( Board.within_starting_area(piece, self.colour)): self.available_moves.append(piece) # print("ACTION: ",end='') # print(piece) # then we pick the best move to make based on a search algorithm self.available_moves.sort() for i in range(len(self.available_moves)): print(str(i) + " : " + str(self.available_moves[i])) index = int(input("Enter move: ")) next_move = self.available_moves[index] # making moves during the placement phase self.board.update_board(next_move, self.colour) # print(self.board.eliminated_pieces) # print("EEEEEE") # print("BOARDS TURNS NOW ---------- " + str(self.board.move_counter)) for colour in (constant.BLACK_PIECE, constant.WHITE_PIECE): for piece in self.board.eliminated_pieces[colour]: if (piece not in self.available_moves) and ( Board.within_starting_area(piece, self.colour)): self.available_moves.append(piece) # print("ACTION: ",end='') # print(piece) print(self.available_moves) # remove the move made from the available moves self.available_moves.remove(next_move) ''' if len(eliminated_pieces) != 0: for piece in eliminated_pieces: print(piece) if piece in self.available_moves: self.available_moves.remove(piece) ''' return next_move elif self.board.phase == constant.MOVING_PHASE: if turns == 0 or turns == 1: # if the turns is 0 or 1 and the board is in moving phase then the # all players have placed their pieces on the board, we can call update_available_moves to update the # available moves available to this player # clear the list self.available_moves = [] # update the lists available moves -- now in the form ((col,row),move_type) # self.update_available_moves() # print(self.available_moves) # we are making a move in the moving phase #print(self.available_moves) self.update_available_moves() # if there are no available moves to be made we can return None: if len(self.available_moves) == 0: return None # print("AVAILABLE MOVES: " + str(self.colour) + " " + str(self.available_moves)) # if there is a move to be made we can return the best move # TODO : THIS IS WHERE WE CARRY OUT OUR SEARCH ALGORITHM # then we pick the best move to make based on a search algorithm self.available_moves.sort() for i in range(len(self.available_moves)): print(str(i) + " : " + str(self.available_moves[i])) index = int(input("Enter move: ")) next_move = self.available_moves[index] self.board.update_board(next_move, self.colour) new_pos = self.board.convert_move_type_to_coord( next_move[0], next_move[1]) # print(self.colour + " " + str(self.board.piece_pos)) # TODO - need to double check if this update_available_moves is necessary self.update_available_moves() #print(getsizeof(self.board.piece_pos)) #print(getsizeof(self.board.board_state)) #print(getsizeof(self.available_moves)) return next_move[0], new_pos