コード例 #1
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()
コード例 #2
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 = ""
        if p_card < 5:
            p_card_suit = "C"
        elif p_card < 10:
            p_card_suit = "D"
        elif p_card < 15:
            p_card_suit = "H"
        elif p_card < 20:
            p_card_suit = "S"
        # 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()
コード例 #3
0
    def kb_acecard(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)
        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()
コード例 #4
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
コード例 #5
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()
コード例 #6
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()
コード例 #7
0
    def kb_consistent(self, state, move):
        # type: (State, move) -> bool

        index = move[0]

        if (Deck.get_suit(index) == state.get_trump_suit()):
            return True

        kb = self.prepareKB(state)

        load.strategy_knowledge(kb)

        variable_string = "pc" + str(index)
        strategy_variable = Boolean(variable_string)

        kb.add_clause(~strategy_variable)

        return kb.satisfiable()
コード例 #8
0
    def kb_consistent(self, state, move):
        # type: (State, move) -> bool

        index = move[0]

        # If a card is chosen by the KB, it will be played, doesn't matter if it is a trump
        # This will be an extremely rare case, possibility of this happening is very low

        if (Deck.get_rank(index) == "A"):
            return False

        kb = self.prepareKB(state)

        load.strategy_knowledge(kb)

        variable_string = "pc" + str(index)
        strategy_variable = Boolean(variable_string)

        kb.add_clause(~strategy_variable)

        return kb.satisfiable()
コード例 #9
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()
コード例 #10
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()
コード例 #11
0
ファイル: load.py プロジェクト: jakubclark/schnapsen
from kb import KB, Boolean, Integer

# Initialise all variables that you need for you strategies and game knowledge.
# First all possible cards:

# First all possible cards:
J0 = Boolean('j0')
J1 = Boolean('j1')
J2 = Boolean('j2')
J3 = Boolean('j3')
J4 = Boolean('j4')
J5 = Boolean('j5')
J6 = Boolean('j6')
J7 = Boolean('j7')
J8 = Boolean('j8')
J9 = Boolean('j9')
J10 = Boolean('j10')
J11 = Boolean('j11')
J12 = Boolean('j12')
J13 = Boolean('j13')
J14 = Boolean('j14')
J15 = Boolean('j15')
J16 = Boolean('j16')
J17 = Boolean('j17')
J18 = Boolean('j18')
J19 = Boolean('j19')

Q0 = Boolean('q0')
Q1 = Boolean('q1')
Q2 = Boolean('q2')
Q3 = Boolean('q3')
コード例 #12
0
ファイル: test5.py プロジェクト: pieterhop/intelligentsystems
import sys
from kb import KB, Boolean, Integer, Constant

# Define our propositional symbols
# a1 is true if the card with index 1 is an ace, etc
# You need to initialise all variables that you need for you strategies and game knowledge.
# Add those variables here.. The following list is complete for the Play ace strategy.
a0 = Boolean('a0')
a1 = Boolean('a1')
a2 = Boolean('a2')
a3 = Boolean('a3')
a4 = Boolean('a4')
a5 = Boolean('a5')
a6 = Boolean('a6')
a7 = Boolean('a7')
a8 = Boolean('a8')
a9 = Boolean('a9')
a10 = Boolean('a10')
a11 = Boolean('a11')
a12 = Boolean('a12')
a13 = Boolean('a13')
a14 = Boolean('a14')
a15 = Boolean('a15')
a16 = Boolean('a16')
a17 = Boolean('a17')
a18 = Boolean('a18')
a19 = Boolean('a19')
Pa0 = Boolean('pa0')
Pa1 = Boolean('pa1')
Pa2 = Boolean('pa2')
Pa3 = Boolean('pa3')
コード例 #13
0
ファイル: load.py プロジェクト: kevinrombout/schnapsen
from kb import KB, Boolean, Integer

