Exemplo n.º 1
0
 def add_ship_position(size: int, ship=Ship) -> None:
     for i in range(size):
         col_letter = lambda x: ivn_col_mapper[np.random.randint(1, 9, x)[0]
                                               ]
         row_num = lambda x: np.random.randint(1, 9, x)[0]
         rand_col = Letter.__dict__['_member_map_'][col_letter(1)]
         rand_row = row_num(1)
         ship.positions.append(Position(rand_col, rand_row))
     return None
Exemplo n.º 2
0
def get_random_position():
    rows = 8
    lines = 8

    letter = Letter(random.randint(1, lines))
    number = random.randint(1, rows)
    position = Position(letter, number)

    return position
Exemplo n.º 3
0
def parse_position(position: str):
    """ Проверяет позицию """
    # TODO: Нельзя стрелять дважды в одну и ту же клетку
    # TODO: Показывать выбранную клетку на карте
    position = GameController.validate_position(position)

    letter = Letter[position.upper()[0]]
    number = int(position[1])
    position = Position(letter, number)

    return position
 def setUp(self):
     self.ships = []
     self.ships.append(
         init_ship(Ship("Test", 2, Color.RED),
                   [Position(Letter.A, 1),
                    Position(Letter.A, 2)]))
 def test_check_is_hit_ship_none(self):
     with self.assertRaises(ValueError):
         self.assertRaises(
             GameController.check_is_hit(None, Position(Letter.A, 1)))
 def test_check_is_hit_false(self):
     self.assertFalse(
         GameController.check_is_hit(self.ships, Position(Letter.B, 1)))
 def test_check_is_hit_true(self):
     self.assertTrue(
         GameController.check_is_hit(self.ships, Position(Letter.A, 1)))
Exemplo n.º 8
0
    def get_random_position(size: int):
        letter = random.choice(list(Letter))
        number = random.randrange(size)
        position = Position(letter, number)

        return position
Exemplo n.º 9
0
def parse_position(input: str):
    letter = Letter[input.upper()[:1]]
    number = int(input[1:])
    position = Position(letter, number)

    return Position(letter, number)
Exemplo n.º 10
0
def initialize_enemyFleet():
    global enemyFleet

    enemyFleet = GameController.initialize_ships()

    enemyFleet[0].positions.append(Position(Letter.B, 4))
    enemyFleet[0].positions.append(Position(Letter.B, 5))
    enemyFleet[0].positions.append(Position(Letter.B, 6))
    enemyFleet[0].positions.append(Position(Letter.B, 7))
    enemyFleet[0].positions.append(Position(Letter.B, 8))

    enemyFleet[1].positions.append(Position(Letter.E, 6))
    enemyFleet[1].positions.append(Position(Letter.E, 7))
    enemyFleet[1].positions.append(Position(Letter.E, 8))
    enemyFleet[1].positions.append(Position(Letter.E, 9))

    enemyFleet[2].positions.append(Position(Letter.A, 3))
    enemyFleet[2].positions.append(Position(Letter.B, 3))
    enemyFleet[2].positions.append(Position(Letter.C, 3))

    enemyFleet[3].positions.append(Position(Letter.F, 8))
    enemyFleet[3].positions.append(Position(Letter.G, 8))
    enemyFleet[3].positions.append(Position(Letter.H, 8))

    enemyFleet[4].positions.append(Position(Letter.C, 5))
    enemyFleet[4].positions.append(Position(Letter.C, 6))