Bot1 = {'win':0, 'lose':0, 'tie':0} Bot2 = {'win':0, 'lose':0, 'tie':0} for game_num in range(0,n_games): print("Playing game " + repr(game_num) + "...") playerturn = random.randint(0,1) turn = 0 while not game.won: boardlist = game.boardlist if turn%2 == playerturn: spot = random.randint(0, boardlist_size-1) while not game.addmark(spot): spot = random.randint(0, boardlist_size-1) else: clf = NN(num_nodes, boardlist_size, boardlist_size) boardlist = game.boardlist if turn%2: probs = clf.probs(-1*boardlist) else: probs = clf.probs(boardlist) spot = np.argmax(probs) while not game.addmark(spot): probs[0][spot] = 0
playerturn = 0 while True: print("") print("Starting new game!") turn = 0 game.printboard() while not game.won: if turn%2 == playerturn: print("Player taking turn...") val = int(raw_input("Please select a cell number: ")) while val > boardlist_size-1 or val < 0 or not game.addmark(val): val = int(raw_input("Invalid cell number. Please select a cell number: ")) else: print("AI taking turn...") spot = clf.predict(game, verbose=True) game.addmark(spot) game.printboard() winner = game.winner() if winner == 2: print("It's a tie!") elif winner == 1: