コード例 #1
0
ファイル: game.py プロジェクト: Contrix/pybots-server
    def test_action_simple_movements(self):
        game_map = Map(width=1, height=1)
        fake_map = [
            [BotField(Orientation.EAST), EmptyField()],
            [EmptyField(), EmptyField()],
        ]
        setattr(game_map, '_{}__map'.format(game_map.__class__.__name__), fake_map)
        game = Game(game_map)
        game._empty_bots_positions = game._map.get_field_occurrences(BotField)

        self.assertFalse(game.is_filled, 'Game has free bot field.')

        fake_bot_id = 'fake_bot_id'

        game.action(fake_bot_id, Action.TURN_RIGHT)
        self.assertEqual(
            game._map[game._bots_positions[fake_bot_id]].orientation,
            Orientation.SOUTH
        )

        game.action(fake_bot_id, Action.TURN_LEFT)
        self.assertEqual(
            game.map[game._bots_positions[fake_bot_id]].orientation,
            Orientation.EAST
        )

        game.action(fake_bot_id, Action.STEP)
        self.assertEqual(
            game._bots_positions[fake_bot_id],
            (1, 0)
        )

        with self.assertRaises(MovementError):
            game.action(fake_bot_id, Action.STEP)
        self.assertEqual(
            game._bots_positions[fake_bot_id],
            (1, 0)
        )

        game.action(fake_bot_id, Action.TURN_RIGHT)

        game.action(fake_bot_id, Action.STEP)
        with self.assertRaises(MovementError):
            game.action(fake_bot_id, Action.STEP)
コード例 #2
0
    def test_action_simple_movements(self):
        game_map = Map(width=1, height=1)
        fake_map = [
            [BotField(Orientation.EAST), EmptyField()],
            [EmptyField(), EmptyField()],
        ]
        setattr(game_map, '_{}__map'.format(game_map.__class__.__name__), fake_map)
        game = Game(game_map)
        game._empty_bots_positions = game._map.get_field_occurrences(BotField)

        self.assertFalse(game.is_filled, 'Game has free bot field.')

        fake_bot_id = 'fake_bot_id'

        game.action(fake_bot_id, Action.TURN_RIGHT)
        self.assertEqual(
            game._map[game._bots_positions[fake_bot_id]].orientation,
            Orientation.SOUTH
        )

        game.action(fake_bot_id, Action.TURN_LEFT)
        self.assertEqual(
            game.map[game._bots_positions[fake_bot_id]].orientation,
            Orientation.EAST
        )

        game.action(fake_bot_id, Action.STEP)
        self.assertEqual(
            game._bots_positions[fake_bot_id],
            (1, 0)
        )

        with self.assertRaises(MovementError):
            game.action(fake_bot_id, Action.STEP)
        self.assertEqual(
            game._bots_positions[fake_bot_id],
            (1, 0)
        )

        game.action(fake_bot_id, Action.TURN_RIGHT)

        game.action(fake_bot_id, Action.STEP)
        with self.assertRaises(MovementError):
            game.action(fake_bot_id, Action.STEP)