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()
import rivercrossingsolver as rcs from itertools import combinations game_players = "P F M D S" rcs.setPlayers(game_players) rcs.setdrivers(game_players) rcs.startLeft() rcs.setgoalStatus("", game_players) rcs.settimeLimit(30) rcs.settimeValues("P:1 F:3 M:6 D:8 S:12") rcs.setduplicateNode(True) rcs.solve("train")
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")