Feat: reorga
This commit is contained in:
parent
b0e26e2c67
commit
21e783da88
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 9.7 KiB |
30
maze.py
30
maze.py
@ -1,30 +0,0 @@
|
||||
def DeckOfCards():
|
||||
"""Génère un paquet de carte mélangé
|
||||
|
||||
Le "jeu mélangé" devra être une pile ou un file avec toutes les cartes.
|
||||
|
||||
"""
|
||||
jeu = # File ou Pile()
|
||||
# -----------------------
|
||||
|
||||
# -----------------------
|
||||
return jeu
|
||||
|
||||
|
||||
def main_bjack(jeu):
|
||||
result = 0
|
||||
# -----------------------
|
||||
|
||||
# -----------------------
|
||||
return result
|
||||
|
||||
|
||||
# Test : Distribution de toutes les cartes
|
||||
# j = DeckOfCards()
|
||||
# while not j.is_empty():
|
||||
# print(j.depile())
|
||||
|
||||
# Test : Calcul de mains de blackjack
|
||||
# j = DeckOfCards()
|
||||
# while not j.is_empty():
|
||||
# main_bjack(j)
|
0
maze/__init__.py
Normal file
0
maze/__init__.py
Normal file
@ -1,95 +1,7 @@
|
||||
########################################################################################
|
||||
#
|
||||
# TP - Structure de données linéaire : La pile
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
### import nécéssaires pour le TP
|
||||
import random
|
||||
import time
|
||||
from tkinter import *
|
||||
|
||||
########################################################################################
|
||||
# Classes Node() et Pile()
|
||||
########################################################################################
|
||||
class Node:
|
||||
def __init__(self, a=None, nxt=None) -> None:
|
||||
self.value = a
|
||||
self.nxt = nxt
|
||||
|
||||
|
||||
class Pile:
|
||||
def __init__(self) -> None:
|
||||
self.current = None
|
||||
self.n = 0
|
||||
|
||||
def is_empty(self):
|
||||
return self.current == None
|
||||
|
||||
def add(self, valeur):
|
||||
self.current = Node(valeur, nxt=self.current)
|
||||
self.n += 1
|
||||
|
||||
def depile(self):
|
||||
if not self.is_empty():
|
||||
a = self.current.value
|
||||
self.current = self.current.nxt
|
||||
self.n -= 1
|
||||
return a
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_top(self):
|
||||
return self.current.value if not self.is_empty() else None
|
||||
|
||||
def vide_la_pile(self):
|
||||
while not self.is_empty():
|
||||
self.depile()
|
||||
|
||||
|
||||
####################################################################################
|
||||
# Jeu de cartes
|
||||
####################################################################################
|
||||
def DeckOfCards():
|
||||
jeu_trie = []
|
||||
for valeur in [2, 3, 4, 5, 6, 7, 8, 9, 10, "Valet", "Dame", "Roi", "As"]:
|
||||
for couleur in ["Pique", "Coeur", "Trèfle", "Carreau"]:
|
||||
jeu_trie.append((valeur, couleur))
|
||||
jeu = Pile()
|
||||
while jeu_trie != []:
|
||||
# Un index du jeu trié au hasard
|
||||
i = random.randint(0, len(jeu_trie) - 1)
|
||||
jeu.add(jeu_trie[i]) # On ajoute la carte à la pile
|
||||
jeu_trie.pop(i) # On retire la carte du jeu trié
|
||||
return jeu
|
||||
|
||||
|
||||
def main_bjack(jeu):
|
||||
result = 0
|
||||
if jeu.n < 2:
|
||||
return result
|
||||
c1, c2 = jeu.depile(), jeu.depile()
|
||||
for c in [c1, c2]:
|
||||
if (c[0] == "Valet") or (c[0] == "Dame") or (c[0] == "Roi"):
|
||||
result += 10
|
||||
elif c[0] == "As":
|
||||
result += 11
|
||||
else:
|
||||
result += c[0]
|
||||
print(c1, c2, result)
|
||||
return result
|
||||
|
||||
|
||||
# Test : Distribution de toutes les cartes
|
||||
j = DeckOfCards()
|
||||
while not j.is_empty():
|
||||
print(j.depile())
|
||||
|
||||
# Test : Calcul de mains de blackjack
|
||||
j = DeckOfCards()
|
||||
while not j.is_empty():
|
||||
main_bjack(j)
|
||||
|
||||
####################################################################################
|
||||
# Labyrinthe
|
||||
####################################################################################
|
159
maze/maze.py
Normal file
159
maze/maze.py
Normal file
@ -0,0 +1,159 @@
|
||||
### import nécéssaires pour le TP
|
||||
import time
|
||||
from tkinter import *
|
||||
|
||||
####################################################################################
|
||||
# Labyrinthe
|
||||
####################################################################################
|
||||
def find_e(t):
|
||||
"""Permet de trouver l'entrée du labyrinthe"""
|
||||
# -----------------------
|
||||
|
||||
# -----------------------
|
||||
pass
|
||||
|
||||
|
||||
def aff(t):
|
||||
"""Affiche le labyrinth t"""
|
||||
# -----------------------
|
||||
|
||||
# -----------------------
|
||||
pass
|
||||
|
||||
|
||||
def avance(maze, p):
|
||||
"""Avance dans le labyrinthe"""
|
||||
# -----------------------
|
||||
|
||||
# -----------------------
|
||||
pass
|
||||
|
||||
|
||||
# Notre labyrinthe
|
||||
maze_str = """
|
||||
######################################
|
||||
#e # # # # #
|
||||
###### ## # # # # # # ##############
|
||||
# ## # # # # # ##s #
|
||||
###### ## # # #### # # ## # # ## #
|
||||
# # # # ## # #
|
||||
# ############## # # ######## # # ##
|
||||
# # # # # # # ## #
|
||||
# ##### ############ # # # ### ##
|
||||
# # # # # ## # ##
|
||||
######################################
|
||||
"""
|
||||
|
||||
# On transforme le labyrinthe en listes de chaînes de caractères
|
||||
maze = maze_str.split("\n")
|
||||
|
||||
# pile des positions inexplorées
|
||||
p = Pile()
|
||||
p.add(find_e(maze))
|
||||
|
||||
AFFICHAGE_CONSOLE = False # Mettre à True pour activer l'affichage dans la console
|
||||
|
||||
# Tant que la pile n'est pas vide ... on avance
|
||||
while not p.is_empty() and AFFICHAGE_CONSOLE:
|
||||
avance(maze, p)
|
||||
aff(maze)
|
||||
time.sleep(0.5)
|
||||
|
||||
########################
|
||||
# Interface avec tkinter
|
||||
########################
|
||||
|
||||
# Réinitialisation du labyrinthe
|
||||
maze = maze_str.split("\n")
|
||||
p.add(find_e(maze))
|
||||
|
||||
# Taille des cellules et du labyrinthe
|
||||
# -----------------------
|
||||
|
||||
# -----------------------
|
||||
|
||||
# Affichage
|
||||
root = Tk()
|
||||
root.title = "Labyrinthe"
|
||||
|
||||
# canevas = Canvas(root, width=xmax, height=ymax, background="#FFFFFF")
|
||||
# canevas.pack()
|
||||
|
||||
# Affichage labyrinthe avant l'algorithme de recherche
|
||||
# -----------------------
|
||||
|
||||
# -----------------------
|
||||
|
||||
# Boucle principale d'affichage
|
||||
def loop():
|
||||
# -----------------------
|
||||
|
||||
# -----------------------
|
||||
root.after(50, loop)
|
||||
|
||||
|
||||
root.after(50, loop)
|
||||
AFFICHAGE_TKINTER = False
|
||||
if AFFICHAGE_TKINTER:
|
||||
root.mainloop()
|
||||
|
||||
####################################################################################
|
||||
# Labyrinthes à tester :)
|
||||
####################################################################################
|
||||
|
||||
maze_str = """
|
||||
######################################
|
||||
#e # # # # #
|
||||
###### ## # # # # # # ##############
|
||||
# ## # # # # # ##s #
|
||||
###### ## # # #### # # ## # # ## #
|
||||
# # # # ## # #
|
||||
# ############## # # ######## # # ##
|
||||
# # # # # # # ## #
|
||||
# ##### ############ # # # ### ##
|
||||
# # # # # ## # ##
|
||||
######################################
|
||||
"""
|
||||
|
||||
maze_str = """
|
||||
######### ####
|
||||
## ## ##### s#
|
||||
# # ## # ##
|
||||
# # ## # # ####
|
||||
## # # #
|
||||
#### # # # # #
|
||||
##### #### ### #
|
||||
# # # # # #### # # #
|
||||
# # # # ## # #
|
||||
###### # # ### # #
|
||||
# ## # # #
|
||||
#### # #####
|
||||
## # ## # #
|
||||
# # # ### ###
|
||||
# # # e####
|
||||
##### # #
|
||||
########
|
||||
"""
|
||||
|
||||
maze_str = """
|
||||
####
|
||||
#e #
|
||||
## ########
|
||||
####### # #
|
||||
# # # # # # # ##
|
||||
# # ## # #
|
||||
### ## # # # #########
|
||||
# # ## # ## # # #
|
||||
## # # ## # # # #
|
||||
# ## # ### # # ### # #
|
||||
# ### # # ## ## # ##
|
||||
##### # # ## # # #
|
||||
# # ### # # # ### ### ##
|
||||
# ## # # # ## #
|
||||
# ## ## # ## ## # #
|
||||
## # # # # ## ## # ###
|
||||
## ## # # # # # # ###
|
||||
# ##### # # # ###
|
||||
## # # # # #s###
|
||||
######## ###########
|
||||
"""
|
Loading…
Reference in New Issue
Block a user