class GameTest(unittest.TestCase): def setUp(self): self.board = Board() self.player = Player("X", self.board, "Sys") self.computer = ComputerPlayer("O",self.board) def test_one_game(self): sys_moves = [] print "Testing Player First" while self.board.winner == None: choice_made = False while not choice_made: choice = random.randrange(0, 9, 1) if choice not in sys_moves and self.board.get_cell(choice) == None: sys_moves.append(choice) choice_made = True self.player.place_marker(choice) if self.board.winner == None: self.computer.place_marker() print "\n{0} is the winner with moves of {1} on board {2}\n".format(self.board.winner, sys_moves, self.board.grid ) def test_one_game_computer_first(self): sys_moves = [] print "Testing computer First" while self.board.winner == None: choice_made = False self.computer.place_marker() while not choice_made: choice = random.randrange(0, 9, 1) if choice not in sys_moves and self.board.get_cell(choice) == None: sys_moves.append(choice) choice_made = True self.player.place_marker(choice) #if self.board.winner == None: print "\n{0} is the winner with moves of {1} on board {2}\n".format(self.board.winner, sys_moves, self.board.grid )
class ComputerPlayerTest(unittest.TestCase): def setUp(self): self.board = Board() self.player = Player("X", self.board, "Allan") self.computer = ComputerPlayer("O",self.board ) def test_place_marker(self): self.player.place_marker(4) self.computer.place_marker() assert self.board.last_cell != 4
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))
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))
class GameLoadTestComputerFirst(unittest.TestCase): GAME_COUNT = 1000 def setUp(self): self.board = Board() self.player = Player("X", self.board, "Sys") self.computer = ComputerPlayer("O",self.board) self.winners = {} self.moves = {} def play_game(self): sys_moves = [] while self.board.winner == None: self.computer.place_marker() #print "Computer places Marker at {0}".format(self.board.last_cell) choice_made = False while not choice_made: choice = random.randrange(0, 9, 1) if choice not in sys_moves and self.board.get_cell(choice) == None: sys_moves.append(choice) choice_made = True self.player.place_marker(choice) #if self.board.winner == None: if self.board.full: self.board.declare_cat() choice_made = True #print "Player places Marker at {0}".format(self.board.last_cell) winner = self.board.winner if winner in self.winners.keys(): self.winners[winner] = self.winners[winner] + 1 else: self.winners[winner] = 1 if winner == "X": move = sys_moves.__str__() if move in self.moves.keys(): self.moves[move] = self.moves[move] + 1 else: self.moves[move] = 1 def test_game_computer_first(self): print "Computer Will go first" for count in range(self.GAME_COUNT): self.play_game() self.board.clear() print "\n{0}".format(self.winners) print "\n{0}".format(self.moves)
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))
def setUp(self): self.board = Board() self.player = Player("X", self.board, "Sys") self.computer = ComputerPlayer("O",self.board) self.winners = {} self.moves = {}
def setUp(self): self.board = Board() self.player = Player("X", self.board, "Sys") self.computer = ComputerPlayer("O",self.board)
def test_PlayerId(self): computer_player = ComputerPlayer(computer_id="x", human_id="o") self.assertEqual(computer_player.Id(), "x")
def test_NaoDeixaOutroJogadorVencerComOutroTraversal(self): board = Board() player_id = "x" other_player_id = "o" computer_player = ComputerPlayer(computer_id=player_id, human_id=other_player_id)
def test_EscolheParaGanharComLinha(self): board = Board() player_id = "x" computer_player = ComputerPlayer(computer_id=player_id, human_id="o")