Commit 66e08f49 authored by Maxime DEBUREAU's avatar Maxime DEBUREAU
Browse files

Version 1.1 du programme, modification des codes avec création des classes fondamentales.

parent c34bb9e8
import numpy as np
import time
import random
import Plateau
class Robot :
def __init__(self, abscisse, ordonnee, couleur):
self.absc = abscisse
self.ordo = ordonnee
self.name = "R_" + couleur
self.color = couleur
self.type = "R"
def move_up(self):
while self.ordo > 0 :
if Plateau.plateau_jeu[self.absc,self.ordo,1] != "V" : #Condition qu'on évolue pas dans le vide
break
if "H" in Plateau.plateau_jeu[self.absc,self.ordo,0] : #Condition qu'on puisse monter (au niveau des murs)
break
else :
self.absc = self.absc
self.ordo = self.ordo -1
def move_down(self):
while self.ordo < 15:
if Plateau.plateau_jeu[self.absc, self.ordo, 1] != "V": # Condition qu'on évolue pas dans le vide
break
if "B" in Plateau.plateau_jeu[
self.absc, self.ordo, 0]: # Condition qu'on puisse monter (au niveau des murs)
break
else:
self.absc = self.absc
self.ordo = self.ordo + 1
def move_left(self):
while self.absc > 0:
if Plateau.plateau_jeu[self.absc, self.ordo, 1] != "V": # Condition qu'on évolue pas dans le vide
break
if "H" in Plateau.plateau_jeu[
self.absc, self.ordo, 0]: # Condition qu'on puisse monter (au niveau des murs)
break
else:
self.absc = self.absc
self.ordo = self.ordo - 1
def move_up(self):
while self.ordo > 0:
if Plateau.plateau_jeu[self.absc, self.ordo, 1] != "V": # Condition qu'on évolue pas dans le vide
break
if "H" in Plateau.plateau_jeu[
self.absc, self.ordo, 0]: # Condition qu'on puisse monter (au niveau des murs)
break
else:
self.absc = self.absc
self.ordo = self.ordo - 1
def find_and_create_robots(Plateau) :
import numpy as np
import time
import random
# database plateau
# H = barriere en Haut, G gauche, D droite, B bas, on écrit tjrs dans l'ordre HGDB,
# Cas partculiers pour V = vide, K = Korner ("intouchable")
List_1A = [['HG', 'H', 'H', 'H', 'H', 'HD', 'HG', 'H'],
['G', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['G', 'B', 'V', 'V', 'V', 'V', 'V', 'V'],
['GD', 'HG', 'V', 'V', 'V', 'V', 'V', 'V'],
['G', '', 'V', 'V', 'V', 'V', 'DB', 'G'],
['GB', 'V', 'B', 'V', 'V', 'V', 'H', 'V'],
['HG', 'V', 'HD', 'GB', 'V', 'V', 'V', 'B'],
['G', 'V', 'V', 'H', 'V', 'V', 'D', 'K']]
List_1B = [['HG', 'HD', 'HG', 'HB', 'H', 'H', 'H', 'H'],
['G', 'V', 'D', 'HG', 'V', 'V', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'DB', 'G'],
['GD', 'GB', 'V', 'V', 'V', 'V', 'H', 'V'],
['G', 'H', 'V', 'V', 'B', 'V', 'V', 'V'],
['GB', 'V', 'V', 'V', 'HD', 'G', 'V', 'B'],
['HG', 'V', 'V', 'V', 'V', 'V', 'D', 'K']]
List_2A = [['HG', 'H', 'HD', 'HG', 'H', 'H', 'H', 'H'],
['G', 'V', 'V', 'V', 'V', 'V', 'B', 'V'],
['G', 'V', 'V', 'V', 'V', 'DB', 'HG', 'V'],
['G', 'V', 'V', 'V', 'V', 'H', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['GD', 'GB', 'V', 'V', 'V', 'V', 'V', 'V'],
['GB', 'H', 'V', 'V', 'B', 'V', 'V', 'B'],
['HG', 'V', 'V', 'V', 'HD', 'G', 'D', 'K']]
List_2B = [['HG', 'H', 'H', 'H', 'H', 'HD', 'HG', 'H'],
['G', 'V', 'V', 'B', 'V', 'V', 'V', 'V'],
['G', 'V', 'D', 'HG', 'V', 'V', 'V', 'V'],
['GB', 'V', 'B', 'V', 'D', 'GB', 'V', 'V'],
['HG', 'V', 'HD', 'G', 'V', 'H', 'V', 'V'],
['GD', 'GB', 'V', 'V', 'V', 'V', 'V', 'V'],
['GB', 'H', 'V', 'V', 'B', 'V', 'V', 'B'],
['HG', 'V', 'V', 'V', 'HD', 'G', 'D', 'K']]
List_4A = [['HG', 'HD', 'HG', 'HB', 'H', 'H', 'H', 'H'],
['G', 'V', 'D', 'HG', 'V', 'V', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'DB', 'G'],
['GD', 'GB', 'V', 'V', 'V', 'V', 'H', 'V'],
['G', 'H', 'V', 'V', 'B', 'V', 'V', 'V'],
['GB', 'V', 'V', 'V', 'HD', 'G', 'V', 'B'],
['HG', 'V', 'V', 'V', 'V', 'V', 'D', 'K']]
List_P_Plat = [List_1A,List_1B,List_2A,List_2B,List_4A]
def quart_droit_p_plateau(p_plat):
p_plat = np.array(p_plat)
p_plat = np.rot90(p_plat, 3)
print("rotation", p_plat)
for i in range(8):
for j in range(8):
if p_plat[i][j] == 'G':
p_plat[i][j] = 'H'
elif p_plat[i][j] == 'H':
p_plat[i][j] = 'D'
elif p_plat[i][j] == 'D':
p_plat[i][j] = 'B'
elif p_plat[i][j] == 'B':
p_plat[i][j] = 'G'
elif p_plat[i][j] == 'HG':
p_plat[i][j] = 'HD'
elif p_plat[i][j] == 'HD':
p_plat[i][j] = 'DB'
elif p_plat[i][j] == 'DB':
p_plat[i][j] = 'GB'
elif p_plat[i][j] == 'GB':
p_plat[i][j] = 'HG'
elif p_plat[i][j] == 'HB':
p_plat[i][j] = 'GD'
# --------------------------------------------------------------------------
#
# Ce module contient la classe plateau, qui régule l'espace de jeu
#
# -----------------------------------------------------------------------------
elif p_plat[i][j] == 'GD':
p_plat[i][j] = 'HB'
print("iteration", p_plat)
# H = barriere en Haut, G gauche, D droite, B bas, on écrit tjrs dans l'ordre HGDB,
# Cas partculiers pour V = vide, K = Korner ("intouchable")
print("rotation + transfo", p_plat)
return (p_plat)
## Attention ! Les arrays 3D sont dimensionnées tq dim 0 long_tblo, dim 1 larg_tblo, dim 2 épaisseur_tblo
## Pour obtenir le layer "murs" il faut [:,:,0], et pour le layer Jetons [:,:,1]
def former_plateau (List_P_Plat):
l = np.random.sample(range(len(List_P_Plat),4))
print(l)
# List_formation_plateau = [List_P_Plat[l[0]],List_P_Plat[l[1]],List_P_Plat[l[2]],List_P_Plat[l[3]]]
# List_formation_plateau = np.random.sample(List_P_Plat,4)
np.random.shuffle(List_formation_plateau)
p_plat_1, p_plat_2, p_plat_3, p_plat_4 = List_formation_plateau[0], List_formation_plateau[1], List_formation_plateau[2], List_formation_plateau[3]
print(p_plat_1, p_plat_2, p_plat_3, p_plat_4)
p_plat_1 = np.array(p_plat_1)
p_plat_2 = quart_droit_p_plateau(p_plat_2)
p_plat_3 = quart_droit_p_plateau(quart_droit_p_plateau(p_plat_3))
p_plat_4 = quart_droit_p_plateau(quart_droit_p_plateau(quart_droit_p_plateau(p_plat_4)))
A = concatenate(p_plat_1,p_plat_2, axis = 1)
B = concatenate(p_plat_4,p_plat_3, axis = 1)
C = concatenate(A,B,axis=0)
print(C)
dict_rotation = {
'V' : 'V',
'G' : 'H',
'H' : 'D',
'D' : 'B',
'B' : 'G',
'HG' : 'HD',
'HD' : 'DB',
'DB' : 'GB',
'GB' : 'HG',
'GD' : 'HB',
'HB' : 'GD'
}
former_plateau(List_P_Plat)
#
# P_Plat_1B = np.array(List_1B)
# P_Plat_1B_R = quart_droit_p_plateau(P_Plat_1B)
def quart_droit_p_plateau(tblo_plat):
tblo_plat_bot = tblo_plat[:,:,0]
tblo_plat_top = tblo_plat[:,:,1]
tblo_plat_bot = np.rot90(tblo_plat_bot,3)
tblo_plat_top = np.rot90(tblo_plat_top, 3)
for i in range(8):
for j in range(8):
# tblo_plat_bot[i][j] = dict_rotation(tblo_plat_bot[i][j])
if tblo_plat_bot[i][j] == 'G':
tblo_plat_bot[i][j] = 'H'
elif tblo_plat_bot[i][j] == 'H':
tblo_plat_bot[i][j] = 'D'
elif tblo_plat_bot[i][j] == 'D':
tblo_plat_bot[i][j] = 'B'
elif tblo_plat_bot[i][j] == 'B':
tblo_plat_bot[i][j] = 'G'
elif tblo_plat_bot[i][j] == 'HG':
tblo_plat_bot[i][j] = 'HD'
elif tblo_plat_bot[i][j] == 'HD':
tblo_plat_bot[i][j] = 'DB'
elif tblo_plat_bot[i][j] == 'DB':
tblo_plat_bot[i][j] = 'GB'
elif tblo_plat_bot[i][j] == 'GB':
tblo_plat_bot[i][j] = 'HG'
elif tblo_plat_bot[i][j] == 'HB':
tblo_plat_bot[i][j] = 'GD'
elif tblo_plat_bot[i][j] == 'GD':
tblo_plat_bot[i][j] = 'HB'
tblo_plat = np.dstack((tblo_plat_bot,tblo_plat_top))
return (tblo_plat)
def create_quart_tuple(bot_list, top_list):
tblo_bot = np.array(bot_list)
tblo_top = np.array(top_list)
tblo_final = np.dstack((tblo_bot, tblo_top))
tblo_final.reshape((2, 8, 8))
return (tblo_final)
List_1A_bot = [['HG', 'H', 'H', 'H', 'H', 'HD', 'HG', 'H'],
['G', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['G', 'B', 'V', 'V', 'V', 'V', 'V', 'V'],
['GD', 'HG', 'V', 'V', 'V', 'V', 'V', 'V'],
['G', '', 'V', 'V', 'V', 'V', 'DB', 'G'],
['GB', 'V', 'B', 'V', 'V', 'V', 'H', 'V'],
['HG', 'V', 'HD', 'GB', 'V', 'V', 'V', 'B'],
['G', 'V', 'V', 'H', 'V', 'V', 'D', 'K']]
List_1A_sup = [['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'K']]
tblo_1A = create_quart_tuple(List_1A_bot, List_1A_sup)
List_1B_bot = [['HG', 'HD', 'HG', 'HB', 'H', 'H', 'H', 'H'],
['G', 'V', 'D', 'HG', 'V', 'V', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'DB', 'G'],
['GD', 'GB', 'V', 'V', 'V', 'V', 'H', 'V'],
['G', 'H', 'V', 'V', 'B', 'V', 'V', 'V'],
['GB', 'V', 'V', 'V', 'HD', 'G', 'V', 'B'],
['HG', 'V', 'V', 'V', 'V', 'V', 'D', 'K']]
List_1B_sup = [['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'K']]
tblo_1B = create_quart_tuple(List_1B_bot, List_1B_sup)
List_2A_bot = [['HG', 'H', 'HD', 'HG', 'H', 'H', 'H', 'H'],
['G', 'V', 'V', 'V', 'V', 'V', 'B', 'V'],
['G', 'V', 'V', 'V', 'V', 'DB', 'HG', 'V'],
['G', 'V', 'V', 'V', 'V', 'H', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['GD', 'GB', 'V', 'V', 'V', 'V', 'V', 'V'],
['GB', 'H', 'V', 'V', 'B', 'V', 'V', 'B'],
['HG', 'V', 'V', 'V', 'HD', 'G', 'D', 'K']]
List_2A_sup = [['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'K']]
tblo_2A = create_quart_tuple(List_2A_bot, List_2A_sup)
List_2B_bot = [['HG', 'H', 'H', 'H', 'H', 'HD', 'HG', 'H'],
['G', 'V', 'V', 'B', 'V', 'V', 'V', 'V'],
['G', 'V', 'D', 'HG', 'V', 'V', 'V', 'V'],
['GB', 'V', 'B', 'V', 'D', 'GB', 'V', 'V'],
['HG', 'V', 'HD', 'G', 'V', 'H', 'V', 'V'],
['GD', 'GB', 'V', 'V', 'V', 'V', 'V', 'V'],
['GB', 'H', 'V', 'V', 'B', 'V', 'V', 'B'],
['HG', 'V', 'V', 'V', 'HD', 'G', 'D', 'K']]
List_2B_sup = [['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'K']]
tblo_2B = create_quart_tuple(List_2B_bot, List_2B_sup)
List_4A_bot = [['HG', 'HD', 'HG', 'HB', 'H', 'H', 'H', 'H'],
['G', 'V', 'D', 'HG', 'V', 'V', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['G', 'V', 'V', 'V', 'V', 'V', 'DB', 'G'],
['GD', 'GB', 'V', 'V', 'V', 'V', 'H', 'V'],
['G', 'H', 'V', 'V', 'B', 'V', 'V', 'V'],
['GB', 'V', 'V', 'V', 'HD', 'G', 'V', 'B'],
['HG', 'V', 'V', 'V', 'V', 'V', 'D', 'K']]
List_4A_sup = [['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'V'],
['V', 'V', 'V', 'V', 'V', 'V', 'V', 'K']]
tblo_4A = create_quart_tuple(List_4A_bot, List_4A_sup)
List_tblos = [tblo_1A, tblo_1B, tblo_2A, tblo_2B, tblo_4A]
def create_plateau(List_tblos):
List_fin_plateau = random.sample(List_tblos, 4)
np.random.shuffle(List_fin_plateau)
tblo_plat_1, tblo_plat_2, tblo_plat_3, tblo_plat_4 = List_fin_plateau[0], List_fin_plateau[1], List_fin_plateau[
2], List_fin_plateau[3]
tblo_plat_2 = quart_droit_p_plateau(tblo_plat_2)
tblo_plat_3 = quart_droit_p_plateau(quart_droit_p_plateau(tblo_plat_3))
tblo_plat_4 = quart_droit_p_plateau(quart_droit_p_plateau(quart_droit_p_plateau(tblo_plat_4)))
A = np.concatenate((tblo_plat_1, tblo_plat_2), axis=1)
B = np.concatenate((tblo_plat_4, tblo_plat_3), axis=1)
C = np.concatenate((A, B), axis=0)
return(C)
class Plateau :
def __init__(self,List_tblos):
List_fin_plateau = random.sample(List_tblos, 4)
np.random.shuffle(List_fin_plateau)
tblo_plat_1, tblo_plat_2, tblo_plat_3, tblo_plat_4 = List_fin_plateau[0], List_fin_plateau[1], List_fin_plateau[2], List_fin_plateau[3]
tblo_plat_2 = quart_droit_p_plateau(tblo_plat_2)
tblo_plat_3 = quart_droit_p_plateau(quart_droit_p_plateau(tblo_plat_3))
tblo_plat_4 = quart_droit_p_plateau(quart_droit_p_plateau(quart_droit_p_plateau(tblo_plat_4)))
A = np.concatenate((tblo_plat_1, tblo_plat_2), axis=1)
B = np.concatenate((tblo_plat_4, tblo_plat_3), axis=1)
C = np.concatenate((A, B), axis=0)
self.PJ = C
def find_and_create_robot_entities(self):
Plat_Jeu = Plateau(List_tblos)
import numpy as np
import time
import random
import Plateau
import Pièce
#Programme principal et son organisation générale
#On constitue d'abord un plateau
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment