Compare commits
No commits in common. "21e783da883ed8f9ce0edc605fa59f195b6f9a40" and "7d301e701938cbbbf5431617da711e9e0ac1fafa" have entirely different histories.
21e783da88
...
7d301e7019
@ -243,6 +243,9 @@ def play_backjack(nbr_players):
|
|||||||
:param nbr_players: nombre de joueurs
|
:param nbr_players: nombre de joueurs
|
||||||
:return: la liste des joueurs gagnants
|
:return: la liste des joueurs gagnants
|
||||||
|
|
||||||
|
:example:
|
||||||
|
>>>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
winners = []
|
winners = []
|
||||||
deck = build_deck()
|
deck = build_deck()
|
||||||
@ -250,23 +253,26 @@ def play_backjack(nbr_players):
|
|||||||
dealer = Player("croupier")
|
dealer = Player("croupier")
|
||||||
|
|
||||||
# Première main
|
# Première main
|
||||||
dealer, deck = draw(dealer, deck)
|
dealer = draw(dealer, deck)
|
||||||
players, deck = first_draw(players, deck)
|
players, deck = first_draw(players, deck)
|
||||||
still_in_game_players = File()
|
still_in_game_players = File()
|
||||||
while not players.is_empty():
|
while not players.is_empty():
|
||||||
p = players.pop()
|
p = players.pop()
|
||||||
|
print(p)
|
||||||
if won(p):
|
if won(p):
|
||||||
winners.append(p)
|
winners.append(p)
|
||||||
still_in_game_players.append(p)
|
elif can_play(p):
|
||||||
|
still_in_game_players.append(p)
|
||||||
|
else:
|
||||||
|
print(f"{p} est éliminé")
|
||||||
if winners:
|
if winners:
|
||||||
return winners
|
return winners
|
||||||
|
|
||||||
dealer, deck = draw(dealer, deck)
|
dealer = draw(dealer, deck)
|
||||||
if won(dealer):
|
if won(dealer):
|
||||||
return [dealer]
|
return [dealer]
|
||||||
|
|
||||||
players = still_in_game_players
|
players = still_in_game_players
|
||||||
still_in_game_players = File()
|
|
||||||
while not players.is_empty():
|
while not players.is_empty():
|
||||||
p = players.pop()
|
p = players.pop()
|
||||||
while p.want_continue(dealer.hand):
|
while p.want_continue(dealer.hand):
|
||||||
@ -276,29 +282,9 @@ def play_backjack(nbr_players):
|
|||||||
break
|
break
|
||||||
elif not can_play(p):
|
elif not can_play(p):
|
||||||
break
|
break
|
||||||
if not can_play(p):
|
if can_play(p):
|
||||||
break
|
pass
|
||||||
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__":
|
if __name__ == "__main__":
|
||||||
print(play_backjack(3))
|
play_backjack(3)
|
@ -1,7 +1,95 @@
|
|||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# TP - Structure de données linéaire : La pile
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
### import nécéssaires pour le TP
|
### import nécéssaires pour le TP
|
||||||
|
import random
|
||||||
import time
|
import time
|
||||||
from tkinter import *
|
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
|
# Labyrinthe
|
||||||
####################################################################################
|
####################################################################################
|
30
maze.py
Normal file
30
maze.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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)
|
159
maze/maze.py
159
maze/maze.py
@ -1,159 +0,0 @@
|
|||||||
### 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###
|
|
||||||
######## ###########
|
|
||||||
"""
|
|
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 |
Loading…
Reference in New Issue
Block a user