示例#1
0
    def kb_ace(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 = "pa" + 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()
示例#2
0
    def kb_consistent_trumpmarriage(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":
            card1 = 2
            card2 = 3
            variable_string = "m" + str(card1) + str(card2)
            strategy_variable = Boolean(variable_string)
            kb.add_clause(strategy_variable)
        elif suit == "D":
            card1 = 7
            card2 = 8
            variable_string = "m" + str(card1) + str(card2)
            strategy_variable = Boolean(variable_string)
            kb.add_clause(strategy_variable)
        elif suit == "H":
            card1 = 12
            card2 = 13
            variable_string = "m" + str(card1) + str(card2)
            strategy_variable = Boolean(variable_string)
            kb.add_clause(strategy_variable)
        elif suit == "S":
            card1 = 17
            card2 = 18
            variable_string = "m" + str(card1) + str(card2)
            strategy_variable = Boolean(variable_string)
            kb.add_clause(strategy_variable)

        load.general_information(kb)

        # Add the necessary knowledge about the strategy
        load.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 = "pm" + 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()
示例#3
0
    def prepareKB(self, state):
        readyKB = KB()

        for card in state.get_perspective(self):
            index = -1
            if card == "P1H" or card == "P2H" or card == "P1W" or card == "P2W":
                index = state.get_perspective(self).index(card)

            if index != -1:
                tempString = self.__RANKS[index % 5]
                tempString += str(index % 5)
                readyKB.add_clause(Boolean(tempString))

        return readyKB
示例#4
0
    def kb_consistent_marriage(self, state, move):
        # type: (State, move) -> bool

        kb = KB()
        load.general_information(kb)
        load.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()
示例#5
0
    def kb_consistent_low_non_trump(self, state, move):
        # type: (State, move) -> bool

        kb = KB()

        load.general_information(kb)
        load.strategy_knowledge(kb)

        card = move[0]
        trump_suit = state.get_trump_suit()

        variable_string = "pc" + str(card) + str(trump_suit)
        strategy_variable = Boolean(variable_string)

        kb.add_clause(~strategy_variable)

        return kb.satisfiable()
示例#6
0
    def kb_trump(self, state, move):

        # type: (State,move) -> bool

        kb = KB()

        load.general_information(kb)
        load.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()
示例#7
0
    def kb_consistent_matching_win(self, state, move):

        # type: (State,move) -> bool

        kb = KB()
        load_justabout.general_information(kb)
        load_justabout.strategy_knowledge(kb)

        opp_card = state.get_opponents_played_card()
        opp_card_suit = Deck.get_suit(opp_card)
        opp_card_rank = opp_card % 5

        p_card = move[0]
        p_card_suit = Deck.get_suit(p_card)
        p_card_rank = opp_card % 5

        variable_string = "wt" + str(p_card_rank) + str(opp_card_rank) + str(p_card_suit) + str(opp_card_suit)
        strategy_variable = Boolean(variable_string)

        kb.add_clause(~strategy_variable)

        return kb.satisfiable()
示例#8
0
    def kb_consistent_trump_win(self,state,move):

        # type: (State,move) -> bool

        kb = KB()

        load_justabout.general_information(kb)
        load_justabout.strategy_knowledge(kb)

        opp_card = state.get_opponents_played_card()
        opp_card_suit = Deck.get_suit(opp_card)
        opp_card_rank = opp_card & 5

        p_card = move[0]
        p_card_suit = Deck.get_suit(p_card)
        p_card_rank = p_card % 5

        trump_suit = state.get_trump_suit()

        constraint_a = Integer('me') > Integer('op')
        constraint_b = Integer('op') > Integer('me')

        if opp_card_suit == trump_suit:
            if p_card_suit == trump_suit:
                if opp_card_rank < p_card_rank:
                    strategy_variable = constraint_b
                else:
                    strategy_variable = constraint_a
            else:
                strategy_variable = constraint_b
        else:
            variable_string = "wtt" + str(p_card_suit) + str(trump_suit)
            strategy_variable = Boolean(variable_string)


        kb.add_clause(~strategy_variable)

        return kb.satisfiable()
示例#9
0
import sys
from kb import KB, Boolean, Integer, Constant

# Define our symbols
A = Boolean('A')
B = Boolean('B')
C = Boolean('C')
D = Boolean('D')

# Create a new knowledge base
kb = KB()

# Add clauses
kb.add_clause(A, B)
kb.add_clause(~B, A)
kb.add_clause(C, ~A)
kb.add_clause(D, ~A)
kb.add_clause(~A, ~C, ~D)

# Print all models of the knowledge base
for model in kb.models():
    print(model)

# Print out whether the KB is satisfiable (if there are no models, it is not satisfiable)
print(kb.satisfiable())
# Create a new knowledge base
kb = KB()

# Add clauses
# kb.add_clause(A, B, C)
# kb.add_clause(~A, B)
# kb.add_clause(C)
# kb.add_clause(C)

# # Question 3
# kb.add_clause(A)
# kb.add_clause(C)
# kb.add_clause(D)
# kb.add_clause(~A)

# Question 4
kb.add_clause(A, B)
kb.add_clause(B, ~C)
kb.add_clause(~C, ~A)

# This needs to be unsatisfiable for entailment
kb.add_clause(A, ~B)
kb.add_clause(~A, B)

# Print all models of the knowledge base
for model in kb.models():
    print(model)

# Print out whether the KB is satisfiable (if there are no models, it is not satisfiable)
print("It is satisfiable" if kb.satisfiable() else "It is not satisfiable")
示例#11
0
PA11 = Boolean('pa11')
PA12 = Boolean('pa12')
PA13 = Boolean('pa13')
PA14 = Boolean('pa14')
PA15 = Boolean('pa15')
PA16 = Boolean('pa16')
PA17 = Boolean('pa17')
PA18 = Boolean('pa18')
PA19 = Boolean('pa19')

# Create a new knowledge base
kb = KB()

# GENERAL INFORMATION ABOUT THE CARDS
# This adds information which cards are Jacks
kb.add_clause(J4)
kb.add_clause(J9)
kb.add_clause(J14)
kb.add_clause(J19)
# Add here whatever is needed for your strategy.
kb.add_clause(A0)
kb.add_clause(A5)
kb.add_clause(A10)
kb.add_clause(A15)
# DEFINITION OF THE STRATEGY
# Add clauses (This list is sufficient for this strategy)
# PJ is the strategy to play jacks first, so all we need to model is all x PJ(x) <-> J(x),
# In other words that the PJ strategy should play a card when it is a jack
kb.add_clause(~J4, PJ4)
kb.add_clause(~J9, PJ9)
kb.add_clause(~J14, PJ14)
示例#12
0
#Trump suit
C = Boolean('c')
D = Boolean('d')
H = Boolean('h')
S = Boolean('s')


# Create a new knowledge base
kb = KB()

# GENERAL INFORMATION ABOUT THE CARDS
# This adds information which cards are Kings, Queens and Jacks


kb.add_clause(C2)
kb.add_clause(C3)
kb.add_clause(C4)
kb.add_clause(C7)
kb.add_clause(C8)
kb.add_clause(C9)
kb.add_clause(C12)
kb.add_clause(C13)
kb.add_clause(C14)
kb.add_clause(C17)
kb.add_clause(C18)
kb.add_clause(C19)

kb.add_clause(PC2, C2, ~C)
kb.add_clause(PC2, ~PC2, ~C)
kb.add_clause(~C2, C2, ~C)
示例#13
0
import sys
from kb import KB, Boolean, Integer, Constant

# Define our integer symbols
x = Integer('x')
y = Integer('y')

q = x == y
a = x + y > 2
b = x + y < 5
c = x + y < -2
d = x + y > -5

kb = KB()

kb.add_clause(q)
kb.add_clause(a, d)
kb.add_clause(a, c)
kb.add_clause(b, d)
kb.add_clause(b, c)

for model in kb.models():
    print(model)
示例#14
0
import sys
from kb import KB, Boolean, Integer, Constant

# Define our symbols
A = Boolean('A')
B = Boolean('B')
C = Boolean('C')
D = Boolean('D')

# Create a new knowledge base
kb = KB()

# KB
kb.add_clause(A, B)
kb.add_clause(A,~B)
kb.add_clause(~A,C)
kb.add_clause(~A,D)

# ~alpha
kb.add_clause(~A)
kb.add_clause(~B)
kb.add_clause(~C)

# Print all models of the knowledge base
for model in kb.models():
    print(model)

# Print out whether the KB is satisfiable (if there are no models, it is not satisfiable)
print(kb.satisfiable())
PJ11 = Boolean('pj11')
PJ12 = Boolean('pj12')
PJ13 = Boolean('pj13')
PJ14 = Boolean('pj14')
PJ15 = Boolean('pj15')
PJ16 = Boolean('pj16')
PJ17 = Boolean('pj17')
PJ18 = Boolean('pj18')
PJ19 = Boolean('pj19')

# Create a new knowledge base
kb = KB()

# GENERAL INFORMATION ABOUT THE CARDS
# This adds information which cards are Jacks
kb.add_clause(J4)
kb.add_clause(J9)
kb.add_clause(J14)
kb.add_clause(J19)
# Adds information on which cards are As
kb.add_clause(J0)
kb.add_clause(J5)
kb.add_clause(J10)
kb.add_clause(J15)

# DEFINITION OF THE STRATEGY
# Add clauses (This list is sufficient for this strategy)
# PJ is the strategy to play jacks first, so all we need to model is all x PJ(x) <-> J(x),
# In other words that the PJ strategy should play a card when it is a jack
kb.add_clause(~J4, PJ4)
kb.add_clause(~J9, PJ9)
示例#16
0
    def kb_consistent(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.general_information(kb)

        # Add the necessary knowledge about the strategy
        load.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)

        # # Always play trump
        trump_suit = state.get_trump_suit()
        trump = trump_suit.lower()
        if trump == 'c':
            pj = Boolean('pj4')
            pq = Boolean('pq3')
            pk = Boolean('pk2')
            pt = Boolean('pt1')
            pa = Boolean('pa0')
        if trump == 'd':
            pj = Boolean('pj9')
            pq = Boolean('pq8')
            pk = Boolean('pk7')
            pt = Boolean('pt6')
            pa = Boolean('pa5')
        if trump == 'h':
            pj = Boolean('pj14')
            pq = Boolean('pq13')
            pk = Boolean('pk12')
            pt = Boolean('pt11')
            pa = Boolean('pa10')
        if trump == 's':
            pj = Boolean('pj19')
            pq = Boolean('pq18')
            pk = Boolean('pk17')
            pt = Boolean('pt16')
            pa = Boolean('pa15')

        kb.add_clause(~pj, ~pq, ~pk, ~pt, ~pa)

        # # always play Jack
        # 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()
示例#17
0
P = Boolean('P')
Q = Boolean('Q')
R = Boolean('R')
#D = Boolean('D')

# Create a new knowledge base
kb = KB()

# Add clauses

# KB:
# {(P v Q)
# (Q -> R) => -Q | R
# (R -> -P)} => -R | -P

kb.add_clause(~P, Q)
kb.add_clause(~Q, R)
kb.add_clause(~R, ~P)

# alpha: (P <-> - Q) => P -> -Q & -Q -> P =>
# -P | -Q
# Q | P

# -alpha: -((-P | -Q) & (Q | P)) => -(-P|-Q) | -(Q|P) => (P & Q) | (-Q & -P) => (P|-Q),(P|-P),(Q|-Q),(Q|-P)
kb.add_clause(P, ~Q)
kb.add_clause(Q, ~P)

# Print all models that satisfy the knowledge base
for model in kb.models():
    print(model)
示例#18
0
PJ11 = Boolean('pj11')
PJ12 = Boolean('pj12')
PJ13 = Boolean('pj13')
PJ14 = Boolean('pj14')
PJ15 = Boolean('pj15')
PJ16 = Boolean('pj16')
PJ17 = Boolean('pj17')
PJ18 = Boolean('pj18')
PJ19 = Boolean('pj19')

# Create a new knowledge base
kb = KB()

# GENERAL INFORMATION ABOUT THE CARDS
# This adds information which cards are Jacks
kb.add_clause(J1)
kb.add_clause(J6)
kb.add_clause(J11)
kb.add_clause(J16)
# Add here whatever is needed for your strategy.

# DEFINITION OF THE STRATEGYcb
# Add clauses (This list is sufficient for this strategy)
# PJ is the strategy to play jacks first, so all we need to model is all x PJ(x) <-> J(x),
# In other words that the PJ strategy should play a card when it is a jack
kb.add_clause(~J1, PJ1)
kb.add_clause(~J6, PJ6)
kb.add_clause(~J11, PJ11)
kb.add_clause(~J16, PJ16)
kb.add_clause(~PJ1, J1)
kb.add_clause(~PJ6, J6)
示例#19
0
PJ11 = Boolean('pj11')
PJ12 = Boolean('pj12')
PJ13 = Boolean('pj13')
PJ14 = Boolean('pj14')
PJ15 = Boolean('pj15')
PJ16 = Boolean('pj16')
PJ17 = Boolean('pj17')
PJ18 = Boolean('pj18')
PJ19 = Boolean('pj19')

# Create a new knowledge base
kb = KB()

# GENERAL INFORMATION ABOUT THE CARDS
# This adds information which cards are Jacks
"""
kb.add_clause(J4)
kb.add_clause(J9)
kb.add_clause(J14)
kb.add_clause(J19)
"""
kb.add_clause(J0)
kb.add_clause(J5)
kb.add_clause(J10)
kb.add_clause(J15)
# Add here whatever is needed for your strategy.

# DEFINITION OF THE STRATEGY
# Add clauses (This list is sufficient for this strategy)
# PJ is the strategy to play jacks first, so all we need to model is all x PJ(x) <-> J(x),
# In other words that the PJ strategy should play a card when it is a jack
示例#20
0
import sys
from kb import KB, Boolean, Integer, Constant

# Define our integer symbols
x = Integer('x')
y = Integer('y')

q = x == y
a = x + y > 2
b = x + y < 5
c = x + y < -2
d = x + y > -5

kb = KB()

kb.add_clause(q)
kb.add_clause(c, a)
kb.add_clause(d, a)
kb.add_clause(c, b)
kb.add_clause(d, b)

for model in kb.models():
    print(model)
示例#21
0
PA11 = Boolean('pa11')
PA12 = Boolean('pa12')
PA13 = Boolean('pa13')
PA14 = Boolean('pa14')
PA15 = Boolean('pa15')
PA16 = Boolean('pa16')
PA17 = Boolean('pa17')
PA18 = Boolean('pa18')
PA19 = Boolean('pa19')

# Create a new knowledge base
kb = KB()

# GENERAL INFORMATION ABOUT THE CARDS
# This adds information which cards are Aces
kb.add_clause(A0)
kb.add_clause(A5)
kb.add_clause(A10)
kb.add_clause(A15)

# Add here whatever is needed for your strategy.

# DEFINITION OF THE STRATEGY
# Add clauses (This list is sufficient for this strategy)
# PA is the strategy to play Aces first, so all we need to model is all x PA(x) <-> A(x),
# In other words that the PA strategy should play a card when it is a Ace

kb.add_clause(~A0, PA0)
kb.add_clause(~A5, PA5)
kb.add_clause(~A10, PA10)
kb.add_clause(~A15, PA15)
示例#22
0
import sys
from kb import KB, Boolean, Integer, Constant

# Define our symbols
P = Boolean('P')
Q = Boolean('Q')
R = Boolean('R')

# Create P new knowledge base
kb = KB()

# KB
kb.add_clause(P, Q)
kb.add_clause(R, ~Q)
kb.add_clause(~P, ~R)

# ~alpha
kb.add_clause(P, ~Q)
kb.add_clause(~P, Q)

# Print all models of the knowledge base
for model in kb.models():
    print(model)

# Print out whether the KB is satisfiable (if there are no models, it is not satisfiable)
print(kb.satisfiable())
示例#23
0
import sys
from kb import KB, Boolean, Integer, Constant

# Define our integer symbols
x = Integer('x')
y = Integer('y')

q = x == y
a = x + y > 2
b = x + y < 5
c = x + y < -2
d = x + y > -5

kb = KB()

kb.add_clause(q)
kb.add_clause(a, c)
kb.add_clause(a, d)
kb.add_clause(b, c)
kb.add_clause(b, d)

for model in kb.models():
    print(model)
示例#24
0
Pa11 = Boolean('pa11')
Pa12 = Boolean('pa12')
Pa13 = Boolean('pa13')
Pa14 = Boolean('pa14')
Pa15 = Boolean('pa15')
Pa16 = Boolean('pa16')
Pa17 = Boolean('pa17')
Pa18 = Boolean('pa18')
Pa19 = Boolean('pa19')

# Create a new knowledge base
kb = KB()

# GENERAL INFORMATION ABOUT THE CARDS
# This adds information which cards are aacks
kb.add_clause(a0)
kb.add_clause(a5)
kb.add_clause(a10)
kb.add_clause(a15)
# Add here whatever is needed for your strategy.

# DEFINITION OF THE STRATEGY
# Add clauses (This list is sufficient for this strategy)
# Pa is the strategy to play aces first, so all we need to model is all x Pa(x) <-> a(x),
# In other words that the Pa strategy should play a card when it is an ace
kb.add_clause(~a0, Pa0)
kb.add_clause(~a5, Pa5)
kb.add_clause(~a10, Pa10)
kb.add_clause(~a15, Pa15)
kb.add_clause(~Pa0, a0)
kb.add_clause(~Pa5, a5)
示例#25
0
import sys
from kb import KB, Boolean, Integer, Constant

# Define our symbols
A = Boolean('A')
B = Boolean('B')
C = Boolean('C')

# Create a new knowledge base
kb = KB()

# Add clauses
kb.add_clause(A, B, C)
kb.add_clause(~A, B)
kb.add_clause(~B, C)
kb.add_clause(B, ~C)

# Our clause
kb.add_clause(~B,~C)

# Print all models of the knowledge base
for model in kb.models():
    print(model)

# Print out whether the KB is satisfiable (if there are no models, it is not satisfiable)
print(kb.satisfiable())
示例#26
0
import sys
from kb import KB, Boolean, Integer, Constant

# Define our integer symbols
x = Integer('x')
y = Integer('y')

q = x == y
a = x + y > 2
b = x + y < 5
c = x + y < -2
d = x + y > -5

kb = KB()

kb.add_clause(q)
kb.add_clause(???)
kb.add_clause(???)
kb.add_clause(???)
kb.add_clause(???)

for model in kb.models():
    print(model)
示例#27
0
import sys
from kb import KB, Boolean, Integer, Constant

# Define our symbols
Q = Boolean('Q')
P = Boolean('P')
R = Boolean('R')

# Create a new knowledge base
kb = KB()

# Add clauses
kb.add_clause(P, Q)
kb.add_clause(~Q, R)
kb.add_clause(~R, ~P)
kb.add_clause(Q, ~P)
kb.add_clause(P, ~Q)

# Print all models of the knowledge base
for model in kb.models():
    print(model)

# Print out whether the KB is satisfiable (if there are no models, it is not satisfiable)
print(kb.satisfiable())
示例#28
0
PC11 = Boolean('pc11')
PC12 = Boolean('pc12')
PC13 = Boolean('pc13')
PC14 = Boolean('pc14')
PC15 = Boolean('pc15')
PC16 = Boolean('pc16')
PC17 = Boolean('pc17')
PC18 = Boolean('pc18')
PC19 = Boolean('pc19')

# Create a new knowledge base
kb = KB()

# strategy: plays cheap card first (J, Q, K)
# This adds information which cards are Cheap
kb.add_clause(C2)
kb.add_clause(C3)
kb.add_clause(C4)
kb.add_clause(C7)
kb.add_clause(C8)
kb.add_clause(C9)
kb.add_clause(C12)
kb.add_clause(C13)
kb.add_clause(C14)
kb.add_clause(C17)
kb.add_clause(C18)
kb.add_clause(C19)

# all x PC(x) <-> C(x) => ~C | PC, ~PC | C
kb.add_clause(~C2, PC2)
kb.add_clause(~C3, PC3)