示例#1
0
 def test_spawn_is_static(self):
     decorated_map = WorldMapStaticSpawnDecorator(WorldMap({}, {}), Location(3, 7))
     for _ in range(5):
         self.assertEqual(decorated_map.get_random_spawn_location(), Location(3, 7))
示例#2
0
    def test_avatars_cannot_go_into_each_other(self):
        """
        Two avatars moving in the same direction towards each other.
        """
        # Even number of cells between two avatars.
        self.set_up_environment([MoveEastDummy, MoveWestDummy])
        self.game.game_state.add_avatar(2, Location(3, 0))
        avatar_two = self.game.avatar_manager.get_avatar(2)

        self.assertEqual(self.avatar.location, Location(0, 0))
        self.assertEqual(avatar_two.location, Location(3, 0))
        loop = asyncio.get_event_loop()
        for i in range(2):
            loop.run_until_complete(
                self.game.simulation_runner.run_single_turn(
                    self.game.avatar_manager.
                    get_player_id_to_serialised_action()))

        # Avatar 1 & Avatar 2 only managed to move once.
        self.assertEqual(self.avatar.location, Location(1, 0))
        self.assertEqual(avatar_two.location, Location(2, 0))

        # Odd number of cells between two avatars.
        self.set_up_environment([MoveEastDummy, MoveWestDummy])
        self.game.game_state.add_avatar(2, Location(4, 0))
        avatar_two = self.game.avatar_manager.get_avatar(2)

        self.assertEqual(self.avatar.location, Location(0, 0))
        self.assertEqual(avatar_two.location, Location(4, 0))

        for i in range(2):
            loop.run_until_complete(
                self.game.simulation_runner.run_single_turn(
                    self.game.avatar_manager.
                    get_player_id_to_serialised_action()))

        # Avatar 1 & Avatar 2 managed to only move only once.
        self.assertEqual(self.avatar.location, Location(1, 0))
        self.assertEqual(avatar_two.location, Location(3, 0))

        # Live avatar can't move into a square occupied by a 'dead' (no worker) avatar
        self.set_up_environment([DeadDummy, MoveWestDummy])
        self.game.game_state.add_avatar(2, Location(1, 0))
        avatar_two = self.game.avatar_manager.get_avatar(2)

        self.assertEqual(self.avatar.location, Location(0, 0))
        self.assertEqual(avatar_two.location, Location(1, 0))
        loop.run_until_complete(
            self.game.simulation_runner.run_single_turn(
                self.game.avatar_manager.get_player_id_to_serialised_action()))

        self.assertEqual(self.avatar.location, Location(0, 0))
        self.assertEqual(avatar_two.location, Location(1, 0))
示例#3
0
 def test_empty_grid(self):
     world_map = WorldMap({}, self.settings)
     self.assertFalse(world_map.is_on_map(Location(0, 0)))
示例#4
0
    def test_attackable_avatar_returns_avatar(self):
        avatar = DummyAvatar()
        world_map = AvatarMap(avatar)

        self.assertEqual(world_map.attackable_avatar(Location(0, 0)), avatar)
示例#5
0
 def test_can_move_to(self):
     world_map = WorldMap(generate_grid(), self.settings)
     target = Location(1, 1)
     self.assertTrue(world_map.can_move_to(target))
示例#6
0
 def test_cannot_move_to_uninhabitable_cell(self):
     target = Location(0, 0)
     cell = MockCell(target, habitable=False)
     world_map = WorldMap({target: cell}, self.settings)
     self.assertFalse(world_map.can_move_to(target))
示例#7
0
 def test_x_off_map(self):
     map = WorldMap(self._generate_grid())
     for y in (0, 1):
         self.assertFalse(map.is_on_map(Location(-1, y)))
         self.assertFalse(map.is_on_map(Location(2, y)))
示例#8
0
 def test_random_spawn_location_successful(self):
     cell = MockCell()
     world_map = WorldMap({Location(0, 0): cell}, self.settings)
     self.assertEqual(world_map.get_random_spawn_location(), cell.location)
