-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjogar.py
138 lines (125 loc) · 3.75 KB
/
jogar.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import numpy as np
from time import sleep
from BO import BO
import os
class Game():
def __init__(self, tmn,RN):
self.tmn = tmn
self.CriarTabuleiro()
self.RN = RN
def CriarTabuleiro(self):
self.tabuleiro = np.zeros((self.tmn,self.tmn))
self.pontos = 0
self.rodadas = 0
self.Colocar_Aleatrio()
def Colocar_Aleatrio(self):
while True:
i = np.random.randint(0,self.tmn)
j = np.random.randint(0,self.tmn)
if self.tabuleiro[i][j] == 0:
self.tabuleiro[i][j] = 1
break
def Pontos(self):
self.pontos = (np.sum(self.tabuleiro)+ np.max(self.tabuleiro)*4)
def Print(self):
print(self.tabuleiro)
def Teclado(self):
aux=self.RN.predict(self.tabuleiro)
if aux == 0 :
return 'c'
elif aux == 1:
return 'b'
elif aux == 2:
return 'e'
else :
return 'd'
def esqdit(self,tabu):
novo_tabuleiro = []
for linha in tabu:
l = []
mem = []
zeros = []
for item in linha:
if not item == 0:
mem.append(item)
else:
zeros.append(0)
aux = 0
aux2 = []
for item in mem:
if aux == 0:
aux = item
else:
if aux == item:
zeros.append(0)
aux += 1
else:
aux2.append(aux)
aux = item
if not aux == 0:
aux2.append(aux)
l = zeros + aux2
novo_tabuleiro.append(l)
self.tabuleiro = np.array(novo_tabuleiro)
def diresq(self,tabu):
novo_tabuleiro = []
for linha in tabu:
l = []
mem = []
zeros = []
for item in reversed(linha):
if not item == 0:
mem.insert(0,item)
else:
zeros.append(0)
aux = 0
aux2 = []
for item in reversed(mem):
if aux == 0:
aux = item
else:
if aux == item:
zeros.insert(0,0)
aux += 1
else:
aux2.insert(0,aux)
aux = item
if not aux == 0:
aux2.insert(0,aux)
l = aux2 +zeros
novo_tabuleiro.append(l)
self.tabuleiro = np.array(novo_tabuleiro)
def cimabaixo(self, tabu):
self.esqdit(tabu.transpose())
self.tabuleiro = self.tabuleiro.transpose()
def baixocima(self, tabu):
self.diresq(tabu.transpose())
self.tabuleiro = self.tabuleiro.transpose()
def Calcular_novo_tabuleiro(self,tecla):
if (tecla == 'c'):
self.baixocima(self.tabuleiro)
elif (tecla == 'b'):
self.cimabaixo(self.tabuleiro)
elif (tecla == 'e'):
self.diresq(self.tabuleiro)
else:
self.esqdit(self.tabuleiro)
def LoopGame(self,i):
while True:
os.system('clear')
if not 0 in self.tabuleiro or 11 in self.tabuleiro:
break
self.Colocar_Aleatrio()
self.Print()
tecla = self.Teclado()
print(tecla)
self.Calcular_novo_tabuleiro(tecla)
self.rodadas += 1
self.Print()
input()
sleep(i)
self.Pontos()
bo = BO()
nn=bo.load("Elite-epoca-23")
game = Game(4,nn)
game.LoopGame(0)