Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # http://zetcode.com/lang/tcl/io/
- # http://wiki.tcl.tk/1549
- # https://fr.wikipedia.org/wiki/Tool_Command_Language
- # ---------
- # Fonctions
- # ---------
- # Récupérer une valeur au hasard dans une liste
- proc random_pick { a_list } {
- # [expr int(rand() * $upper_limit + 1)]
- lindex $a_list [ expr { int(rand() * [ expr { [ llength $a_list ] - 1 } ]) } ]
- }
- # Donner la valeur d'une carte
- proc card_value { card } {
- set value [ lindex [ regexp -all -inline {(.+) de (.+)} $card ] 1 ]
- switch $value {
- valet - dame - roi { return 10 }
- as { return 11 }
- default { return $value }
- }
- }
- # Récupérer une carte dans le jeu
- proc pick_card { game i } {
- puts $i
- upvar $game a_game
- set card [ lreplace $a_game $i $i ]
- set a_game $card
- return [ lindex $card $i ]
- }
- # ---
- # Jeu
- # ---
- # Noms
- set names {
- Yannick Aurelie Guillaume Benoit Hugo Aymeric
- George Jeremy Matthieu Romain Elisa Corentin
- }
- # Cartes
- set cards { 2 3 4 5 6 7 8 9 10 valet dame roi as }
- # Types
- set types { coeur pique trefle carreau }
- # Création du jeu de cartes
- set game [ list ]
- foreach card $cards {
- foreach type $types {
- lappend game "$card de $type"
- }
- }
- set player(Yannick) [ list ]
- for { set i 0 } { $i < 3 } { incr i } {
- lappend player(Yannick) [ pick_card game [ lsearch $game [ random_pick $game ] ] ]
- }
- puts $player(Yannick)
- set score(Yannick) 0
- for { set i 0 } { $i < 3 } { incr i } {
- set score(Yannick) [ expr { $score(Yannick) + [ card_value [ lindex $player(Yannick) $i ] ] } ]
- }
- puts $score(Yannick)
- # puts $player(Yannick)
- # gets stdin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement