예제 #1
0
def run2(options):

    rows = options.size
    columns = options.size

    enviroments = [CellularAutomata(rows, columns) for i in range(5)]

    for i in enviroments: i.drawCycle(options.radius, options.X_center, options.Y_center)

    enviroments[1].applyNoiseBoundary()
    enviroments[2].applyNoiseBoundary(noiseLevel = options.noise_level)
    enviroments[3].applyNoiseRandom()
    enviroments[4].applyNoiseRandom(noiseLevel = options.noise_level)

    for i in range(options.time_steps):
        print("Time Step: ",i)
        # env.printCA()
        for env in enviroments: env.step(timeStep=i)

    data = [env.getData() for env in enviroments]
    titles = [env.getTitle() for env in enviroments]

    for index, d in enumerate(data):
        plt.plot(d, label=titles[index])
    plt.legend()
    plt.xlabel('Time Step')
    plt.ylabel('Non Zero Elements [Activated Cells]')
    plt.show()
예제 #2
0
def start_match(name_game, n_players, raw_mode):
    #PARAMETRI
    flags = "W1B"
    list_mode = ["007", "kamikaze"]

    players_mode = []
    if raw_mode == "R":
        players_mode = [
            list_mode[random.randint(0, 1)] for elem in range(n_players)
        ]
    else:
        players_mode = (["007"] * raw_mode[0]) + (["kamikaze"] * raw_mode[1])

    #INIZIALIZZAZIONE THREAD COMMUNICATION
    manager = multiprocessing.Manager()

    #OTHER_PLAYER_GAME_INTERFACE___________________________________________________________________
    threads = []
    for i in range(n_players):
        pl = GameInterface(name_game,
                           name_game,
                           "Garada" + str(i + 1),
                           player_descr="AI9-v1.1",
                           flags=flags)

        print(pl.interact("join"))
        pl.command_chat("name")
        pl.command_chat("join")

        manager_dict = manager.dict()

        ca = CellularAutomata(pl,
                              manager_dict,
                              debug=False,
                              mode=players_mode[i])  # to Debug

        ca_chat = CellularAutomata_chat(pl, manager_dict, debug=False)

        t = multiprocessing.Process(target=start_game, args=(ca, ))
        c = multiprocessing.Process(target=start_chat, args=(ca_chat, ))

        threads.append(c)
        threads.append(t)
    #_______________________________________________________________________________

    for n in range(0, len(threads)):
        threads[n].start()

    for n in range(len(threads)):
        threads[n].join()
예제 #3
0
def run(options):

    rows = options.size
    columns = options.size

    env =  CellularAutomata(rows, columns)

    currentV, currentT = getCurrentW2E(options.size, 35, 7)
    # currentV, currentT = getCurrentVοrtice(options.size)

    env.addIsland(options.R_island, options.X_island, options.Y_island)
    env.addSource(options.X_oil, options.Y_oil)
    env.addCurrent(currentV, currentT)

    for i in range(options.time_steps):
        if (i%15==0):
            # env.printCA(step = i)
            print("-- Time Step: ",i)
        env.step(step = i )
예제 #4
0
def run(options):

    #initiate enviroment
    atari = gym.make('BankHeist-v0')

    observation = atari.reset()

    # initiate class
    envCA = CellularAutomata(observation)

    for i in range(options.time_steps):
        atari.render()

        action = envCA.step(observation)

        observation, reward, done, info = atari.step(
            action)  # take a random action
        time.sleep(0.1)
        # pdb.set_trace()

        # envCA.print()

    atari.close()
예제 #5
0
        #Creazione Gioco
        if (i == 0):
            pl.manage_game("new")

        print(pl.interact("join"))
        pl.command_chat("name")
        pl.command_chat("join")

        # Aggiunta log
        if (i == 0 and "l" in flags):
            pl.command_chat("join_log")

        manager_dict = manager.dict()

        if (i == 0):
            ca = CellularAutomata(pl, manager_dict, debug=False,
                                  mode="007")  # to Debug
        else:
            if (i % 2 == 1):
                ca = CellularAutomata(pl,
                                      manager_dict,
                                      debug=False,
                                      mode="007")  # to Debug
            else:
                ca = CellularAutomata(pl,
                                      manager_dict,
                                      debug=False,
                                      mode="007")  # to Debug

        ca_chat = CellularAutomata_chat(pl, manager_dict, debug=False)

        if (i == 0):
