forked from sparshag21/game-QLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initializers.py
49 lines (35 loc) · 907 Bytes
/
initializers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import numpy as np
import pygame
import random
#initializing parameters
WIDTH = 800
HEIGHT = 600
RED = (255,0,0)
BLUE = (0,0,255)
YELLOW = (255,255,0)
BACKGROUND_COLOR = (0,0,0)
player_size = 50
player_pos = [WIDTH/2, HEIGHT-player_size]
playerstep = 20
player = pygame.Rect(player_pos[0], player_pos[1], player_size, player_size)
enemy_size = 50
enemy_pos = [random.randint(0,WIDTH-enemy_size), 0]
enemy = pygame.Rect(enemy_pos[0], enemy_pos[1], enemy_size, enemy_size)
enemy_list = [enemy]
SPEED = 20
#Initializing Q-values and setting number of states and actions
QIDic = {}
states = int(WIDTH/player_size*(WIDTH-enemy_size)/enemy_size*HEIGHT/SPEED)
action_number = 3
Q = np.zeros(
[states, action_number])
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
#Initializing score and reward
game_over = False
reward = 0
score = 0
deaths = 0
# set learning rate
lr = .85
y = .99