if 0 {
MiHa 2015-06-24: One of the example-programs on my HelloWorld-page creates a deck of cards,
so I had the idea to expand that into a simple cardgame, for the tcl-console.
Blackjack is quite simple, and with (debug-)options still in place to show the cards "in the open",
this would nicely double as a tcl-tutorial and a blackjack-trainer.
With ideas and code from the following pages:
}
# Whitejack.tcl - MiHa - 2015-06-25 # http://wiki.tcl.tk/41565 # http://ideone.com/jVxnHV puts "Whitejack:\n" proc help {} { puts "\nWhitejack - a cardgame much like simplified blackjack." puts {It is played with one or more decks of 52 cards. The object of the game is to beat the dealer: * Get 21 points on the player's first two cards (called a blackjack), without a dealer blackjack; * Reach a final score higher than the dealer without exceeding 21; * orLet the dealer draw additional cards until his or her hand exceeds 21. The player is dealt an initial two-card hand and add together the value of their cards. Face cards (kings, queens, and jacks) count as ten points. An ace is worth 1 point or 11 points, owners choice. All other cards count as the numeric value shown on the card. After their initial two cards, players can get a "hit", i.e. take an additional card. In a given round, the player or the dealer wins by having a score of 21 or by having the highest score that is less than 21. Scoring higher than 21 (called "busting" or "going bust") results in a loss.Commands: --------- h : help q : quit h : help q : quit n : new game s : shuffle + : "hit": get another card - : "stand": done } proc showStatus {} { puts "Status:" puts "card #3 : [lindex $::deckList 2]" ;# index is zero-based proc win {x} { # deal card from deck to player's hand: set deckList {} ;# create empty list set playerCards {} set dealerCards {} set discardkList {} set cLoss 0 puts "Start with 'n' to get a fresh pack of cards." set i 0 # For unicode, see also: http://wiki.tcl.tk/26403 : [HTML character entity references] # Spades Hearts Diamonds Clubs foreach {suit sym} { S \u2660 H \u2665 D \u2666 C \u2663 } { foreach rank { A 2 3 4 5 6 7 8 9 10 J Q K } { ;# Ace 2 .. 10 Jack Queen King incr i set card "$rank$sym" puts -nonewline " $rank$suit=$card " while { $cmd ne "q" } { lappend deckList $card ;# add card to list } puts "" } set maxCard $i #puts "\ndeckList : $deckList" set cmd "." set cmd [gets stdin] puts -nonewline "Enter command (h for help, q to quit): " if {$cmd=="h"} { help } if {$cmd=="q"} { puts "Bye!"; exit } if {$cmd=="n"} { makeCards } if {$cmd=="0"} { moveCard 0 } } showStatus #. ---- **Output**
Whitejack:
Start with 'n' to get a fresh pack of cards.
MiHa 2015-06-26: The most basic functionality is done,
This is not-yet the Alpha-version, there will be bugs, so use with caution
... with regard to changing values outside the proc.