Ejemplo n.º 1
0
def test_sh_player():

    weights = {
        "unit_weight": 1.242,
        "node_weight": -0.4971,
        "occ_weight": 0,
        "occ_new_weight": 0.05953,
        "n_enemies_weight": 0.2306,
        "enemy_occ_nodes_weight": -1.126,
        "enemy_unit_weight": -0.2431,
        "empty_node_weight": -0.7042,
        "attacker_weight": -0.3131,
        "defender_weight": 0.06549,
        "occ_attacker_weight": -0.2173,
        "occ_defender_weight": 0.4239,
        "enemy_occ_attacker_weight": 0.3953,
        "enemy_occ_defender_weight": -0.02868,
    }

    nodes = [
        GameNode(0, [], [1, 2]),
        GameNode(1, [], [0, 2]),
        GameNode(2, [], [0, 1, 3]),
        GameNode(3, [], [2, 4, 5]),
        GameNode(4, [], [3, 5]),
        GameNode(5, [], [3, 4]),
    ]

    players = [
        ShortHorizonPlayer(0, [Unit(0, nodes[0])], [nodes[0]], nodes[0], **weights),
        ShortHorizonPlayer(1, [Unit(1, nodes[1])], [nodes[1]], nodes[1], **weights),
        ShortHorizonPlayer(2, [Unit(2, nodes[4])], [nodes[4]], nodes[4], **weights),
        ShortHorizonPlayer(3, [Unit(3, nodes[5])], [nodes[5]], nodes[5], **weights),
    ]

    nodes[0].add_unit(players[0].units[0])
    nodes[1].add_unit(players[1].units[0])
    nodes[4].add_unit(players[2].units[0])
    nodes[5].add_unit(players[3].units[0])

    graph = GameGraph(nodes)

    game = Game(players, graph)

    game.update_state([], False)

    def next_round(event):
        win = game.play_round()
        if win is None:
            graphics.draw(f, w, l, game.state)
        else:
            graphics.draw_winner(w, win)

    f, w, l = graphics.setup(game.state, next_round)

    graphics.draw(f, w, l, game.state)
    graphics.show()
Ejemplo n.º 2
0
def test_human_player():

    nodes = [
        GameNode(0, [], [1, 2]),
        GameNode(1, [], [0, 2]),
        GameNode(2, [], [0, 1, 3]),
        GameNode(3, [], [2, 4, 5]),
        GameNode(4, [], [3, 5]),
        GameNode(5, [], [3, 4])
    ]

    players = [
        HumanPlayer(0, [HumanInteractionUnit(0, nodes[0])], [nodes[0]],
                    nodes[0]),
        HumanPlayer(1, [HumanInteractionUnit(1, nodes[1])], [nodes[1]],
                    nodes[1]),
        HumanPlayer(2, [HumanInteractionUnit(2, nodes[4])], [nodes[4]],
                    nodes[4]),
        HumanPlayer(3, [HumanInteractionUnit(3, nodes[5])], [nodes[5]],
                    nodes[5])
    ]

    nodes[0].add_unit(players[0].units[0])
    nodes[1].add_unit(players[1].units[0])
    nodes[4].add_unit(players[2].units[0])
    nodes[5].add_unit(players[3].units[0])

    graph = GameGraph(nodes)

    game = Game(players, graph)

    game.update_state([], False)

    def next_round(event):
        win = game.play_round()
        if win is None:
            graphics.draw(f, w, l, game.state)
        else:
            graphics.draw_winner(w, win)

    f, w, l = graphics.setup(game.state, next_round)

    for p in players:
        p.canvas = w

    graphics.draw(f, w, l, game.state)
    graphics.show()
Ejemplo n.º 3
0
def test_human_player():

    nodes = [
        GameNode(0, [], [1, 2]),
        GameNode(1, [], [0, 2]),
        GameNode(2, [], [0, 1, 3]),
        GameNode(3, [], [2, 4, 5]),
        GameNode(4, [], [3, 5]),
        GameNode(5, [], [3, 4]),
    ]

    players = [
        HumanPlayer(0, [HumanInteractionUnit(0, nodes[0])], [nodes[0]], nodes[0]),
        HumanPlayer(1, [HumanInteractionUnit(1, nodes[1])], [nodes[1]], nodes[1]),
        HumanPlayer(2, [HumanInteractionUnit(2, nodes[4])], [nodes[4]], nodes[4]),
        HumanPlayer(3, [HumanInteractionUnit(3, nodes[5])], [nodes[5]], nodes[5]),
    ]

    nodes[0].add_unit(players[0].units[0])
    nodes[1].add_unit(players[1].units[0])
    nodes[4].add_unit(players[2].units[0])
    nodes[5].add_unit(players[3].units[0])

    graph = GameGraph(nodes)

    game = Game(players, graph)

    game.update_state([], False)

    def next_round(event):
        win = game.play_round()
        if win is None:
            graphics.draw(f, w, l, game.state)
        else:
            graphics.draw_winner(w, win)

    f, w, l = graphics.setup(game.state, next_round)

    for p in players:
        p.canvas = w

    graphics.draw(f, w, l, game.state)
    graphics.show()
