def __repr__(self): # type: () -> str """ :return: A concise string representation of the state in one line """ rep = "The game is in phase: {}\n".format(self.__phase) rep += "Player 1's points: {}, pending: {}\n".format(self.__p1_points, self.__p1_pending_points) rep += "Player 2's points: {}, pending: {}\n".format(self.__p2_points, self.__p2_pending_points) rep += "The trump suit is: {}\n".format(self.get_trump_suit()) rep += "Player 1's hand:" for card in self.__deck.get_player_hand(1): rank, suit = util.get_card_name(card) rep += " {}{}".format(rank, suit) rep += "\n" rep += "Player 2's hand:" for card in self.__deck.get_player_hand(2): rank, suit = util.get_card_name(card) rep += " {}{}".format(rank, suit) rep += "\n" rep += "There are {} cards in the stock\n".format(self.__deck.get_stock_size()) trick = self.__deck.get_trick() if trick[0] is not None: rep += "Player 1 has played card: {} of {}\n".format(util.get_rank(trick[0]), util.get_suit(trick[0])) if trick[1] is not None: rep += "Player 2 has played card: {} of {}\n".format(util.get_rank(trick[1]), util.get_suit(trick[1])) return rep
def get_move(self, state): moves = state.moves() random.shuffle(moves) for move in moves: if not self.kb_consistent_trumpace(state, move): # Plays the first move that makes the kb inconsistent. We do not take # into account that there might be other valid moves according to the strategy. # Uncomment the next line if you want to see that something happens. # print "Strategy Applied" print "Card played (trump):" print util.get_card_name(move[0]) return move if not self.kb_consistent_trumpten(state, move): print "Card played (trump):" print util.get_card_name(move[0]) print move return move if not self.kb_consistent_ten(state, move): print "Card played (non-trump):" print util.get_card_name(move[0]) return move if not self.kb_consistent_jack(state, move): print "Card played (non-trump/trump):" print util.get_card_name(move[0]) return move # If no move that is entailed by the kb is found, play random move return random.choice(moves)
def get_move(self, state): self.player = state.whose_turn() if state.get_phase() == 1: try: state = state.make_assumption() except: pass if bestRoot is None: self.root = Node() self.root.state = state if self.debug: if self.root.state.get_opponents_played_card() is not None: self.root.card = util.get_card_name( self.root.state.get_opponents_played_card()) print(self.root.card[0], self.root.card[1]) else: print("Started With An Empty Deck") print("Trump suit is: ", self.root.state.get_trump_suit()) print("Start...\n") self.expansion(self.root) else: if self.root.state.get_opponents_played_card() is not None: self.root = bestRoot else: for nodes in bestRoot.children: if state == nodes.state: self.root = nodes.state break return self.root.state.moves()[self.MCTS(state)]
def expansion(self, currentNode=Node()): state = currentNode.state for move in state.moves(): #Play the card and set the state acording to the result st = state.clone() childNode = Node() #if st.finished() is not True: NOT SURE IF THIS IS A SOLUTION BUT PROBABLY IS st = st.next(move) childNode.state = st childNode.parent = currentNode #DEBUG ONLY if move[0] is not None: childNode.card = util.get_card_name(move[0]) currentNode.children.append(childNode) return
def expansion(self, currentNode=Node()): state = currentNode.state if state.finished() is True: return False for move in state.moves(): # Play the card and set the state acording to the result st = state.clone() childNode = Node() if st.finished() is True: return False st = st.next(move) childNode.state = st childNode.parent = currentNode currentNode.children.append(childNode) # DEBUG ONLY if move[0] is not None: childNode.card = util.get_card_name(move[0]) return True