From 6f84ec02ba2fb2f69e64e64303682388ec01d286 Mon Sep 17 00:00:00 2001 From: 2wenty1ne Date: Mon, 1 Dec 2025 18:20:05 +0100 Subject: [PATCH] dt --- data.txt | 16 ++++++++++++++++ game.py | 6 +++--- main.py | 30 +++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 data.txt diff --git a/data.txt b/data.txt new file mode 100644 index 0000000..0116767 --- /dev/null +++ b/data.txt @@ -0,0 +1,16 @@ +E: 0,1; A: 0.1; G: 0.9; 200/5000 +E: 0,1; A: 0.1; G: 0.9; 150/5000 + +E: 0,5; A: 0.1; G: 0.9; 0.0034% +E: 0,5; A: 0.1; G: 0.9; 0.002% + +E: 0,5; A: 0.5; G: 0.5; 0.0012% +E: 0,5; A: 0.5; G: 0.5; 0.0002% +E: 0,5; A: 0.5; G: 0.5; 0.001% + +E: 0,5; A: 0.3; G: 0.5; 0.0018% +E: 0,5; A: 0.3; G: 0.5; 0.0022% +E: 0,5; A: 0.3; G: 0.5; 0.0014% +E: 0,5; A: 0.3; G: 0.5; 0.0016% +E: 0,5; A: 0.3; G: 0.5; 0.0022% + diff --git a/game.py b/game.py index 5f18516..ada0948 100644 --- a/game.py +++ b/game.py @@ -168,7 +168,7 @@ def run_game(q_values, EPSILON, ALPHA, GAMMA): # Check for collisions (game over if ghost catches pacman) if pacman.x == ghost.x and pacman.y == ghost.y: - print("Game Over! The ghost caught Pacman.") + # print("Game Over! The ghost caught Pacman.") running = False reward = -10 @@ -178,7 +178,7 @@ def run_game(q_values, EPSILON, ALPHA, GAMMA): # Check if all cookies are eaten (game over) if all("." not in row for row in labyrinth): - print("You Win! Pacman ate all the cookies.") + # print("You Win! Pacman ate all the cookies.") reward = 10 running = False @@ -214,7 +214,7 @@ def run_game(q_values, EPSILON, ALPHA, GAMMA): # pygame.display.flip() # Cap the frame rate - clock.tick(10000) + clock.tick(1000000) pygame.quit() diff --git a/main.py b/main.py index 0187b46..182dd0d 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,14 @@ import matplotlib.pyplot as plt +import pandas as pd from game import run_game from util import initial_q_fill AMOUNT_RUNS = 5000 -EPSILON = 0.1 -ALPHA = 0.1 -GAMMA = 0.9 +EPSILON = 0.5 +ALPHA = 0.3 +GAMMA = 0.5 """ @@ -23,8 +24,27 @@ cookies_per_run = [] for x in range(AMOUNT_RUNS): amount_cookies_ate = run_game(q_values, EPSILON, ALPHA, GAMMA) cookies_per_run.append(amount_cookies_ate) - print(f"Run {x}: {amount_cookies_ate} cookies ate\n") + # print(f"Run {x}: {amount_cookies_ate} cookies ate\n") + +wins = 0 +for element in cookies_per_run: + if element == 20: + wins += 1 + +print(f"Win percentage: {wins/AMOUNT_RUNS}%") -plt.plot(cookies_per_run) +window_size = 100 # Adjust based on your needs +rolling_avg = pd.Series(cookies_per_run).rolling(window=window_size, center=True).mean() + +plt.figure(figsize=(12, 6)) +plt.plot(cookies_per_run, alpha=0.2, label='Raw Data', linewidth=0.5, color='gray') +plt.plot(rolling_avg, label=f'{window_size}-point Moving Average', + linewidth=2, color='blue') +plt.title("Data with Rolling Average") +plt.xlabel("Index") +plt.ylabel("Value") +plt.legend() +plt.grid(True, alpha=0.3) plt.show() +