# Initialise all variables that you need for you strategies and game knowledge.
# Add those variables here.. The following list is complete for the Play Jack strategy.
J0 = Boolean('j0')
J1 = Boolean('j1')
J2 = Boolean('j2')
J3 = Boolean('j3')
J4 = Boolean('j4')
J5 = Boolean('j5')
J6 = Boolean('j6')
J7 = Boolean('j7')
J8 = Boolean('j8')
J9 = Boolean('j9')
J10 = Boolean('j10')
J11 = Boolean('j11')
J12 = Boolean('j12')
J13 = Boolean('j13')
J14 = Boolean('j14')
J15 = Boolean('j15')
J16 = Boolean('j16')
J17 = Boolean('j17')
J18 = Boolean('j18')
J19 = Boolean('j19')

Q0 = Boolean('q0')
Q1 = Boolean('q1')
Q2 = Boolean('q2')
Q3 = Boolean('q3')
Q4 = Boolean('q4')
Q5 = Boolean('q5')
コード例 #14
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()
コード例 #15
0
ファイル: test4.py プロジェクト: CriMilanese/schnapsen_ml
import sys
from kb import KB, Boolean, Integer, Constant

# Define our propositional symbols
# A1 is true if the card with index 1 is a Aack, etc
# You need to initialise all variables that you need for you strategies and game knowledge.
# Add those variables here.. The following list is complete for the Play Aack strategy.
A0 = Boolean('a0')
A1 = Boolean('a1')
A2 = Boolean('a2')
A3 = Boolean('a3')
A4 = Boolean('a4')
A5 = Boolean('a5')
A6 = Boolean('a6')
A7 = Boolean('a7')
A8 = Boolean('a8')
A9 = Boolean('a9')
A10 = Boolean('a10')
A11 = Boolean('a11')
A12 = Boolean('a12')
A13 = Boolean('a13')
A14 = Boolean('a14')
A15 = Boolean('a15')
A16 = Boolean('a16')
A17 = Boolean('a17')
A18 = Boolean('a18')
A19 = Boolean('a19')
PA0 = Boolean('pa0')
PA1 = Boolean('pa1')
PA2 = Boolean('pa2')
PA3 = Boolean('pa3')
コード例 #16
0
from kb import KB, Boolean, Integer

# Initialise all variables that you need for you strategies and game knowledge.
# First all possible cards:
J0 = Boolean('j0')
J1 = Boolean('j1')
J2 = Boolean('j2')
J3 = Boolean('j3')
J4 = Boolean('j4')
J5 = Boolean('j5')
J6 = Boolean('j6')
J7 = Boolean('j7')
J8 = Boolean('j8')
J9 = Boolean('j9')
J10 = Boolean('j10')
J11 = Boolean('j11')
J12 = Boolean('j12')
J13 = Boolean('j13')
J14 = Boolean('j14')
J15 = Boolean('j15')
J16 = Boolean('j16')
J17 = Boolean('j17')
J18 = Boolean('j18')
J19 = Boolean('j19')

Q0 = Boolean('q0')
Q1 = Boolean('q1')
Q2 = Boolean('q2')
Q3 = Boolean('q3')
Q4 = Boolean('q4')
Q5 = Boolean('q5')
コード例 #17
0
ファイル: test4.py プロジェクト: rhmvu/VU-Intelligent-Systems
import kb, sys
from kb import KB, Boolean, Integer, Constant

# Define our propositional symbols
# J1 is true if the card with index 1 is a jack, etc
# You need to initialise all variables that you need for you strategies and game knowledge.
# Add those variables here.. The following list is complete for the Play Jack strategy.
J0 = Boolean('j0')
J1 = Boolean('j1')
J2 = Boolean('j2')
J3 = Boolean('j3')
J4 = Boolean('j4')
J5 = Boolean('j5')
J6 = Boolean('j6')
J7 = Boolean('j7')
J8 = Boolean('j8')
J9 = Boolean('j9')
J10 = Boolean('j10')
J11 = Boolean('j11')
J12 = Boolean('j12')
J13 = Boolean('j13')
J14 = Boolean('j14')
J15 = Boolean('j15')
J16 = Boolean('j16')
J17 = Boolean('j17')
J18 = Boolean('j18')
J19 = Boolean('j19')
PJ0 = Boolean('pj0')
PJ1 = Boolean('pj1')
PJ2 = Boolean('pj2')
PJ3 = Boolean('pj3')
コード例 #18
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())
コード例 #19
0
ファイル: load.py プロジェクト: louisepos/schnapsen
from kb import KB, Boolean, Integer