示例#9
0
    def test_move_towards_map_boundaries(self):
        """
        Tests game behaviour when the avatar tries to move towards one of the four of the
        maps boundaries.
        """

        # North boundary.
        self.set_up_and_make_movements_in_a_single_direction([MoveNorthDummy],
                                                             2,
                                                             Location(0, 25))

        self.assertFalse(
            self.game.game_state.world_map.is_on_map(Location(0, 26)))
        self.assertEqual(self.avatar.location, Location(0, 25))

        # South boundary.
        self.set_up_and_make_movements_in_a_single_direction([MoveSouthDummy],
                                                             2,
                                                             Location(0, -24))

        self.assertFalse(
            self.game.game_state.world_map.is_on_map(Location(0, -25)))
        self.assertEqual(self.avatar.location, Location(0, -24))

        # East boundary.
        self.set_up_and_make_movements_in_a_single_direction([MoveEastDummy],
                                                             2,
                                                             Location(25, 0))

        self.assertFalse(
            self.game.game_state.world_map.is_on_map(Location(26, 0)))
        self.assertEqual(self.avatar.location, Location(25, 0))

        # West boundary.
        self.set_up_and_make_movements_in_a_single_direction([MoveWestDummy],
                                                             2,
                                                             Location(-24, 0))

        self.assertFalse(
            self.game.game_state.world_map.is_on_map(Location(-25, 0)))
        self.assertEqual(self.avatar.location, Location(-24, 0))
示例#10
0
 def test_location_on_map(self):
     map = WorldMap(self._generate_grid())
     for x in (0, 1):
         for y in (0, 1):
             self.assertTrue(map.is_on_map(Location(x, y)))
示例#11
0
from __future__ import absolute_import
import unittest

from simulation import event
from simulation import action
from simulation.location import Location
from simulation.direction import EAST
from simulation.game_state import GameState
from simulation.avatar.avatar_manager import AvatarManager

from .dummy_avatar import MoveDummy
from .maps import InfiniteMap, EmptyMap, ScoreOnOddColumnsMap, AvatarMap, MockPickup, PickupMap

ORIGIN = Location(x=0, y=0)
EAST_OF_ORIGIN = Location(x=1, y=0)
NORTH_OF_ORIGIN = Location(x=0, y=1)


class TestAction(unittest.TestCase):
    def setUp(self):
        self.avatar = MoveDummy(1, ORIGIN, EAST)
        self.other_avatar = MoveDummy(2, EAST_OF_ORIGIN, EAST)
        self.avatar_manager = AvatarManager()

    def test_successful_move_north_action(self):
        game_state = GameState(InfiniteMap(), self.avatar_manager)
        action.MoveAction(self.avatar, {
            'x': 0,
            'y': 1
        }).process(game_state.world_map)
示例#12
0
from .dummy_avatar import (
    DeadDummy,
    DummyAvatar,
    DummyAvatarManager,
    MoveEastDummy,
    MoveNorthDummy,
    MoveSouthDummy,
    MoveWestDummy,
    WaitDummy,
)
from .maps import InfiniteMap, MockCell, MockPickup
from .mock_communicator import MockCommunicator
from .mock_game_state import MockGameState

ORIGIN = Location(0, 0)

RIGHT_OF_ORIGIN = Location(1, 0)
FIVE_RIGHT_OF_ORIGIN = Location(5, 0)

ABOVE_ORIGIN = Location(0, 1)
FIVE_RIGHT_OF_ORIGIN_AND_ONE_ABOVE = Location(5, 1)

SETTINGS = {
    "TARGET_NUM_CELLS_PER_AVATAR": 0,
    "TARGET_NUM_PICKUPS_PER_AVATAR": 0,
    "TARGET_NUM_SCORE_LOCATIONS_PER_AVATAR": 0,
    "SCORE_DESPAWN_CHANCE": 0,
    "PICKUP_SPAWN_CHANCE": 0,
}
示例#13
0
文件: maps.py 项目: iberischris/aimmo
 def get_random_spawn_location(self):
     return Location(10, 10)
示例#14
0
文件: maps.py 项目: iberischris/aimmo
 def __init__(self):
     self._cell_cache = {}
     [self.get_cell(Location(x, y)) for x in range(5) for y in range(5)]
     self.updates = 0
     self.num_avatars = None
