def test_cell_sum(self): game_board = GameBoard() self.assertFalse(game_board.check_for_win()) game_board.set_cell(3,1) game_board.set_cell(5,1) game_board.set_cell(7,1) self.assertTrue(game_board.check_for_win())
def test_computer_player(self): game_board = GameBoard() computerplayer = ComputerPlayer("Computer",game_board,1) name = computerplayer.name # Test name was set self.assertEqual(name,"Computer") # Test board is instance of GameBoard self.assertIsInstance(computerplayer.game_board,GameBoard) # Test player (id of 1) has marker value of 4 self.assertEquals(computerplayer.marker_value, 4) # Make the first move computerplayer.make_move() self.assertFalse(game_board.is_cell_empty(5)) # Make the another move computerplayer.make_move() self.assertFalse(game_board.is_cell_empty(1)) # Make the third move computerplayer.make_move() self.assertFalse(game_board.is_cell_empty(9)) self.assertTrue(game_board.check_for_win())
moves = 0 current_player_id = 0 active_turn = True while active_turn: moves += 1 # Grab the current player (based on id) player = players[current_player_id] print "%s's turn: Move #%d..." % (player.get_name(), moves) player.make_move() print board if moves > 4 and board.check_for_win(): # If win combo was found, set to winner board.winner = player active_turn = False elif (moves == 9): # If max # of moves, done with game active_turn = False else: # Move to the next player if (current_player_id == 1): current_player_id = 0 else: current_player_id = 1 if (board.winner): print "The WINNER is %s!\n" % board.winner.get_name()