def _popAction(game, action): if DarkLogic.hasAlreadyPlayed(): DarkLogic.unapply() print("Current theorem is") DarkLogic.printTheorem() return True else: print("Cannot pop action") return False
def humanIdentity(): DarkLogic.init(0) print("Identity Demonstration") DarkLogic.makeTheorem("identity", "a<=>a") DarkLogic.printTheorem() print("__________________________________________________") apply("arr,[0]") apply("arr,[0]") apply("arr,[1]") apply("arr_True,[]") assert DarkLogic.isDemonstrated(), "identity theorem was not demonstrated"
def humanDoubleNot(): DarkLogic.init(0) print("DoubleNot Demonstration") DarkLogic.makeTheorem("doubleNot", "a<=>!!a") DarkLogic.printTheorem() print("__________________________________________________") apply("FE,[1]") apply("arr,[0]") apply("arr,[0]") apply("arr_True") assert DarkLogic.isDemonstrated(), "DoubleNot theorem was not demonstrated"
def demonstration(self, name, content, nbThreads): print("Test AI on " + name + " theorem with " + str(nbThreads) + " cores") DarkLogic.init(nbThreads) ai = AI(nbThreads, 60) assert DarkLogic.makeTheorem( name, content), "cannot make " + name + " theorem" DarkLogic.printTheorem() start = time.perf_counter() while not DarkLogic.isOver(): action = ai.play() DarkLogic.getActions() print(ai.name() + " plays action with id " + str(action.id())) DarkLogic.apply(action.id()) DarkLogic.printTheorem() print( "____________________________________________________________________________" ) end = time.perf_counter() if DarkLogic.hasAlreadyPlayed(): if DarkLogic.isDemonstrated(): print(ai.name() + " won! " + ai.name() + " finished the demonstration!") elif DarkLogic.isAlreadyPlayed(): print(ai.name() + " lost! Repetition of theorem!") elif DarkLogic.isEvaluated(): print( ai.name() + " lost! Cannot (\"back-\")demonstrate that a theorem is false with implications" ) elif not DarkLogic.canBeDemonstrated(): print( ai.name() + " lost! This theorem cannot be demonstrated! " + "It can be true or false according to the values of its variables" ) else: if DarkLogic.isDemonstrated(): print("Game Over! the demonstration is already finished!") self._elapsed_seconds = end - start elif not DarkLogic.canBeDemonstrated(): print( "Game Over! This theorem cannot be demonstrated! " + "It can be true or false according to the values of its variables" ) self.pushEvent(Event.EventEnum.STOP)
def humanExcludedMiddle(): DarkLogic.init(0) print("ExcludedMiddle Demonstration") DarkLogic.makeTheorem("ExcludedMiddle", "p||!p") DarkLogic.printTheorem() print("__________________________________________________") apply("arr") apply("FI!") apply("||Ig_Annexe_0") apply("FE") apply("FI!_Annexe_7") apply("||Ig") apply("ax_Annexe_1") assert DarkLogic.isDemonstrated( ), "ExcludedMiddle theorem was not demonstrated"
def _pushActionStr(self, action): id = int(action) actions = DarkLogic.getHumanActions() foundAction = False ruleName = "" for action in actions: if id == action.id(): foundAction = True ruleName = action.ruleName() break if foundAction: DarkLogic.apply(id) print(self._player.name() + " uses " + ruleName) print("Current theorem is") DarkLogic.printTheorem() else: print(action + " is not a valid action") return foundAction
def _pushAction(self, action): DarkLogic.getActions() print(self._player.name() + " played action with id " + str(action.id())) DarkLogic.apply(action.id()) DarkLogic.printTheorem()
def apply(actionStr): print("Apply {" + actionStr + "}") assert DarkLogic.applyStr(actionStr), "cannot apply {" + actionStr + "}" DarkLogic.printTheorem() print("__________________________________________________")