示例#1
0
    def __init__(self, player_order, card_nums=None):
        '''init for a particular clue game.
            player_order is a list of strings of players in the order that they
            are sitting around the table. Note: This may not include all the suspects,
            as there may be fewer than 6 players in any given game.

            card_nums is a list of numbers of cards in players' hands. It is
            possible that different players have different numbers of cards!
        '''
        self.players = player_order
        clauses = []

        # Each card is in at least one place (including case file).
        # If you want to change the string representation of the variables,
        #   go ahead!
        for c in CARDS:
            clause = ""
            for p in POSSIBLE_CARD_LOCATIONS:
                clause += c + "_" + p + " "
            clauses.append(clause)

        # TO BE IMPLEMENTED AS AN EXERCISE:
        """ -------------------my code------------------------------------------ """

        # ---------------------A card cannot be in two places.---------------------------
        for c in CARDS:
            clause = ""
            for i in range(POSSIBLE_CARD_LOCATIONS.__len__()):
                for j in range(i + 1, POSSIBLE_CARD_LOCATIONS.__len__()):
                    clause = "~" + c + "_" + POSSIBLE_CARD_LOCATIONS[
                        i] + " " + "~" + c + "_" + POSSIBLE_CARD_LOCATIONS[j]
                    clauses.append(clause)

        # --------------------At least one card of each category is in the case file.-------------------------------------
        def atLeast(cArr,
                    p):  ## cArr stands for card Array, p stands for position
            clause = ""
            for x in cArr:
                clause += x + "_" + p + " "
            clauses.append(clause)

        atLeast(SUSPECTS, CASE_FILE)
        atLeast(WEAPONS, CASE_FILE)
        atLeast(ROOMS, CASE_FILE)

        # --------------------No two cards in each category can both be in the case file.----------------------
        def atMost(cArr, p):
            clause = ""
            for i in range(cArr.__len__()):
                for j in range(i + 1, cArr.__len__()):
                    clause = "~" + cArr[i] + "_" + p + " " + "~" + cArr[
                        j] + "_" + p
                    clauses.append(clause)

        atMost(SUSPECTS, CASE_FILE)
        atMost(WEAPONS, CASE_FILE)
        atMost(ROOMS, CASE_FILE)

        self.KB = sat_interface.KB(clauses)
示例#2
0
def tt3():
    print()
    print("problem 3")
    example_prob3 = sat_interface.KB(
        ["~A ~C", "C A", "~B ~A", "~B ~C", "A C B", "~C B", "~B C"])
    #print(example_prob3.is_satisfiable())
    thislist3 = ["A", "B", "C"]
    showResult(thislist3, example_prob3)
示例#3
0
def tt2():
    print()
    print("problem 2")
    example_prob2 = sat_interface.KB(
        ["~A C", "~B ~C", "C B", "~C B ~A", "~B C", "A C"])
    #print(example_prob2.is_satisfiable())
    thislist2 = ["A", "B", "C"]
    showResult(thislist2, example_prob2)
示例#4
0
def salt():
    print()
    print("problem 4")
    example_prob4 = sat_interface.KB([
        "a b c", "~a ~b", "~a ~c", "~c ~b", "~A ~B ~C", "A B C", "~A b",
        "~B A", "~C ~c", "~b A", "~A B", "c C"
    ])
    #print(example_prob4.is_satisfiable())
    thislist4 = ["A", "B", "C", "a", "b", "c"]
    showResult(thislist4, example_prob4)
    print("----------caterpillar ate the salt---------")
示例#5
0
def bigLoop():
    mList = [20, 30, 40, 50, 60, 70, 80]
    nList = [5, 10, 15, 20]
    print("Running...")
    for m in mList:
        for n in nList:
            print("m=" + str(m) + " " + "n=" + str(n))
            Tnum = 0
            Fnum = 0
            for i in range(100):
                myKB = rand3cnf(m, n)
                prob = sat_interface.KB(myKB)
                if (prob.is_satisfiable() == True):
                    Tnum += 1
                else:
                    Fnum += 1
            print("True: " + str(Tnum) + "              False: " + str(Fnum))
    print("Finished")
示例#6
0
def golf():
    print()
    print("problem 5")
    example_prob5 = sat_interface.KB([
        "~aT bH",
        "~aH ~bH",
        "~bT bD",
        "~bH ~bD",
        "~cT bT",
        "~cH ~bT",
        "aT bT cT",
        "~aT ~bT",
        "~aT ~cT",
        "~bT ~cT",
        "aH bH cH",
        "~aH ~bH",
        "~aH ~cH",
        "~bH ~cH",
        "aD bD cD",
        "~aD ~bD",
        "~aD ~cD",
        "~bD ~cD",
        "aT aH aD",
        "~aT ~aH",
        "~aT ~aD",
        "~aH ~aD",
        "bT bH bD",
        "~bT ~bH",
        "~bT ~bD",
        "~bH ~bD",
        "cT cH cD",
        "~cT ~cH",
        "~cT ~cD",
        "~cH ~cD",
    ])
    #print(example_prob5.is_satisfiable())
    thislist5 = ["aH", "bH", "cH", "aD", "bD", "cD", "aT", "bT", "cT"]
    showResult(thislist5, example_prob5)
    print("-----------Tom, Harry, Dick------------")