Example #1
0
def test_sinked():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    cords = (2, 6)
    fleet = sinked(fleet, cords)
    assert not fleet.get_ship(cords)
Example #2
0
def test_fleet_fleet_is_not():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    fleet.remove_ship_from_fleet(ship1)
    fleet.remove_ship_from_fleet(ship2)
    assert not fleet.if_fleet_is()
Example #3
0
def test_fleet_setter():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    ship3 = Ship(3, [(5, 2), (5, 3), (5, 4)], 'poziom')
    ship4 = Ship(2, [(2, 6), (2, 7)], 'poziom')
    fleet.set_ships_list([ship3, ship4])
    assert fleet.get_ships_list() == [ship3, ship4]
Example #4
0
def test_fleet_get_list_of_cords():
    ship1 = Ship(
        4,
        [(3, 2), (3, 3), (3, 4), (3, 5)],
        'poziom',
    )
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    assert fleet.get_list_of_cords() == [[(3, 2), (3, 3), (3, 4), (3, 5)],
                                         [(2, 6), (3, 6)]]
def generate_computer_matrix(list_of_sizes, dim):
    '''
    Creates matrix and fleet for bot.
    '''
    matrix = generate_empty_matrix(dim)
    list_of_infos = []
    for size in list_of_sizes:
        list_of_cords = []
        check = False
        while not check:
            cords = create_random_cords(dim)
            direction = choose_direction()
            check = check_if_making_is_possible(size, cords,
                                                matrix, dim,
                                                direction)
            if check:
                first, second = cords[0], cords[1]
                if direction == 'poziom':
                    for number in range(size):
                        matrix[first, second + number] = 1
                        list_of_cords.append((first, second+number))
                if direction == 'pion':
                    for number in range(size):
                        matrix[first + number, second] = 1
                        list_of_cords.append((first + number, second))
                list_of_infos.append((size, list_of_cords, direction))
    Bot_Matrix = Matrix(matrix)
    Bot_Fleet = Fleet(make_list_of_ships(list_of_infos))
    return Bot_Matrix, Bot_Fleet
Example #6
0
def test_f_continue():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(1, [(2, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    cords = (2, 6)
    shot_list = [(2, 2)]
    shot_list, fleet_object = f_continue(fleet, cords, shot_list)
    assert shot_list[1] == cords
Example #7
0
def test_hit():
    dim = 8
    matrix = np.zeros((dim, dim), dtype=int)
    m_obj = Matrix(matrix)
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    size = ship1.get_size()
    ship2 = Ship(3, [(2, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    cords = (3, 2)
    lifes, m_obj, fleet = hit(m_obj, cords, fleet, dim)
    assert lifes < size
def make_player_matrix(list_of_sizes, dim):
    '''
    Conducts creating player's matrix and fleet
    '''
    list_of_infos = []
    matrix = np.zeros((dim, dim), dtype=int)
    print(make_empty_board(dim))
    while list_of_sizes:
        size = list_of_sizes[0]
        direction, location = get_info_about_ship(size, matrix, dim)
        for cord in location:
            first, second = cord
            matrix[first, second] = 1
        list_of_infos.append((size, location, direction))
        list_of_sizes.pop(0)
        print(show_actual_board(matrix, dim))
    Player_Matrix = Matrix(matrix)
    Player_Fleet = Fleet(make_list_of_ships(list_of_infos))
    print('Twoja finalna tablica')
    return Player_Matrix, Player_Fleet
Example #9
0
    dino1.type = 'stegosaurus'
    dino2.type = 't-rex'
    dino3.type = 'pterodactyl'

    robot1.name = 'ryan'
    robot2.name = 'ryan 2.0'
    robot3.name = 'slasher mk II'

    robot1.Weapon.assign_weapon()
    robot2.Weapon.assign_weapon()
    robot3.Weapon.assign_weapon()
    robot1.assign_attack_power()
    robot2.assign_attack_power()
    robot3.assign_attack_power()

    robo_list = Fleet()
    dino_list = Herd()
    robo_list.join_fleet(robot1)
    robo_list.join_fleet(robot2)
    robo_list.join_fleet(robot3)
    dino_list.join_herd(dino1)
    dino_list.join_herd(dino2)
    dino_list.join_herd(dino3)

    battle = Battlefield()
    while True:
        battle.enter_battlefield(robo_list.robots[0], dino_list.dinosaurs[0])
        battle.dino_combatant.get_hit(battle.robot_combatant.attack())
        battle.robot_combatant.get_hit(battle.dino_combatant.attack())
        robo_list.robots[0] = battle.robot_combatant
        dino_list.dinosaurs[0] = battle.dino_combatant
Example #10
0
def test_fleet_fleet_is():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    assert fleet.if_fleet_is()
Example #11
0
def test_fleet_remove_ship_from_fleet():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    fleet.remove_ship_from_fleet(ship2)
    assert fleet.get_ships_list() == [ship1]
Example #12
0
def test_fleet_getter():
    ship1 = Ship(4, [(3, 2), (3, 3), (3, 4), (3, 5)], 'poziom')
    ship2 = Ship(3, [(2, 6), (3, 6)], 'pion')
    fleet = Fleet([ship1, ship2])
    assert fleet.get_ships_list() == [ship1, ship2]