示例#1
0
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 )
示例#2
0
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
示例#3
0
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)