Exemplo n.º 1
0
 def _createEvalAI(self):
     from AI.evalai import EvalAI
     print("Eval AI Mode")
     self._mode = Mode.EvalAI
     nbInstances = multiprocessing.cpu_count()
     # nbInstances = 1
     DarkLogic.init(nbInstances)
     self._player = EvalAI(nbInstances, LogicGame._AI_TIMEOUT)
Exemplo n.º 2
0
 def _createNeuralAI(self):
     from AI.neuralai import NeuralAI
     print("Neural AI Mode")
     self._mode = Mode.NeuralAI
     # nbInstances = multiprocessing.cpu_count()
     nbInstances = 1
     DarkLogic.init(nbInstances)
     self._player = NeuralAI(nbInstances, LogicGame._AI_TIMEOUT)
Exemplo n.º 3
0
 def _createBasicAI(self):
     from AI.ai import AI
     print("Basic AI Mode")
     self._mode = Mode.BasicAI
     nbInstances = multiprocessing.cpu_count()
     # nbInstances = 1
     DarkLogic.init(nbInstances)
     self._player = AI(nbInstances, LogicGame._AI_TIMEOUT)
Exemplo n.º 4
0
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"
Exemplo n.º 5
0
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"
Exemplo n.º 6
0
def parser():
    DarkLogic.init(0)
    db = Database("Test/dbtest.csv")
    dbStates = db.getDatas()
    print("Total number of theorems in database: " + str(len(dbStates)))
    for dbState in dbStates.values():
        thCreated = DarkLogic.makeTheorem(dbState.theoremName(),
                                          dbState.theoremContent())
        assert thCreated, "Theorem name: " + dbState.theoremName() + ", " \
                             "content: " + dbState.theoremContent() + " has not been created"
        dlContent = DarkLogic.toStrTheorem()
        assert dlContent == dbState.theoremContent(), "Bad parsing! content in darklogic is '"\
            + dlContent + "', but original was " + dbState.theoremContent()
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
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"
Exemplo n.º 9
0
 def _createHuman(self):
     from Human.human import Human
     print("Human Mode")
     self._mode = Mode.Human
     DarkLogic.init(0)
     self._player = Human()