示例#15
0
 def test_y_off_map(self):
     map = WorldMap(self._generate_grid())
     for x in (0, 1):
         self.assertFalse(map.is_on_map(Location(x, -1)))
         self.assertFalse(map.is_on_map(Location(x, 2)))
示例#16
0
 def test_get_valid_cell(self):
     world_map = WorldMap(generate_grid(), self.settings)
     for x in (0, 1):
         for y in (0, 1):
             location = Location(x, y)
             self.assertEqual(world_map.get_cell(location).location, location)
示例#17
0
 def test_get_valid_cell(self):
     map = WorldMap(self._generate_grid())
     for x in (0, 1):
         for y in (0, 1):
             location = Location(x, y)
             self.assertEqual(map.get_cell(location).location, location)
示例#18
0
 def test_random_spawn_location_with_no_candidates(self):
     grid = generate_grid(1, 1)
     world_map = WorldMap(grid, self.settings)
     grid[Location(0, 0)].avatar = True
     with self.assertRaises(IndexError):
         world_map.get_random_spawn_location()
示例#19
0
 def test_can_move_to(self):
     map = WorldMap(self._generate_grid())
     target = Location(1, 1)
     self.assertTrue(map.can_move_to(target))
示例#20
0
 def test_cannot_move_to_cell_off_grid(self):
     world_map = WorldMap(generate_grid(), self.settings)
     target = Location(4, 1)
     self.assertFalse(world_map.can_move_to(target))
示例#21
0
 def test_cannot_move_to_cell_off_grid(self):
     map = WorldMap(self._generate_grid())
     target = Location(4, 1)
     self.assertFalse(map.can_move_to(target))
示例#22
0
 def test_cannot_move_to_inhabited_cell(self):
     target = Location(0, 0)
     cell = MockCell(target, avatar=DummyAvatar(target, 0))
     world_map = WorldMap({target: cell}, self.settings)
     target = Location(0, 0)
     self.assertFalse(world_map.can_move_to(target))
示例#23
0
 def test_cannot_move_to_uninhabitable_cell(self):
     target = Location(0, 0)
     cell = MockCell(target, habitable=False)
     map = WorldMap([[cell]])
     self.assertFalse(map.can_move_to(target))
示例#24
0
 def test_attackable_avatar_returns_none(self):
     world_map = WorldMap(generate_grid(), self.settings)
     for x in (0, 1):
         for y in (0, 1):
             self.assertIsNone(world_map.attackable_avatar(Location(x, y)))
示例#25
0
 def test_cannot_move_to_habited_cell(self):
     target = Location(0, 0)
     cell = MockCell(target, avatar=DummyAvatar(target, 0))
     map = WorldMap([[cell]])
     target = Location(0, 0)
     self.assertFalse(map.can_move_to(target))
示例#26
0
 def test_retrieve_negative(self):
     world_map = WorldMap(generate_grid(3, 3), self.settings)
     self.assertTrue(world_map.is_on_map(Location(-1, -1)))
示例#27
0
 def test_x_off_map(self):
     world_map = WorldMap(generate_grid(), self.settings)
     for y in (0, 1):
         self.assertFalse(world_map.is_on_map(Location(-1, y)))
         self.assertFalse(world_map.is_on_map(Location(2, y)))
示例#28
0
 def _grid_from_list(self, in_list):
     out = {}
     for x, column in enumerate(in_list):
         for y, cell in enumerate(column):
             out[Location(x, y)] = cell
     return out
示例#29
0
 def test_y_off_map(self):
     world_map = WorldMap(generate_grid(), self.settings)
     for x in (0, 1):
         self.assertFalse(world_map.is_on_map(Location(x, -1)))
         self.assertFalse(world_map.is_on_map(Location(x, 2)))
示例#30
0
 def test_serialise(self):
     loc = Location(3, 9)
     expected = {'x': 3, 'y': 9}
     self.assertEqual(loc.serialise(), expected)
示例#31
0
 def __init__(self, location, health, score, events):
     self.location = Location(**location)
     self.health = health
     self.score = score
     self.events = events