def test_computer_make_random_move(self):
     victoria = single_player.player.Player(10, 2)
     victoria.put_ship(3, [0, 0], 0)
     grid1 = [[0 for i in range(10)] for i in range(10)]
     grid2 = [[0 for i in range(10)] for i in range(10)]
     computer_make_move(victoria, victoria.sea, grid1, grid2)
     sum_grid = sum([sum(row) for row in grid1])
     self.assertEqual(sum_grid, 4)
 def test_computer_make_move(self):
     player1 = single_player.player.Player(10, 2)
     sea1 = player1.sea
     grid1 = [[0 for i in range(10)] for i in range(10)]
     grid2 = [[0 for i in range(10)] for i in range(10)]
     put_one_ship(player1, [8, 8], 3, 0, grid1)
     single_player.computer_open_cell([0, 0], grid1, sea1, grid2)
     self.assertTrue(computer_make_move(player1, sea1, grid1, grid2))
     self.assertTrue(grid1[0][1] == 3 or grid1[1][0] == 4)
     computer_make_move(player1, sea1, grid1, grid2)
     self.assertTrue(grid1[0][1] == 3)
     computer_make_move(player1, sea1, grid1, grid2)
     self.assertTrue(grid1[0][2] == 3)
Exemple #3
0
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()

    while turn:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                turn = single_player.player_make_move(pos, sea2, grid2, grid1)
                draw_board()
                if computer.check_ships():
                    win_window(player1)

    while not turn:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            turn = single_player.computer_make_move(player1, sea1, grid1, grid2)
            draw_board()
            if player1.check_ships():
                win_window(computer)

    # clock.tick(20)

pygame.quit()