-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataGatheringPlayer.py
49 lines (34 loc) · 1.38 KB
/
DataGatheringPlayer.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
import time
import sys
import pyglet
import math
import random
from game_globals import *
import Action
from Player import Player
import h5py
class DataGatheringPlayer(Player):
def __init__(self, dataset_filepath=""):
Player.__init__(self)
self.dataset_filepath = dataset_filepath
self.h5 = h5py.File(dataset_filepath, 'w')
self.dataset = self.h5.create_dataset("data", (16, WINDOW_SIZE, WINDOW_SIZE), maxshape=(None, WINDOW_SIZE, WINDOW_SIZE))
self.dataset_index = 0
def saveDataset(self):
print("Saving dataset to ", self.dataset_filepath)
self.dataset.resize((self.dataset_index, WINDOW_SIZE, WINDOW_SIZE))
self.h5.close()
def getDecision(self, current_frame):
if self.game.world_counter % 100 == 0:
print "*" * 40, self.game.world_counter, "%" * 40
curr_action = Action.getRandomAction()
# Actually perform the action in the game
self.performAction(curr_action)
data = current_frame.toCNNInput()
#data = data.reshape((84,84))
data *= 1/255.
self.dataset[self.dataset_index] = data
self.dataset_index += 1
if self.dataset_index == len(self.dataset):
print("RESIZING TO ", len(self.dataset)*2)
self.dataset.resize((len(self.dataset)*2, WINDOW_SIZE, WINDOW_SIZE))