-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_data.py
executable file
·63 lines (52 loc) · 1.61 KB
/
create_data.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
from game import MinesGame
import numpy as np
from copy import deepcopy
from statistics import mean, median
from bot import Bot
INITIAL_GAMES = 700
SCORE_REQUIREMENTS = 35
HEIGHT = 8
WIDTH = 8
GOAL_STEPS = 500
accepted_scores = []
def initial_population():
# training_data = []
X = []
Y = []
scores = []
data_count = 0
while data_count != INITIAL_GAMES:
if data_count % 1000 == 0:
print(f"{data_count + 1} / {INITIAL_GAMES}")
game = MinesGame(WIDTH, HEIGHT)
bot = Bot(game)
score = 0
game_memory = []
prev_observation = deepcopy(game.game_board)
for _ in range(GOAL_STEPS):
action = bot.look_for_empty()
observation, done, reward, won = game.enter_input(action, True)
if done and not won:
break
data = [prev_observation, action]
game_memory.append(data)
prev_observation = deepcopy(observation)
score += reward
if done:
break
if won:
accepted_scores.append(score)
data_count += 1
for data in game_memory:
# training_data.append(data)
X.append(data[0])
Y.append(data[1])
scores.append(score)
# training_data_save = np.array(training_data)
print("Average accepted score: ", mean(accepted_scores))
print("Accepted scores: ", len(accepted_scores))
return X, Y
if __name__ == "__main__":
X, Y = initial_population()
np.savez(f"training_data/data.npz", X, Y, allow_pickle=True)