# Initialise all variables that you need for you strategies and game knowledge.
# Add those variables here.. The following list is complete for the Play Jack strategy.
J0 = Boolean('j0')
J1 = Boolean('j1')
J2 = Boolean('j2')
J3 = Boolean('j3')
J4 = Boolean('j4')
J5 = Boolean('j5')
J6 = Boolean('j6')
J7 = Boolean('j7')
J8 = Boolean('j8')
J9 = Boolean('j9')
J10 = Boolean('j10')
J11 = Boolean('j11')
J12 = Boolean('j12')
J13 = Boolean('j13')
J14 = Boolean('j14')
J15 = Boolean('j15')
J16 = Boolean('j16')
J17 = Boolean('j17')
J18 = Boolean('j18')
J19 = Boolean('j19')

Q0 = Boolean('q0')
Q1 = Boolean('q1')
Q2 = Boolean('q2')
Q3 = Boolean('q3')
Q4 = Boolean('q4')
Q5 = Boolean('q5')
コード例 #20
0
ファイル: load.py プロジェクト: jakubclark/schnapsen
from kb import KB, Boolean, Integer

# Initialise all variables that you need for you strategies and game knowledge.
# First all possible cards:
J0 = Boolean('j0')
J1 = Boolean('j1')
J2 = Boolean('j2')
J3 = Boolean('j3')
J4 = Boolean('j4')
J5 = Boolean('j5')
J6 = Boolean('j6')
J7 = Boolean('j7')
J8 = Boolean('j8')
J9 = Boolean('j9')
J10 = Boolean('j10')
J11 = Boolean('j11')
J12 = Boolean('j12')
J13 = Boolean('j13')
J14 = Boolean('j14')
J15 = Boolean('j15')
J16 = Boolean('j16')
J17 = Boolean('j17')
J18 = Boolean('j18')
J19 = Boolean('j19')

Q0 = Boolean('q0')
Q1 = Boolean('q1')
Q2 = Boolean('q2')
Q3 = Boolean('q3')
Q4 = Boolean('q4')
Q5 = Boolean('q5')
コード例 #21
0
from kb import KB, Boolean, Integer

# Initialise all variables that you need for you strategies and game knowledge.
# Add those variables here.. The following list is complete for the Play Jack strategy.
C0 = Boolean('c0')
C1 = Boolean('c1')
C2 = Boolean('c2')
C3 = Boolean('c3')
C4 = Boolean('c4')
C5 = Boolean('c5')
C6 = Boolean('c6')
C7 = Boolean('c7')
C8 = Boolean('c8')
C9 = Boolean('c9')
C10 = Boolean('c10')
C11 = Boolean('c11')
C12 = Boolean('c12')
C13 = Boolean('c13')
C14 = Boolean('c14')
C15 = Boolean('c15')
C16 = Boolean('c16')
C17 = Boolean('c17')
C18 = Boolean('c18')
C19 = Boolean('c19')
PC0 = Boolean('pc0')
PC1 = Boolean('pc1')
PC2 = Boolean('pc2')
PC3 = Boolean('pc3')
PC4 = Boolean('pc4')
PC5 = Boolean('pc5')
PC6 = Boolean('pc6')
コード例 #22
0
from kb import KB, Boolean, Integer

# The variables initialized below need to be initialized to use different strategies. We can reduce these variables
# if we plan to use a strategy where all of them are not being used.

