示例#1
0
    def kb_consistent(self, state, depth, alpha, beta):
        # type: (State, int, float, float) -> bool
        """
        Check whether the current state contradicts our knowledge.
        (The knowledge base describes what properties a state should satisfy  to be explored)
        """
        v = Integer("v") # the heuristic value when the maximu m depth is reached
        a = Integer("a") # alpha
        b = Integer("b") # beta
        m = Integer("m") # how many ships player one will have (when the heuristic is computed)
        h = Integer("h") # how many ships player two will have

        kb = KB()

        # Add clauses
        ???
示例#2
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()
import kb, 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, c)
kb.add_clause(b)
kb.add_clause(d)

for model in kb.models():
    print model
示例#4
0
文件: test2.py 项目: mxdfr/Schnapsen
import kb, sys
from kb import KB, Boolean, Integer, Constant

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

sum = x + y
print(sum)

constraint = x + y + z > 1
print(constraint)

constraint = 1 < x + y + z
print(constraint)

constraint = x - (z + y) < x - (y - z)
print(constraint)

q = 15
constraint = q * x == x - (y - q * z)
print(constraint)
示例#5
0
WT24SS = Boolean('wt24SS')
WT14SS = Boolean('wt14SS')
WT04SS = Boolean('wt04SS')
WT23SS = Boolean('wt23SS')
WT13SS = Boolean('wt13SS')
WT03SS = Boolean('wt03SS')
WT12SS = Boolean('wt12SS')
WT02SS = Boolean('wt02SS')
WT01SS = Boolean('wt01SS')

WTTCC = Boolean('wttCC')
WTTDD = Boolean('wttDD')
WTTHH = Boolean('wttHH')
WTTSS = Boolean('wttSS')

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


def general_information(kb):
    # GENERAL INFORMATION ABOUT THE CARDS
    kb.add_clause(J4)
    kb.add_clause(J9)
    kb.add_clause(J14)
    kb.add_clause(J19)

    kb.add_clause(Q3)
    kb.add_clause(Q8)
    kb.add_clause(Q13)