-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoisson_terminal.py
151 lines (123 loc) · 4.27 KB
/
Poisson_terminal.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
139
140
141
142
143
144
145
146
147
148
149
150
151
import random
from resize import console_resize # Fonction pour redimentionner le terminal
from time import sleep
from tabulate import tabulate # Affichage du tableau
# **** VARIABLES ****
global nombre, nombreMorts
NombreListe = [i for i in range(2, 102)]
ListePoisson = []
rep = 0
# **** CLASSES ****
class Poisson:
def __init__(self, x, y, nombre):
self.x = x
self.y = y
self.nombre = nombre
def __lt__(self, other):
return self.nombre < other.nombre
def __gt__(self, other):
return self.nombre > other.nombre
class Cellule:
def __init__(self, x, y):
self.x = x
self.y = y
self.poissons = []
def recupPoisson(self):
for i in ListePoisson:
if i.x == self.x and i.y == self.y:
self.poissons.append(i)
def nbspoisson(self):
print("Je suis pelle")
class Monde:
def __init__(self, taille, n):
self.taille = taille
self.nbPoissons = n
self.nombreMorts = 0
self.mortsTotaux = []
global grille
grille = []
for i in range(self.taille):
colonne = []
for j in range(self.taille):
colonne.append(Cellule(i, j))
grille.append(colonne)
# Creation des poissons
for a in range(self.taille):
for b in range(self.taille):
nombre = random.choice(NombreListe)
ListePoisson.append(Poisson(a, b, nombre))
NombreListe.remove(nombre)
def deplacer(self):
for i in ListePoisson:
# print('1 : ', i.x, i.y)
i.x = (random.randint(-1, 1) + i.x) % 10
i.y = (random.randint(-1, 1) + i.y) % 10
# print('2 : ', i.x, i.y)
def affichage(self):
tableauMonde = []
# Pour chaque Colone
for i in range(self.taille):
listCol = []
# Pour chaque Case
for j in range(self.taille):
placeContainer = ''
listPoissCase = []
for p in ListePoisson:
if p.x == j and p.y == i:
listPoissCase.append(p.nombre)
if listPoissCase == []:
placeContainer += '_'
else:
listPoissCase = sorted(listPoissCase)
for chfr in listPoissCase:
if chfr == listPoissCase[-1]:
placeContainer += str(chfr)
else:
placeContainer += str(chfr) + ', '
listCol.append(placeContainer)
tableauMonde.append(listCol)
print(tabulate(tableauMonde, tablefmt='fancy_grid', numalign='left'))
print('Morts : ', self.nombreMorts)
def bataille(self):
ko = []
for i in range(self.taille):
for j in range(self.taille):
listTemp = []
for p in ListePoisson:
if p.x == j and p.y == i:
listTemp.append(p.nombre)
if not(listTemp == []) and len(listTemp) > 1:
listTemp = sorted(listTemp)
koTemp = []
for divPos, div in enumerate(listTemp[:-1]):
for m in listTemp[divPos+1:]:
if m % div == 0 and not(m in ko):
koTemp.append(m)
ko.append(m)
self.mortsTotaux.append(m)
print('Ko ce tour :', len(ko), '||', ko, '\n')
# Tuer les poissons
for i in ko:
ListePoisson.remove(next(x for x in ListePoisson if x.nombre == i))
self.nombreMorts += len(ko)
# **** FONCTIONS ****
def cls(): print('\n' * 30)
# **** CODE ****
console_resize(150)
Terrain = Monde(10, 100)
Terrain.affichage()
print("_________________\n")
# sleep(1)
input('press enter to start')
while rep < 5:
sleep(0.1)
cls()
sleep(0.1)
rep += 1
print('/\\/\\/\\/\\/\\/\\/\\/ TOUR N° :', rep, ' /\\/\\/\\/\\/\\/\\/\\/')
Terrain.deplacer()
Terrain.bataille()
Terrain.affichage()
sleep(1)
print('Liste morts : ', Terrain.mortsTotaux, '\nNombre de tours : ', rep, '\n')
input('press enter to exit\n')