Compare commits

...

2 Commits

Author SHA1 Message Date
21e783da88 Feat: reorga 2021-06-09 15:10:06 +02:00
b0e26e2c67 Feat: correction du Blackjack 2021-06-09 14:52:02 +02:00
10 changed files with 186 additions and 131 deletions

View File

@ -243,9 +243,6 @@ def play_backjack(nbr_players):
:param nbr_players: nombre de joueurs
:return: la liste des joueurs gagnants
:example:
>>>
"""
winners = []
deck = build_deck()
@ -253,26 +250,23 @@ def play_backjack(nbr_players):
dealer = Player("croupier")
# Première main
dealer = draw(dealer, deck)
dealer, deck = draw(dealer, deck)
players, deck = first_draw(players, deck)
still_in_game_players = File()
while not players.is_empty():
p = players.pop()
print(p)
if won(p):
winners.append(p)
elif can_play(p):
still_in_game_players.append(p)
else:
print(f"{p} est éliminé")
still_in_game_players.append(p)
if winners:
return winners
dealer = draw(dealer, deck)
dealer, deck = draw(dealer, deck)
if won(dealer):
return [dealer]
players = still_in_game_players
still_in_game_players = File()
while not players.is_empty():
p = players.pop()
while p.want_continue(dealer.hand):
@ -282,9 +276,29 @@ def play_backjack(nbr_players):
break
elif not can_play(p):
break
if can_play(p):
pass
if not can_play(p):
break
still_in_game_players.append(p)
if still_in_game_players.n == 0:
return []
while dealer.want_continue(dealer.hand):
dealer, deck = draw(dealer, deck)
if won(p):
return []
elif not can_play(p):
break
while not still_in_game_players.is_empty():
p = still_in_game_players.pop()
if not can_play(dealer):
winners.append(p)
elif p.score > dealer.score:
winners.append(p)
return winners
if __name__ == "__main__":
play_backjack(3)
print(play_backjack(3))

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

30
maze.py
View File

@ -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
View File

View 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
View 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###
######## ###########
"""