Exemplo n.º 1
0
def test_ship_collision4():

    game = Game(wait_agent, wait_agent)
    s1 = Ship(10, 11, game.players[0])
    s1.halite = 10
    s2 = Ship(10, 11, game.players[1])
    s2.halite = 10
    game.players[0].add_ship(s1)
    game.players[1].add_ship(s2)

    assert len(game.players[0].ships) == 2
    assert len(game.players[0].ship_array[11][10]) == 1

    assert len(game.players[1].ships) == 2
    assert len(game.players[1].ship_array[11][10]) == 1

    assert game.get_halite(s1.x, s1.y) == 0

    game.ship_collisions()

    assert len(game.players[0].ships) == 1
    assert len(game.players[0].ship_array[11][10]) == 0

    assert len(game.players[1].ships) == 1
    assert len(game.players[1].ship_array[11][10]) == 0

    assert game.get_halite(s1.x, s1.y) == 20
Exemplo n.º 2
0
def test_halite_regeneration():
    game = Game(wait_agent, wait_agent)

    game.set_halite(0, 0, 100)
    assert game.get_halite(0, 0) == 100

    game.halite_regeneration()

    assert game.get_halite(0, 0) == 102
    assert game.get_halite(0, 1) == 0
Exemplo n.º 3
0
def test_collect():
    game = Game(wait_agent, wait_agent)

    s = game.players[0].ships[0]

    game.halite[10, 5] = 40

    assert game.players[0].halite == 5000

    s.collect()

    assert game.get_halite(5, 10) == 30
    assert s.halite == 10
    assert game.players[0].halite == 5000
Exemplo n.º 4
0
def test__step():
    game = Game(wait_agent, wait_agent)

    p0 = game.players[0]
    p1 = game.players[1]

    s1 = Ship(15, 15, p0)  #collect
    game.set_halite(15, 15, 1)
    s1.halite = 10
    p0.add_ship(s1)
    s2 = Ship(16, 15, p1)  #move left
    s2.halite = 10
    p1.add_ship(s2)

    s3 = Ship(9, 7, p0)  #move up
    p0.add_ship(s3)

    s4 = Ship(10, 11, p1)  #collect
    game.set_halite(10, 11, 100)
    p1.add_ship(s4)

    s5 = Ship(16, 9, p0)  #move right and deposit
    s5.halite = 20
    p0.add_ship(s5)

    s6 = Ship(7, 7, p1)  #convert
    game.set_halite(7, 7, 20)
    s6.halite = 700
    p1.add_ship(s6)

    s7 = Ship(7, 8, p0)  #Move up
    p0.add_ship(s7)

    sy1 = Shipyard(17, 9, p0)
    p0.add_shipyard(sy1)

    sy2 = Shipyard(4, 5, p1)  #spawn
    p1.add_shipyard(sy2)

    actions0 = actions_dict()
    actions0[ShipMove.UP] = [s3, s7]
    actions0[ShipMove.RIGHT] = [s5]
    actions0[ShipMove.COLLECT] = [s1]

    actions1 = actions_dict()
    actions1[ShipyardMove.SPAWN] = [sy2]
    actions1[ShipMove.CONVERT] = [s6]
    actions1[ShipMove.LEFT] = [s2]
    actions1[ShipMove.COLLECT] = [s4]

    game._step(actions0, actions1)

    assert p0.ship_array[15][15] == []
    assert p1.ship_array[15][15] == []
    assert game.get_halite(15, 15) == 21 * 1.02

    assert p0.ship_array[7][9] == []
    assert p0.ship_array[6][9] == [s3]

    assert s4.halite == 25
    assert game.get_halite(10, 11) == 75 * 1.02

    assert s5.halite == 0
    assert p0.halite == 5020

    assert p1.halite == 5000 - 500 + 200
    assert p1.shipyard_array[7][7] == 0
    assert p0.ship_array[7][7] == [s7]
    assert game.get_halite(7, 7) == 0

    assert p1.ship_array[5][4] != []