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()
for y in combos: if "D1" in y and "M1" not in y and "F1" not in y: rule_set.append(y) if "D2" in y and "M2" not in y and "F2" not in y: rule_set.append(y) if len(y) == 2: if "D1" in y and "F1" not in y: boat_rule_set.append(y) if "D2" in y and "F2" not in y: boat_rule_set.append(y) rule_set.append(["D1"]) rule_set.append(["D2"]) rules = " ".join(x for x in [",".join(x) for x in rule_set]) boat_rules = " ".join(x for x in [",".join(x) for x in boat_rule_set]) # for r in rule_set: # print r # exit(0) rcs.setPlayers(game_players) rcs.setdrivers("F1 F2") rcs.startLeft() rcs.setgoalStatus("", game_players) rcs.setinvalidBoat(boat_rules) rcs.setinvalidBank(rules) rcs.setboatCapacity(2) rcs.solve()
rule_set.append(y) # No child on raft with other mother, but other child OK brule_set = [ ["M1", "D2"], ["M1", "S2"], ["M2", "S1"], ["M2", "D1"] ] # 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]) brules = " ".join(x for x in [",".join(x) for x in brule_set]) # print rules # exit(0) rcs.setPlayers(game_players) rcs.setdrivers("M1 S1") rcs.startLeft() rcs.setgoalStatus("", game_players) rcs.setinvalidBoat(brules) rcs.setinvalidBank(rules) rcs.setboatCapacity(2) rcs.solve()
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()
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()
import rivercrossingsolver as rcs game_players = "A L B1 B2" rcs.setPlayers(game_players) rcs.setdrivers(game_players) rcs.startLeft() rcs.setgoalStatus("", game_players) rcs.setinvalidBoat("L A,L A,B1 A,B2") rcs.setinvalidBank("L") rcs.setboatCapacity(2) rcs.solve("soldiers")