def kb_jack(self, state, move): # type: (State, move) -> bool # each time we check for consistency we initialise a new knowledge-base kb = KB() # Add general information about the game load_greedy.general_information(kb) # Add the necessary knowledge about the strategy load_greedy.strategy_knowledge(kb) # This line stores the index of the card in the deck. # If this doesn't make sense, refer to _deck.py for the card index mapping index = move[0] # This creates the string which is used to make the strategy_variable. # Note that as far as kb.py is concerned, two objects created with the same # string in the constructor are equivalent, and are seen as the same symbol. # Here we use "pj" to indicate that the card with index "index" should be played with the # PlayJack heuristics that was defined in class. Initialise a different variable if # you want to apply a different strategy (that you will have to define in load.py) variable_string = "pj" + str(index) strategy_variable = Boolean(variable_string) # Add the relevant clause to the loaded knowledge base kb.add_clause(~strategy_variable) # If the knowledge base is not satisfiable, the strategy variable is # entailed (proof by refutation) return kb.satisfiable()
def kb_consistent_trumpjack(self, state, move): # type: (State, move) -> bool # each time we check for consistency we initialise a new knowledge-base kb = KB() # Add general information about the game suit = State.get_trump_suit(state) if suit == "C": index = 4 variable_string = "tj" + str(index) strategy_variable = Boolean(variable_string) kb.add_clause(strategy_variable) elif suit == "D": index = 9 variable_string = "tj" + str(index) strategy_variable = Boolean(variable_string) kb.add_clause(strategy_variable) elif suit == "H": index = 14 variable_string = "tj" + str(index) strategy_variable = Boolean(variable_string) kb.add_clause(strategy_variable) elif suit == "S": index = 19 variable_string = "tj" + str(index) strategy_variable = Boolean(variable_string) kb.add_clause(strategy_variable) load_greedy.general_information(kb) # Add the necessary knowledge about the strategy load_greedy.strategy_knowledge(kb) # This line stores the index of the card in the deck. # If this doesn't make sense, refer to _deck.py for the card index mapping index = move[0] variable_string = "ptj" + str(index) strategy_variable = Boolean(variable_string) # Add the relevant clause to the loaded knowledge base kb.add_clause(~strategy_variable) # If the knowledge base is not satisfiable, the strategy variable is # entailed (proof by refutation) return kb.satisfiable()
def kb_consistent_marriage(self, state, move): # type: (State, move) -> bool kb = KB() load_greedy.general_information(kb) load_greedy.strategy_knowledge(kb) card1 = move[0] card2 = move[1] variable_string = "m" + str(card1) + str(card2) strategy_variable = Boolean(variable_string) kb.add_clause(~strategy_variable) return kb.satisfiable()
def kb_trump(self,state,move): # type: (State,move) -> bool kb = KB() load_greedy.general_information(kb) load_greedy.strategy_knowledge(kb) p_card = move[0] p_card_suit = Deck.get_suit(p_card) trump_suit = state.get_trump_suit() variable_string = "wtt" + str(p_card_suit) + str(trump_suit) strategy_variable = Boolean(variable_string) kb.add_clause(~strategy_variable) return kb.satisfiable()