Пример #1
0
    def __init__(self,
                 field_params: field.FieldParams,
                 white_player: player.Player,
                 black_player: player.Player,
                 main_player: str,
                 is_ai_mode=False,
                 connect_service: ConnectionService = None):

        self._white_pl = white_player
        self._back_pl = black_player
        self._field = field.GameField(field_params)
        self._players = cycle([white_player, black_player])
        self._game_is_on = True
        self._is_ai_mode = False
        self.is_online_mode = bool(connect_service)
        self._current_player = next(self._players)
        self._is_pass = False
        self._connect_service = connect_service
        self._log_manager = LogBoardManager()

        if is_ai_mode:
            if main_player == 'white':
                enemy = black_player
            else:
                enemy = white_player

            self._init_ai(enemy)

            if self.current_player == enemy:
                self.make_ai_move()
Пример #2
0
    def test_ko(self):
        field = fld.GameField(fld.FieldParams(3))
        black_master = player.Player(stones.BlackStone)
        white_master = player.Player(stones.WhiteStone)

        stone = field.set_stone_on_position(black_master, 1, 0)

        stone.die(field)

        self.assertRaises(sp_exc.KOException, field.set_stone_on_position,
                          black_master, 1, 0)
Пример #3
0
    def test_suicide_move(self):
        field = fld.GameField(fld.FieldParams(3))
        master = player.Player(stones.BlackStone)
        enemy_master = player.Player(stones.WhiteStone)

        field.set_stone_on_position(master, 1, 0)
        field.set_stone_on_position(master, 1, 1)
        field.set_stone_on_position(master, 0, 2)

        field.set_stone_on_position(enemy_master, 0, 0)

        self.assertRaises(sp_exc.SuicideMove, field.set_stone_on_position,
                          enemy_master, 0, 1)
Пример #4
0
    def test_close_group_breath(self):
        field = fld.GameField(fld.FieldParams(3))
        master = player.Player(stones.BlackStone)
        enemy_master = player.Player(stones.WhiteStone)

        first_stone = field.set_stone_on_position(master, 0, 1)
        second_stone = field.set_stone_on_position(master, 0, 2)
        third_stone = field.set_stone_on_position(master, 0, 0)
        fourth_stone = field.set_stone_on_position(master, 1, 1)

        enemy_stone = field.set_stone_on_position(enemy_master, 1, 0)
        self.assertTrue(first_stone.breaths == second_stone.breaths ==
                        third_stone.breaths == fourth_stone.breaths == 3)

        self.assertEqual(enemy_stone.breaths, 1)
Пример #5
0
    def test_stone_death(self):
        field = fld.GameField(fld.FieldParams(3))
        black_master = player.Player(stones.BlackStone)
        white_master = player.Player(stones.WhiteStone)

        field.set_stone_on_position(black_master, 0, 0)
        white_stone_1 = field.set_stone_on_position(white_master, 0, 1)
        white_stone_2 = field.set_stone_on_position(white_master, 1, 1)
        white_stone_3 = field.set_stone_on_position(white_master, 1, 0)

        self.assertEqual(field.get_obj_on_position(0, 0), None)
        self.assertEqual(white_stone_1.breaths, 6)
        self.assertEqual(white_stone_2.breaths, 6)
        self.assertEqual(white_stone_3.breaths, 6)

        self.assertEqual(white_master._hostages_count, 1)
Пример #6
0
    def test_field_str(self):
        field = fld.GameField(fld.FieldParams(6))

        self.assertEqual(str(field),
                         ('.-.-.-.-.-.\n' + '| | | | | |\n' + '.-.-.-.-.-.\n' +
                          '| | | | | |\n' + '.-.-.-.-.-.\n' + '| | | | | |\n' +
                          '.-.-.-.-.-.\n' + '| | | | | |\n' + '.-.-.-.-.-.\n' +
                          '| | | | | |\n' + '.-.-.-.-.-.\n'))

        field.set_stone_on_position(player.Player(stones.BlackStone), 3, 3)

        self.assertEqual(str(field),
                         ('.-.-.-.-.-.\n' + '| | | | | |\n' + '.-.-.-.-.-.\n' +
                          '| | | | | |\n' + '.-.-.-.-.-.\n' + '| | | | | |\n' +
                          '.-.-.-o-.-.\n' + '| | | | | |\n' + '.-.-.-.-.-.\n' +
                          '| | | | | |\n' + '.-.-.-.-.-.\n'))
Пример #7
0
    def test_move_with_stone(self):
        field = fld.GameField(fld.FieldParams(3))
        master = player.Player(stones.BlackStone)
        # тест на позиционирование
        stone = field.set_stone_on_position(master, 0, 0)
        self.assertEqual(
            field._field,
            [[stone, None, None], [None, None, None], [None, None, None]])

        # тест на невозможность повтороного позиционирования
        self.assertRaises(sp_exc.BusyPoint, field.set_stone_on_position,
                          stones.BlackStone, 0, 0)

        # тест на обращение
        self.assertEqual(field.get_obj_on_position(0, 0), stone)
        self.assertTrue(
            isinstance(field.get_obj_on_position(5, 5), fld.OutsideStone))
Пример #8
0
    def test_stone_group(self):
        field = fld.GameField(fld.FieldParams(3))
        master = player.Player(stones.BlackStone)
        first_stone = field.set_stone_on_position(master, 0, 1)

        second_stone = field.set_stone_on_position(master, 0, 2)

        self.assertTrue(first_stone.breaths == second_stone.breaths == 3)

        third_stone = field.set_stone_on_position(master, 0, 0)

        self.assertTrue(first_stone.breaths == second_stone.breaths ==
                        third_stone.breaths == 3)

        fourth_stone = field.set_stone_on_position(master, 1, 1)

        self.assertTrue(first_stone.breaths == second_stone.breaths ==
                        third_stone.breaths == fourth_stone.breaths == 5)