Exemple #1
0
 def setUp(self):
     self.game = GameBattleship()
     input_user = [
         '1, 1, 1, vertical',
         '1, 2, 2, vertical',
         '1, 3, 3, vertical',
         '1, 4, 3, vertical',
         '1, 5, 4, vertical',
         '1, 6, 5, vertical',
     ]
     board = Board()
     board_table = [
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 1, 2, 31, 32, 4, 5, 0, 0, 0],
         [0, 0, 2, 31, 32, 4, 5, 0, 0, 0],
         [0, 0, 0, 31, 32, 4, 5, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 4, 5, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 5, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     ]
     board.board = board_table
     for single_input in input_user:
         self.game.play(single_input)
     self.game.player_cpu.board_own = board
Exemple #2
0
 def test_doblehit(self):
     board_cpu = Board()
     board = [
         [31, 9, 31, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     ]
     board_cpu.board = board
     result = board_cpu.shoot(0, 1)
     self.assertEqual(result, 'already shoot')
Exemple #3
0
 def test_game_dont_change_state(self):
     board_cpu = Board()
     board = [
         [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     ]
     board_cpu.board = board
     self.game.player_cpu.board_own = board_cpu
     expected = self.game.state
     self.game.play('1, 2')
     self.assertEqual(expected, self.game.state)
Exemple #4
0
 def test_game_war_player_can_hit_boat_player_cpu(self):
     board_cpu = Board()
     board = [
         [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 2, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 2, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     ]
     board_cpu.board = board
     self.game.player_cpu.board_own = board_cpu
     expected = ['You hit a boat']
     self.game.state = game_states[1]
     result = self.game.play('2, 2')
     self.assertEqual(expected, result)
Exemple #5
0
 def test_game_war_player_can_sunk_boat_player_cpu(self):
     board_cpu = Board()
     board = [
         [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 2, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 2, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     ]
     board_cpu.board = board
     self.game.state = game_states[1]
     self.game.player_cpu.board_own = board_cpu
     expected = ['Congratulations! You sunk a boat.']
     result = self.game.play('0, 0')
     self.assertEqual(expected, result)
Exemple #6
0
 def test_game_check_cpu_wins(self, mock_pick_coordenate):
     board_human = Board()
     board_table = [
         [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     ]
     board_human.board = board_table
     self.game.player_human.board_own = board_human
     self.game_states = game_states[1]
     self.game.turn = 'cpu'
     mock_pick_coordenate.return_value = [0, 0]
     result = self.game.war_cpu()
     self.assertEqual(['Your boat was sunk.', 'You lose.'], result)
Exemple #7
0
 def test_game_war_player_can_water_boat_player_cpu(self, mock_pick_coordenate):
     board_cpu = Board()
     board = [
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     ]
     board_cpu.board = board
     self.game.player_cpu.board_own = board_cpu
     self.game.turn = possible_turn[0]
     self.game.state = game_states[1]
     expected = ['You only hit water! CPU turn', 'Water! Now is your turn.']
     mock_pick_coordenate.return_value = [0, 0]
     result = self.game.play('0, 0')
     self.assertEqual(expected, result)