コード例 #1
0
rule_set = []

p = game_players.split()
combos = [x for l in range(1, len(game_players)) for x in combinations(p, l)]
for y in combos:
    if "A1" in y and ("C2" in y or "C3" in y) and "C1" not in y:
        rule_set.append(y)
    if "A2" in y and ("C1" in y or "C3" in y) and "C2" not in y:
        rule_set.append(y)
    if "A3" in y and ("C1" in y or "C2" in y) and "C3" not in y:
        rule_set.append(y)

    # m_count = "".join(y).count("M")
    # c_count = "".join(y).count("C")
    # if len(y) > 2 and m_count > 0 and c_count > m_count:
    #     too_many_criminals.append(list(y))

rules = " ".join(x for x in [",".join(x) for x in rule_set])
# print rules
# exit(0)

rcs.setPlayers(game_players)
rcs.setdrivers(game_players)
rcs.startLeft()
rcs.setgoalStatus("", game_players)
rcs.setinvalidBoat("")
rcs.setinvalidBank(rules)
rcs.setboatCapacity(2)

rcs.solve()
コード例 #2
0
import rivercrossingsolver as rcs

game_players = "1 2 3 4 5"

rcs.setPlayers(game_players)
rcs.setdrivers(game_players)
rcs.startLeft()
rcs.setgoalStatus("", game_players)
rcs.setinvalidBoat("1,2 2,3 3,4 4,5 5,1")
rcs.setinvalidBank("1,2 2,3 3,4 4,5 5,1")
rcs.setboatCapacity(2)

rcs.solve()
コード例 #3
0
import rivercrossingsolver as rcs
from itertools import combinations

game_players = "T1 T2 T3 T1B1 T1B2 T2B1"

no_t1 = []
no_t2 = []
p = game_players.split()
combos = [x for l in range(1, len(game_players)) for x in combinations(p, l)]
for y in combos:
    if "T1" not in y and ("T1B1" in y or "T1B2" in y) and (
        ("T2" in y and "T3" not in y) or ("T3" in y and "T2" not in y)):
        no_t1.append(list(y))
    if "T2" not in y and "T2B1" in y and (("T1" in y and "T3" not in y) or
                                          ("T3" in y and "T1" not in y)):
        no_t2.append(list(y))

t1_rules = " ".join(x for x in [",".join(x) for x in no_t1])
t2_rules = " ".join(x for x in [",".join(x) for x in no_t2])
final_rules = t1_rules + " " + t2_rules

rcs.setPlayers(game_players)
rcs.setdrivers("T1 T2 T3")
rcs.startLeft()
rcs.setgoalStatus("", game_players)
rcs.setinvalidBoat("")
rcs.setinvalidBank(final_rules)
rcs.setboatCapacity(2)

rcs.solve()
コード例 #4
0
import rivercrossingsolver as rcs

# Father    = 90
# Mother    = 80
# Boy       = 60
# Girl      = 40
# Bag       = 20
game_players = "F M B G A"

rcs.setPlayers(game_players)
rcs.setdrivers("F M B G")
rcs.startLeft()
rcs.setgoalStatus("", game_players)
rcs.setinvalidBoat("F,M F,B F,G F,A M,B M,G")
rcs.setinvalidBank("")
rcs.setboatCapacity(2)

rcs.solve()