예제 #6
0
def single_match():

    #PARAMETRI
    NAME_GAME = "ai9_" + datetime.datetime.now().strftime(
        "%Y%m%d_%H%M%S")  #"Species"
    n_players = randint(4, 8)
    flags = "T"

    if (randint(0, 1) == 1):
        flags += "Q"
    else:
        flags += "W"
    flags += str(randint(1, 3))

    if (randint(0, 1) == 1):
        flags += "B"

    print(NAME_GAME)
    print(flags)
    print(n_players)

    #INIZIALIZZAZIONE THREAD COMMUNICATION
    manager = multiprocessing.Manager()

    #OTHER_PLAYER_GAME_INTERFACE___________________________________________________________________
    threads = []
    for i in range(n_players):

        #Game Interface
        pl = GameInterface(NAME_GAME,
                           NAME_GAME,
                           "Garada" + str(i + 1),
                           player_descr="AI9-v1.1",
                           flags=flags)
        if (i == 0):
            pl.manage_game("new")

        #Join game and chat
        print(pl.interact("join"))
        pl.command_chat("name")
        pl.command_chat("join")

        manager_dict = manager.dict()

        #Cellular automata
        if (i == 0):
            ca = CellularAutomata(pl,
                                  manager_dict,
                                  debug=False,
                                  mode="007",
                                  save_maps=True)  # to Debug
        else:
            if (i % 2 == 1):
                ca = CellularAutomata(pl,
                                      manager_dict,
                                      debug=False,
                                      mode="007",
                                      save_maps=True)  # to Debug
            else:
                ca = CellularAutomata(pl,
                                      manager_dict,
                                      debug=False,
                                      mode="007",
                                      save_maps=True)  # to Debug

        # Cellula automata chat
        if (i == 0):
            ca_chat = CellularAutomata_chat(pl, manager_dict, debug=False)
        else:
            ca_chat = CellularAutomata_chat(pl, manager_dict, debug=False)

        # Multiprocessing
        if (i == 0):
            t = multiprocessing.Process(target=start_game, args=(ca, True))
        else:
            t = multiprocessing.Process(target=start_game, args=(ca, ))

        c = multiprocessing.Process(target=start_chat, args=(ca_chat, ))

        threads.append(c)
        threads.append(t)
    #_______________________________________________________________________________

    for n in range(0, len(threads)):
        threads[n].start()

    for n in range(len(threads)):
        threads[n].join()
예제 #7
0
        value = tournament + "-" + str(i) + "-1"
        print("Start game on: " + value)
        input('wait')
        SAME_NAME = value
        NAME_GAME = SAME_NAME  #+datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
        NAME_CHAT = SAME_NAME
        debug = False
        debug_chat = False

        pl1 = GameInterface(game_name=NAME_GAME,
                            chat_name=NAME_CHAT,
                            player_name="ai9_pl1",
                            player_descr="ai9_1.0")
        print(pl1.interact("join"))
        ai_dict = manager.dict()
        ca = CellularAutomata(pl1, ai_dict, debug=debug, mode='007')
        ca_chat = CellularAutomata_chat(pl1, ai_dict, debug=debug_chat)
        pl1.command_chat("join")
        t_pl1 = multiprocessing.Process(target=start_game, args=(ca, ))
        c_pl1 = multiprocessing.Process(target=start_chat, args=(ca_chat, ))

        pl2 = GameInterface(game_name=NAME_GAME,
                            chat_name=NAME_CHAT,
                            player_name="ai9_pl2",
                            player_descr="ai9_1.0")
        print(pl2.interact("join"))
        ai_dict = manager.dict()
        ca2 = CellularAutomata(pl2, ai_dict, debug=debug, mode='kamikaze')
        ca2_chat = CellularAutomata_chat(pl2, ai_dict, debug=debug_chat)
        t_pl2 = multiprocessing.Process(target=start_game, args=(ca2, ))
        c_pl2 = multiprocessing.Process(target=start_chat, args=(ca2_chat, ))
예제 #8
0
                    result = temp.manage_game("new").lower()
                    print(result)
                    if (result.find("error") != -1):
                        print("ERRORE CREAZIONE")
                        exit()
                    else:
                        creation_game = False
                        created = True
                        manager_game = temp
                print(temp.interact("join"))
                temp.command_chat("name")
                temp.command_chat("join")

                manager_dict = manager.dict()
                ca = CellularAutomata(temp,
                                      manager_dict,
                                      debug=debug,
                                      mode=mode)  # to Debug
                if (i == 0):
                    ca_chat = CellularAutomata_chat(temp,
                                                    manager_dict,
                                                    debug=True)
                else:
                    ca_chat = CellularAutomata_chat(temp,
                                                    manager_dict,
                                                    debug=False)
                t_player = multiprocessing.Process(target=start_game,
                                                   args=(ca, ))
                chat_player = multiprocessing.Process(target=start_chat,
                                                      args=(ca_chat, ))
                threads_player.append(t_player)
                threads_chat.append(chat_player)