A0 = Boolean('a0')
T0 = Boolean('t0')
K0 = Boolean('k0')
Q0 = Boolean('q0')
J0 = Boolean('j0')
A1 = Boolean('a1')
T1 = Boolean('t1')
K1 = Boolean('k1')
Q1 = Boolean('q1')
J1 = Boolean('j1')
A2 = Boolean('a2')
T2 = Boolean('t2')
K2 = Boolean('k2')
Q2 = Boolean('q2')
J2 = Boolean('j2')
A3 = Boolean('a3')
T3 = Boolean('t3')
K3 = Boolean('k3')
Q3 = Boolean('q3')
J3 = Boolean('j3')
A4 = Boolean('a4')
T4 = Boolean('t4')
K4 = Boolean('k4')
Q4 = Boolean('q4')
J4 = Boolean('j4')
A5 = Boolean('a5')
コード例 #23
0
ファイル: test4.py プロジェクト: louisepos/schnapsen
import kb, sys
from kb import KB, Boolean, Integer, Constant

# Define our propositional symbols
# J1 is true if the card with index 1 is a jack, etc
# You need to initialise all variables that you need for you strategies and game knowledge.
# Add those variables here.. The following list is complete for the Play Jack strategy.
J0 = Boolean('j0')
J1 = Boolean('j1')
J2 = Boolean('j2')
J3 = Boolean('j3')
J4 = Boolean('j4')
J5 = Boolean('j5')
J6 = Boolean('j6')
J7 = Boolean('j7')
J8 = Boolean('j8')
J9 = Boolean('j9')
J10 = Boolean('j10')
J11 = Boolean('j11')
J12 = Boolean('j12')
J13 = Boolean('j13')
J14 = Boolean('j14')
J15 = Boolean('j15')
J16 = Boolean('j16')
J17 = Boolean('j17')
J18 = Boolean('j18')
J19 = Boolean('j19')
PJ0 = Boolean('pj0')
PJ1 = Boolean('pj1')
PJ2 = Boolean('pj2')
PJ3 = Boolean('pj3')
コード例 #24
0
ファイル: load_clever.py プロジェクト: louisepos/schnapsen
from kb import KB, Boolean, Integer

# Initialise all variables that you need for you strategies and game knowledge.
# Add those variables here.. The following list is complete for the Play Jack strategy.
# Jacks
J0 = Boolean('j0')
J1 = Boolean('j1')
J2 = Boolean('j2')
J3 = Boolean('j3')
J4 = Boolean('j4')
J5 = Boolean('j5')
J6 = Boolean('j6')
J7 = Boolean('j7')
J8 = Boolean('j8')
J9 = Boolean('j9')
J10 = Boolean('j10')
J11 = Boolean('j11')
J12 = Boolean('j12')
J13 = Boolean('j13')
J14 = Boolean('j14')
J15 = Boolean('j15')
J16 = Boolean('j16')
J17 = Boolean('j17')
J18 = Boolean('j18')
J19 = Boolean('j19')

#Queens
Q0 = Boolean('q0')
Q1 = Boolean('q1')
Q2 = Boolean('q2')
Q3 = Boolean('q3')
コード例 #25
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())
コード例 #26
0
import kb, sys
from kb import KB, Boolean, Integer, Constant

# Define our propositional symbols
# T1 is true if the card with index 1 is a tack, etc
# You need to initialise all variables that you need for you strategies and game knowledge.
# Add those variables here.. The following list is complete for the Play Tack strategy.
T0 = Boolean('t0')
T1 = Boolean('t1')
T2 = Boolean('t2')
T3 = Boolean('t3')
T4 = Boolean('t4')
T5 = Boolean('t5')
T6 = Boolean('t6')
T7 = Boolean('t7')
T8 = Boolean('t8')
T9 = Boolean('t9')
T10 = Boolean('t10')
T11 = Boolean('t11')
T12 = Boolean('t12')
T13 = Boolean('t13')
T14 = Boolean('t14')
T15 = Boolean('t15')
T16 = Boolean('t16')
T17 = Boolean('t17')
T18 = Boolean('t18')
T19 = Boolean('t19')


A0 = Boolean('a0')
A1 = Boolean('a1')