Ejemplo n.º 1
0
    def test_PlayerWinsWithOtherDiagonal(self):
        # Um jogador vai jogar 3 posicoes na transversal. Teste que assim vai
        # vencer com diagonal, e nao com linha ou coluna.
        board = Board()
        player_id = "x"
        board.PlayPosition(2, 0, player_id)
        board.PlayPosition(1, 1, player_id)
        board.PlayPosition(0, 2, player_id)

        self.assertTrue(board.WonWithTransversal(player_id))
        self.assertFalse(board.WonWithRow(player_id))
        self.assertFalse(board.WonWithCol(player_id))
Ejemplo n.º 2
0
 def test_VaiJogarParaVencerEmVezDeBloquar(self):
     board = Board()
     player_id = "x"
     other_player_id = "o"
     computer_player = ComputerPlayer(computer_id=player_id,
                                      human_id=other_player_id)
     # Set pattern:
     #    | o | o       Expect (2, 2) to be "x"
     # ---+---+---
     #    |   |
     # ---+---+---
     #  x | x | *
     board.PlayPosition(0, 1, other_player_id)
     board.PlayPosition(0, 2, other_player_id)
     board.PlayPosition(2, 0, player_id)
     board.PlayPosition(2, 1, player_id)
     computer_player.Play(board)
     self.assertTrue(board.HasPosition(2, 2, player_id))
     self.assertTrue(board.PlayerWon(player_id))
Ejemplo n.º 3
0
 def test_PlayedPosition(self):
     # Um jogador vai jogar uma posicao... Teste se a mudansa foi feita no
     # tabuleiro. Repare que a valor do "player_id" nao importa.
     board = Board()
     player_id = "x"
     row = 2
     col = 1
     board.PlayPosition(row, col, player_id)
     self.assertTrue(board.HasPosition(row, col, player_id))
     self.assertFalse(board.IsFree(row, col))
Ejemplo n.º 4
0
 def test_EscolheParaGanharComLinha(self):
     board = Board()
     player_id = "x"
     computer_player = ComputerPlayer(computer_id=player_id, human_id="o")
     # Set pattern:
     #  * | x | x       Expect (0, 0)
     # ---+---+---
     #    |   |
     # ---+---+---
     #    |   |
     board.PlayPosition(0, 1, player_id)
     board.PlayPosition(0, 2, player_id)
     computer_player.Play(board)
     self.assertTrue(board.HasPosition(0, 0, player_id))
     self.assertTrue(board.PlayerWon(player_id))
Ejemplo n.º 5
0
 def test_NaoDeixaOutroJogadorVencerComLinha(self):
     board = Board()
     player_id = "x"
     other_player_id = "o"
     computer_player = ComputerPlayer(computer_id=player_id,
                                      human_id=other_player_id)
     # Set pattern:
     #  * | o | o       Expect (0, 0) to be "x"
     # ---+---+---
     #    |   |
     # ---+---+---
     #    |   |
     board.PlayPosition(0, 1, other_player_id)
     board.PlayPosition(0, 2, other_player_id)
     computer_player.Play(board)
     self.assertTrue(board.HasPosition(0, 0, player_id))