View difference between Paste ID: gVpTRXLf and L24U21h5
SHOW: | | - or go back to the newest paste.
1
# http://zetcode.com/lang/tcl/io/
2
# http://wiki.tcl.tk/1549
3
# https://fr.wikipedia.org/wiki/Tool_Command_Language
4
5
# ---------
6
# Fonctions
7
# ---------
8
# Récupérer une valeur au hasard dans une liste
9-
proc lpick list {
9+
proc random_pick { a_list } {
10-
	lindex $list [ expr { int(rand() * [ llength $list ]) } ]
10+
	# [expr int(rand() * $upper_limit + 1)] 
11
	lindex $a_list [ expr { int(rand() * [ expr { [ llength $a_list ] - 1 } ]) } ]
12
}
13
14-
proc card_value card {
14+
15-
	switch $card {
15+
proc card_value { card } {
16
	set value [ lindex [ regexp -all -inline {(.+) de (.+)} $card ] 1 ]
17
18-
		default            { return $card }
18+
	switch $value {
19
		valet - dame - roi { return 10 }
20
		as                 { return 11 }
21
		default            { return $value }
22-
proc pick_card {game i} {
22+
23
}
24
25
# Récupérer une carte dans le jeu
26
proc pick_card { game i } {
27
	puts $i
28
	upvar $game a_game
29
	set card [ lreplace $a_game $i $i ]
30
	set a_game $card
31
	return [ lindex $card $i ]
32
}
33
34-
	Yannick Aurélie Guillaume Benoît Hugo Aymeric
34+
35-
	George Jérémy Matthieu Romain Elisa Corentin
35+
36
# ---
37
# Noms
38
set names {
39
	Yannick Aurelie Guillaume Benoit Hugo Aymeric
40
	George Jeremy Matthieu Romain Elisa Corentin
41
}
42-
set types { coeur pique trèfle carreau }
42+
43
# Cartes
44
set cards { 2 3 4 5 6 7 8 9 10 valet dame roi as }
45
46
# Types
47
set types { coeur pique trefle carreau }
48
49
# Création du jeu de cartes
50
set game [ list ]
51
52
foreach card $cards {
53
	foreach type $types {
54
		lappend game "$card de $type"
55
	}
56-
	lappend player(Yannick) [ pick_card game [ lsearch $game [ lpick $game ] ] ]
56+
57
58
set player(Yannick) [ list ]
59
60
for { set i 0 } { $i < 3 } { incr i } {
61
	lappend player(Yannick) [ pick_card game [ lsearch $game [ random_pick $game ] ] ]
62
}
63
64
puts $player(Yannick)
65
66
set score(Yannick) 0
67
68
for { set i 0 } { $i < 3 } { incr i } {
69
	set score(Yannick) [ expr { $score(Yannick) + [ card_value [ lindex $player(Yannick) $i ] ] } ]
70
}
71
72
puts $score(Yannick)
73
74
# puts $player(Yannick)
75
76
# gets stdin