-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateDataSet.py
42 lines (39 loc) · 1.27 KB
/
generateDataSet.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
GAME_SIZE = 4
SCORE_TO_WIN = 2048
from game2048.game import Game
from game2048.agents import ExpectiMaxAgent
# save the dataset
f_256 = open("dataset_256.txt", "w")
f_512 = open("dataset_512.txt", "w")
f_1024 = open("dataset_1024.txt", "w")
for i in range(30000):
print("i = ", i)
game = Game(size=GAME_SIZE)
agent = ExpectiMaxAgent(game=game)
while True:
direction = agent.step()
if (game.end == True):
break
maxNum = 0
for i in range(4):
for j in range(4):
if game.board[i, j] > maxNum:
maxNum = game.board[i, j]
if maxNum == 2048: # start the next turn
break
if maxNum <= 256:
for i in range(4):
for j in range(4):
print(game.board[i, j], file = f_256)
print(direction, file = f_256)
elif maxNum == 512:
for i in range(4):
for j in range(4):
print(game.board[i, j], file = f_512)
print(direction, file = f_512)
if maxNum == 1024:
for i in range(4):
for j in range(4):
print(game.board[i, j], file = f_1024)
print(direction, file = f_1024)
game.move(direction)