import matplotlib.pyplot as plt import numpy as np from utilities.constants import GREEN, WHITE # winners = [] with open("winners-5.txt", "r") as f: winners = f.readlines() winners = [int(x.strip()) for x in winners] # lavg = [] # for i in range(0, len(winners), 25): # lavg.append(winners[i:i+25].count(2) / 25) # # x = np.arange(0, len(lavg)) # y = np.array(lavg) * 100 # # a, b = np.polyfit(x, y, 1) # # fig, ax = plt.subplots(figsize=(10, 5)) # ax.plot(y) # ax.set_xticks(np.arange(0, len(lavg), 2)) # ax.minorticks_on() # ax.plot(x, a*x+b, color='red', linestyle='--', linewidth=2) # ax.set_ylim([0, 100]) # ax.set_title("Winners Average") # ax.grid(which='major', linestyle='-', linewidth='0.5', color='black') # ax.grid(which='minor', linestyle=':', linewidth='0.5') # ax.set_xlabel("Average Set") # ax.set_ylabel("Percentage of Wins") # ax.tick_params(which="minor", bottom=False, left=False) # plt.show() fig, ax = plt.subplots() bar = ax.bar(["Draw", "White", "Green"], [winners.count(0), winners.count(WHITE), winners.count(GREEN)]) ax.set(xlabel='Winner', ylabel='Frequency', ylim=[0, 100]) ax.set_title("Winners at Depth 5") ax.grid(which='major', linestyle='-', linewidth='0.5', color='grey', axis='y') ax.bar_label(bar) plt.show() # with open("trainedRewards.txt", "r") as f: # totalReward = f.readlines() # # totalReward = [float(x.strip()) for x in totalReward] # filteredReward = list(filter(lambda x: x > -1500, totalReward)) # change_in_rewards = [0] # Initialize with 0 for the first episode # for i in range(1, len(totalReward)): # change_in_reward = totalReward[i] - totalReward[i - 1] # change_in_rewards.append(change_in_reward) # # games = list(range(1, len(totalReward) + 1)) # plt.plot(games, change_in_rewards) # plt.xlabel('Training Games') # plt.ylabel('Change in Game Reward') # plt.title('Change in Game Reward vs. Training Games') # plt.grid(True) # plt.show() # major_ticks = np.arange(0, 101, 20) # minor_ticks = np.arange(0, 101, 5) # # plt.plot([i for i in range(len(totalReward))], totalReward) # plt.title("Rewards to Games") # plt.xlabel("Games") # plt.ylabel("Reward") # plt.xticks(major_ticks) # plt.xticks(minor_ticks, minor=True) # plt.yticks(major_ticks) # plt.yticks(minor_ticks, minor=True) # plt.grid(which='both') # plt.show() # # plt.plot([i for i in range(len(filteredReward))], filteredReward) # plt.title("Filtered Rewards to Games") # plt.xlabel("Games") # plt.ylabel("Reward") # plt.grid(which='both') # plt.show()