2wenty1ne 2025-12-01 18:20:05 +01:00
parent 93076e2426
commit 6f84ec02ba
3 changed files with 44 additions and 8 deletions

16
data.txt 100644
View File

@ -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%

View File

@ -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()

30
main.py
View File

@ -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()