Ejemplo n.º 4
0
def update():
    s = len(v.gui_displayed)
    r = []
    for i in range(s):
        for ii in range(s):
            r.append(
                Rectangle(
                    Point(50 + ((400 / s) * ii), 50 + ((400 / s) * i)),
                    Point(50 + ((400 / s) * (ii + 1)),
                          50 + ((400 / s) * (i + 1)))))
    index = 0
    for i in r:
        i.setOutline("black")
        i.setWidth(2)
        if v.gui_displayed[index] is 0:
            i.setFill("white")
        if v.gui_displayed[index] is 1:
            i.setFill("red")
        i.draw(win)
    g.show()

    return
Ejemplo n.º 5
0
        graphics.draw_ellipse(
            graphics.Point(10 * self.x, 10 * self.y),
            graphics.Point(10 * self.x + 10, 10 * self.y + 10),
            color
        )

    def update(self) -> None:
        self.age += 1

        neighbours = self.field.get_neighbours(self)
        alive = 0
        for neighbour in neighbours:
            if neighbour.alive:
                alive += 1

        if alive < 2 or alive > 3:
            self.kill()


field = Field(40, 30)

graphics.configure('Game of Life', 400, 300)
while True:
    graphics.clear()  # clear screen
    field.draw()
    graphics.show()  # update screen

    field.update()
    sleep(0.100)
Ejemplo n.º 6
0
def test_sh_player():

    weights = {
        "unit_weight": 1.242,
        "node_weight": -0.4971,
        "occ_weight": 0,
        "occ_new_weight": 0.05953,
        "n_enemies_weight": 0.2306,
        "enemy_occ_nodes_weight": -1.126,
        "enemy_unit_weight": -0.2431,
        "empty_node_weight": -0.7042,
        "attacker_weight": -0.3131,
        "defender_weight": 0.06549,
        "occ_attacker_weight": -0.2173,
        "occ_defender_weight": 0.4239,
        "enemy_occ_attacker_weight": 0.3953,
        "enemy_occ_defender_weight": -0.02868
    }

    nodes = [
        GameNode(0, [], [1, 2]),
        GameNode(1, [], [0, 2]),
        GameNode(2, [], [0, 1, 3]),
        GameNode(3, [], [2, 4, 5]),
        GameNode(4, [], [3, 5]),
        GameNode(5, [], [3, 4])
    ]

    players = [
        ShortHorizonPlayer(0, [Unit(0, nodes[0])], [nodes[0]], nodes[0],
                           **weights),
        ShortHorizonPlayer(1, [Unit(1, nodes[1])], [nodes[1]], nodes[1],
                           **weights),
        ShortHorizonPlayer(2, [Unit(2, nodes[4])], [nodes[4]], nodes[4],
                           **weights),
        ShortHorizonPlayer(3, [Unit(3, nodes[5])], [nodes[5]], nodes[5],
                           **weights)
    ]

    nodes[0].add_unit(players[0].units[0])
    nodes[1].add_unit(players[1].units[0])
    nodes[4].add_unit(players[2].units[0])
    nodes[5].add_unit(players[3].units[0])

    graph = GameGraph(nodes)

    game = Game(players, graph)

    game.update_state([], False)

    def next_round(event):
        win = game.play_round()
        if win is None:
            graphics.draw(f, w, l, game.state)
        else:
            graphics.draw_winner(w, win)

    f, w, l = graphics.setup(game.state, next_round)

    graphics.draw(f, w, l, game.state)
    graphics.show()
Ejemplo n.º 7
0
plt.rcParams['figure.figsize'] = (15, 5)  # Розмір картинок

def read_file(file):
    df = pd.read_csv(file, sep=';', encoding='utf8', decimal=',')
    return df

def parse_df(dataframe):
    df['day/month'] = pd.to_datetime(df['day/month'], format='%d.%b').dt.strftime('%d.%m.2019')
    df['Time'] = pd.to_datetime(df['Time']).dt.strftime(r'%H:%M')
    df['Humidity'] = df['Humidity'].str.rstrip('%').astype(float) / 100.0
    df["Wind Speed"] = df["Wind Speed"].str.extract('(\d+)', expand=False).astype(int)
    df["Wind Gust"] = df["Wind Gust"].str.extract('(\d+)', expand=False).astype(int)
    return dataframe

file = "DATABASE.csv"
df = read_file(file)
parse_df(df)
df.set_index('day/month', inplace=True)
print(df)
print(df.dtypes)


k = int(input('How many graphics?\n'))
print('\nWhich column?') 
columns=[]
for j in range(k):
    column=input() 
    columns.append(column)
    
graphics.show(df, columns)
Ejemplo n.º 8
0
        frame = fill(frame, Maybes)

    else:
        print("Change made")

    print("Prev frame")
    for i in range(9):
        print(frame_prev[i])

    print("Pass", q)
    for i in range(9):
        print(frame[i])

    if q > 81 or not change(frame, frame_prev):
        print("Code ran for too long or no changes where made.")
        for i in range(len(Maybes)):
            print(Maybes[i])

        break

if not check(frame):
    print("Final frame")

    for i in range(9):
        print(frame[i])

    print("Finished")

show(frame)