This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Its very hard to reply reasonably without some background of the correspondent on their Wiki bio page. Thanks,gold
gold Here are some calculations for poker probability using TCL expressions in the Windows console with the easy eye line calculator. The impetus for these calculations was checking some poker probabilities, mostly on Texas Holdem Poker, but also 5 Card Poker. Its easy enough to cut and paste TCL based formulas into the easy eye calculator console. Most of the checked testcases involve TCLLIB math functions.
The baby game engine in Mahjong Deletion can be converted or hacked into a set of 52 poker cards. In Texas Holdem Poker, there are four stages of deals and four stages of betting until the final round. All suits are equal and no suit is worth more than another. No Joker cards are used. The winner has the best five-card hand possible using the player’s two cards as pocket cards and the five dealt in the middle of the table. The odds change with each deal, so betting is tricky for the players or exciting for the spectators. On most deals, players have betting options for check, call, raise, or fold. The end of game or last betting session is sometimes called a showdown. Usually a chip marked dealer is passed or shared among the players for the responsibility of dealing the cards. Two antes or blinds are placed for the responsibility of different players as the places of the binds are relative to the selected dealer for the hand. The "Big Blind" is placed on the right of the dealer and the "Small Blind" is placed on the left of the dealer. For only two players or small player games, some of the "Big Blind" and "Small Blind" rules are omitted or handled differently. On the canvas widget of TCL, the four stages of deals can be raised or lowered into spectator view from the underscreen with buttons and keyed canvas tags. In the internal TCL code, each card can be dealt from a fresh deck of electrons. Initially and unlike the Las Vegas tables, a dealt card will not be removed from the 52 total deck.
Revision
In planning any software, it is advisable to gather a number of testcases to check the results of the program. The math for the testcases can be checked by pasting statements with added brackets in the TCL console. Also, some of the pseudocode statements were checked in the google search engine which will take math expressions. Ref factorial procedure in original routines was posted by Suchenwirth RS, but the factorial and derived choose functions are included in the TCLLIB math library.
Revision. In Texas Holdem Poker, there are four stages of deals and four stages of betting until the final round. All suits are equal and no suit is worth more than another. No Joker cards are used. Gameplay The winner has the best five-card hand possible using the player's two cards as pocket cards and the five dealt in the middle of the table. The odds change with each deal, so betting is tricky for the players or exciting for the spectators. On most deals, players have betting options for check, call, raise, or fold. The end of game or last betting session is sometimes called a showdown. Betting and Blinds Usually a chip marked dealer is passed or shared among the players for the responsibility of dealing the cards. Two antes or blinds are placed for the responsibility of different players as the places of the binds are relative to the selected dealer for the hand. The "Big Blind" is placed on the right of the dealer and the "Small Blind" is placed on the left of the dealer. For only two players or small player games, some of the "Big Blind" and "Small Blind" rules are omitted or handled differently. Implementation in Mahjong Deletion On the canvas widget of TCL, the four stages of deals can be raised or lowered into spectator view from the underscreen with buttons and keyed canvas tags. In the internal TCL code, each card can be dealt from a fresh deck of electrons. Initially and unlike the Las Vegas tables, a dealt card will not be removed from the 52 total deck.
| table. Four styles of Texas Holdem odds | dealt cards in a hand | Bet numbers | player options | comment if any |
|---|---|---|---|---|
| preflop odds | 2 | bet1 | After pocket, call, raise, or fold | first 2 called pocket or hole card |
| flop odds | 3 | bet2 | After flop, check, raise, or fold | |
| turn odds | 1 | bet3 | After turn, check, raise, or fold | |
| river odds | 1 | bet4 | After river, check, raise, or fold | |
| >> gist <<< | ||||
| totals | 7 cards | 4 bets | 12 possible actions, expected in typical game |
| quantity | P_probability, S_space etc | 100X, alternate percent, if applicable | formula TCL | comments if any |
|---|---|---|---|---|
| texas_pocket_pair_space | 1326 | expr { math::choose 52 2 } | ||
| texas_pocket_pair | 0.004524886 | 0.4524886 | expr { (1.*math::choose 4 2 )/ math::choose 52 2 } | odds 220:1 |
| any_texas_pocket_pair | 0.0588 | 5.88 | expr { 78/1326 } | odds 16:1 |
| specific_texas_suited combination | 4 | expr { math::choose 4 1 } | ||
| specific_texas_suited_hand | 0.003 | 0.3 | expr { 4/1326 } | odds 331:1 |
| any_texas_suited combination | 312 | expr { 4*78 } | ||
| any_texas_suited_hand | 0.2352 | 23.52 | expr { 312/1326 } | odds 3.25:1 |
Picking up a five card hand, what is the probability and odds of a straight flush, less royal flush ? The sample space is 52!/((5!* (52-5)!) or 2598960. The frequency is (10 choose 1)*(4 choose 1) -(4 choose 1) , 10!/((1!* (10-1)!) * 4!/((1!* (4-1)!) - 4!/((1!* (4-1)!) , 40-4,or 36. The text books use the expression <4 choose 1>, but the TCLLIB math library is invoked by the expression <math::choose 4 1>.
set straight_flush [expr { (1.*36)/ 2598960 } ]
set straight_flush_odds [expr { 1./( (1.*36)/ 2598960 ) } ]
answer% 1.39E-5 , 72192.0| Probabilities in 5 Card Poker | |||||
|---|---|---|---|---|---|
| hand | choose formula | frequency | division terms | probability | odds |
| royal flush | (4 choose 1) | 4 | 4/258960 | 1.54E-5 | 64739 |
| straight flush less royal flush | (10 choose 1)* (4 choose 1) -(4 choose 1) | 36 | 36/258960 | 1.39E-5 | 72192 |
| four of kind | (13 choose 1)* (12 choose 1) *(4 choose 1) | 624 | 624/258960 | 2.4E-4 | 4164 |
| full house | (13 choose 1)* (4 choose 3) *(12 choose 2) | 858 | 858/258960 | 2.11E-2 | 46.3 |
| three of kind | (13 choose 1)* (4 choose 3) *(12 choose 2)* (4 choose 2) | 156 | 156/258960 | 1.44E-3 | 693 |
more than one formula for 1) tables and 2) calculator shell
######)))))) TCL source code follows
# pretty print from autoindent and ased editor
# program Texas Hold Dem Cards.
# adapted from Mahjong_Style_Deletion
# written on Windows XP for TCL
# working under TCL version 8.6
# The original base M. was adapted
# from aricb on the Ask page.
# Probably could start a post,
# since it is a good baby game
# engine. Wish to study dealt values and
# probability of Texas Hold Dem Cards.
# Need to evaluate hands and bet on them.
# I added a few buttons at the bottom
# and tried to keep the clean code separate up top.
# Richard Suchenwirth RS wrote lpick routine below.
# de on TCL Club, 15nov2018
package require Tk
package require math
namespace path {::tcl::mathop ::tcl::mathfunc }
global deck suit
global selectedid selectedtext
global new_card_state
set new_card_state 0
set deck {}
set suitfrenchblack { \u2665 \u2666 \u2663 \u2660 }
set suitfrenchblanc { \u2664 \u2661 \u2662 \u2667 }
# utilities
# suchenwirth_subroutine RS
proc lpick L {lindex $L [expr {int(rand()*[llength $L])} ];}
proc plainsub {text item replacewith} {
set text [string map [list $item $replacewith] $text]
}
proc deal {args} {
global deck suit
foreach suit { \u2665 \u2666 \u2663 \u2660 } {
foreach item $args {
set kay "$item $suit "
set value 1
if {$item == "J"} {set value 10}
if {$item == "Q"} {set value 10}
if {$item == "K"} {set value 10}
if {$item == "A"} {set value 10}
set kay "[append item $suit \ $value ]"
lappend deck $kay
}}
return $deck
}
deal 2 3 4 5 6 7 8 9 10 A J Q K
puts "$deck new_card state equals $new_card_state"
proc self_help {} {
set msg "Texas Hold Dem Cards V2
from TCL ,
# self help listing
# >>>> Copyright Notice <<<<<
# This posting, screenshots, and TCL source code is
# copyrighted under the TCL/TK 8.6 license terms.
# Editorial rights retained under
# the TCL/TK license terms
# and will be defended as necessary in court.
# >>>> Push Button Operation <<<<
# Push left mouse to activate buttons.
# Deal shuffles all hands.
# Move_right_mouse_for_one_card deal.
# All cards listed with value.
# Deck is 52 cards, no jokers.
# Report allows copy and paste
# from console to conventional
# texteditor. For testcases,
# the testcase number is internal
# to the calculator and
# will not be printed until
# the report button is pushed
# for the current result numbers.
# Where the program defaults are recalled,
# canvas colors/features/variables/globals/calculations/clear displays
# may reset prior to calculation
# ( in push button list) .
# Buttons on the calculator are not
# limited to a single action procedure
# or single shot. A button command may
# call multiple statements and procs,
# effectively a separate program or
# subprogram installed as
# a list of procedures in a button.
# Alternately, the list of procedures
# need not be installed in a button,
# but in a separate procedure.
Conventional text editor formulas
or grabbed from internet
screens can be pasted into green console.
Try copy and paste following
into green screen console
set answer [* 1. 2. 3. 4. 5. ]
returns 120
# gold on TCL Club, 15nov2018 "
tk_messageBox -title "self_help" -message $msg }
proc populateCanvas {canvas cols rows} {
variable ids ;# links text ids with respective rect ids
variable boxes ;# lists text id and text associated with each rect id
global deck suitfrenchblack suitfrenchblanc
catch {unset ids boxes}
# parameters for drawing boxes
set boxwidth 50
set boxheight 20
set padx 10
set pady 10
set colors {red orange yellow green blue purple}
set money_color { red }
set labels {one two three four}
# draw the boxes
for {set row 0} {$row < $rows} {incr row} {
for {set col 0} {$col < $cols} {incr col} {
# calculate coordinates
set x1 [expr {$col * ($boxwidth + $padx) + $padx}]
set x2 [expr {$x1 + $boxwidth}]
set x3 [expr {$x1 + ($boxwidth / 2)}]
set y1 [expr {$row * ($boxheight + $pady) + $pady}]
set y2 [expr {$y1 + $boxheight}]
set y3 [expr {$y1 + ($boxheight / 2)}]
# choose color and text
set color [lindex $colors [expr {int(rand() * [llength $colors])}]]
#set text [lindex $labels [expr {int(rand() * [llength $labels])}]]
set text [lindex $deck [expr {int(rand() * [llength $deck])}]]
# create the boxes
set boxid [$canvas create rectangle $x1 $y1 $x2 $y2 -fill $color -outline black]
set textid [$canvas create text $x3 $y3 -text $text]
# remember which text item goes with which box and what the text says
set boxes($boxid) [list $textid $text]
set ids($textid) $boxid
set ids($boxid) $boxid
}
}
}
proc clearSelection {canvas} {
# if there is an existing currently selected box, change its border back to
# black; set variables selectedid and selectedtext to empty strings
variable selectedid
variable selectedtext
if {$selectedid ne "" && [$canvas find withtag $selectedid] ne ""} {
$canvas itemconfigure $selectedid -outline black
}
set selectedid ""
set selectedtext ""
}
proc handleSelection {canvas id} {
# determine the "next step" by comparing the newly selected box id and text
# to the box id and text of the previously selected box (contained in
# the variables $selectedid and $selectedtext)
variable ids
variable boxes
variable selectedid
variable selectedtext
set boxid $ids($id)
lassign $boxes($boxid) textid text
if {$boxid eq $selectedid} {
# user has selected the same box twice; deselect the box
clearSelection $canvas
return
} elseif {$text eq $selectedtext} {
# user has selected two boxes with the same text; delete both boxes
$canvas delete $boxid $textid $selectedid [lindex $boxes($selectedid) 0]
clearSelection $canvas
return
} else {
# user has selected a box when there is no selection, or user has
# selected a box with different text than the previously selected box;
# try to deselect the previous box, then select the new box
clearSelection $canvas
set selectedid $boxid
set selectedtext $text
$canvas itemconfigure $boxid -outline white
return
}
}
proc processClick {canvas x y} {
# determine whether the user has
# clicked on something; if so, call
# proc handleSelection
set id [$canvas find overlapping $x $y $x $y]
if {[llength $id] > 0} {
handleSelection $canvas [lindex $id 0]
}
}
set win [toplevel .demo]
wm title $win "Texas Hold Dem Cards"
set canvas [canvas $win.canvas]
pack $canvas -expand 1 -fill both
bind $canvas <Button-1> [list processClick %W %x %y]
set state 1
proc deal2 {} {
global selectedid selectedtext
global coloritem canvas details
set coloritem gray
# mahjongstyle { $state }
populateCanvas $canvas 7 5
set selectedid ""
set selectedtext ""
}
proc uncover {} {
global coloritem canvas details
global deal1 deal2 deal3 deal4 deal5 deal6 deal7
set state2 1
#$canvas create rectangle 10 10 500 300 -fill blue -outline red -tag deal1
if { $state2 == 5 } { $canvas raise deal1 ;}
if { $state2 == 1 } { $canvas lower deal1 ;}
}
proc flip_new_card {} {
global deck suit canvas x y
global selectedid selectedtext
global new_card_state
# determine whether the user has clicked on something;
# if so, flip to random new card
# set id [$canvas find overlapping $x $y $x $y]
set id ""
if {[llength $id] > 0} {
configure $id -text "switch"
}
}
proc mahjongstyle { state } {
global coloritem canvas details
set coloritem gray
set details {
# program Texas Hold Dem Cards.
# adapted from Mahjong_Style_Deletion
# written on Windows XP for TCL
# working under TCL version 8.6
# The original base M. was adapted
# from aricb on the Ask page.
# Probably could start a post,
# since it is a good baby game
# engine. Wish to study value and
# probability of Texas Hold Dem cards.
# Need to evaluate hands and bet on them.
# I added a few buttons at the bottom
# and tried to keep the clean code separate up top.
Mahjong-style deletion.
press in succession two tiles with the same text.
both tiles should be deleted.
The Mahjong-style deletion is for
the right mouse press.}
$canvas create window 100 200 -window [button $canvas.a -width 10 -text deal \
-bg $coloritem -command {deal2;}]
$canvas create window 100 250 -window [button $canvas.b -width 10 -text swap_card \
-bg $coloritem -command {swap_new_cards 2 ;}]
$canvas create window 200 200 -window [button $canvas.c -width 10 -text about \
-bg $coloritem -command {tk_messageBox -message $details}]
$canvas create window 200 250 -window [button $canvas.d -width 10 -height 1 -text report \
-bg $coloritem -command {puts "new_card_state equals $new_card_state"; console show }]
$canvas create window 300 200 -window [button $canvas.e -width 10 -text self_help \
-bg $coloritem -command {self_help}]
$canvas create window 300 250 -window [button $canvas.f -width 10 -height 1 -text exit \
-bg $coloritem -command {exit }]
$canvas create window 400 200 -window [button $canvas.g -width 10 -text uncover_3-5 \
-bg $coloritem -command {uncover}]
$canvas create window 400 250 -window [button $canvas.h -width 10 -height 1 -text uncover_6-7 \
-bg $coloritem -command {uncover }]
}
mahjongstyle { $state }
populateCanvas $canvas 7 5
set selectedid ""
set selectedtext ""
$canvas configure -background aquamarine4 -highlightcolor brown -relief raised -border 10
proc swap_new_cards { state } {
global new_card_state
set new_card_state 1
flip_new_card
return 1
}
proc moveobject {object x y} {
global deck suitfrenchblack suitfrenchblanc
global canvas
$canvas coords $object [expr $x-25] [expr $y-25]
set new_card [ lpick $deck ]
puts $new_card
$canvas itemconfigure $object -text $new_card -fill orange
}
# set boxid [$canvas create rectangle $x1 $y1 $x2 $y2 -fill $color -outline black]
set egg [$canvas create text 550 200 -text move_right_mouse_for_new_card -fill red ]
$canvas bind $egg <B3-Motion> {moveobject $egg %x %y}
console hide
console eval {wm title . "Texas Hold Dem Cards, screen grab and paste from console 2 to texteditor"}
console eval {.console config -bg palegreen}
console eval {.console config -font {fixed 20 bold}}
console eval {wm geometry . 40x20}
console eval {. configure -background orange -highlightcolor brown -relief raised -border 30}
puts " math = [ math::choose 52 2 ] "
$canvas configure -highlightcolor brown -relief raised -border 10
$canvas configure -width 700 -height 300
# This posting, screenshots, and TCL source code is
# copyrighted under the TCL/TK license terms.
# Editorial rights retained under the TCL/TK license terms
# and will be defended as necessary in court.
# end of file
# gold on TCL club, 5nov2018+----------------------------------------------------------------------------------+ | TEXAS HOLDEM: FOUR DEAL STAGES AND FOUR BETTING ROUNDS | | | | +----------+----------------+-------+------------------------------------------+| | | stage | name | cards | player options || | +----------+----------------+-------+------------------------------------------+| | | pre-flop | pocket / hole | 2 | call, raise, or fold (after pocket deal) || | | flop | community | 3 | check, raise, or fold (after 3 cards) || | | turn | community | 1 | check, raise, or fold (after 4th card) || | | river | community | 1 | check, raise, or fold (after 5th card) || | +----------+----------------+-------+------------------------------------------+| | | TOTAL | | 7 | 4 bets, 12 possible actions per game || | +----------+----------------+-------+------------------------------------------+| | | | Hand construction: | | Each player holds 2 pocket cards (private, face down) | | 5 community cards dealt face up in center of table | | Winner uses BEST 5-card hand from any combo of 7 cards | | | | Dealer chip: rotates around table each hand | | Big Blind: placed to the RIGHT of the dealer | | Small Blind: placed to the LEFT of the dealer | | (For 2-player games: blind rules differ) | | Final round: called "showdown" | | All suits are EQUAL (no suit beats another) | | No joker cards used | +----------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------+
| DECK STRUCTURE: 52 CARDS, FOUR SUITS (deal proc) |
| |
| French suits (unicode): |
| Black (filled): hearts \u2665 diamonds \u2666 clubs \u2663 spades \u2660 |
| White (outline): \u2664 \u2661 \u2662 \u2667 |
| |
| 13 ranks per suit: 2 3 4 5 6 7 8 9 10 A J Q K |
| 4 suits * 13 ranks = 52 cards total |
| |
| deal proc construction: |
| foreach suit { hearts diamonds clubs spades }: |
| foreach item { 2 3 4 5 6 7 8 9 10 A J Q K }: |
| kay = "[append item $suit $value]" |
| lappend deck $kay |
| |
| Card values assigned in deck: |
| +-------+-------+-----------+ |
| | rank | value | comment | |
| +-------+-------+-----------+ |
| | 2-9 | 1 | face value| |
| | 10 | 10 | face card | |
| | J | 10 | jack | |
| | Q | 10 | queen | |
| | K | 10 | king | |
| | A | 10 | ace | |
| +-------+-------+-----------+ |
| |
| Note: initially dealt card is NOT removed from the 52-card deck |
| (unlike Las Vegas tables; simplified implementation) |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| SAMPLE SPACE: COMBINATORICS FOUNDATION (math::choose from TCLLIB) |
| |
| Two-card pocket (pre-flop) sample space: |
| S = C(52,2) = 52! / (2! * 50!) = 1326 possible pocket hands |
| TCL: expr { [math::choose 52 2] } --> 1326 |
| |
| Five-card hand sample space: |
| S = C(52,5) = 52! / (5! * 47!) = 2598960 possible 5-card hands |
| TCL: expr { [math::choose 52 5] } --> 2598960 |
| |
| General combination formula: |
| C(n, k) = n! / (k! * (n-k)!) |
| TCLLIB: math::choose n k |
| (also written as "n choose k") |
| |
| Pocket pair breakdown: |
| Specific pair (e.g. two aces): C(4,2) = 6 ways |
| Any pocket pair: 13 ranks * C(4,2) = 13 * 6 = 78 hands |
| |
| Suited hand breakdown: |
| Specific suited combo (e.g. AK suited): C(4,1) = 4 ways |
| Any suited hand: 78 rank combos * 4 suits = 312 suited hands |
| |
| Reference: factorial and choose functions |
| Original factorial proc by Suchenwirth (RS), TCL wiki |
| TCLLIB math library also includes math::choose |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| TABLE 2: PROBABILITIES IN TEXAS HOLDEM (pocket hand odds) |
| |
| +--------------------------------+--------+--------+------------------------+ |
| | quantity | value | pct % | odds | |
| +--------------------------------+--------+--------+------------------------+ |
| | pocket sample space | 1326 | -- | -- | |
| | C(52,2) | | | | |
| | specific pocket pair | 0.00452| 0.452% | 220:1 | |
| | C(4,2) / C(52,2) = 6/1326 | | | | |
| | any pocket pair | 0.0588 | 5.88% | 16:1 | |
| | 78 / 1326 | | | | |
| | specific suited combo count | 4 | -- | -- | |
| | C(4,1) | | | | |
| | specific suited hand | 0.003 | 0.30% | 331:1 | |
| | 4 / 1326 | | | | |
| | any suited combo count | 312 | -- | -- | |
| | 4 * 78 | | | | |
| | any suited hand | 0.2352 | 23.52% | 3.25:1 | |
| | 312 / 1326 | | | | |
| +--------------------------------+--------+--------+------------------------+ |
| |
| TCL check examples: |
| expr { [math::choose 4 2] } --> 6 |
| expr { (1.*6) / [math::choose 52 2] } --> 0.004524... |
| expr { 78.0 / 1326 } --> 0.0588... |
| expr { 312.0 / 1326 } --> 0.2352... |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| TABLE 3: PROBABILITIES IN 5-CARD POKER |
| Sample space = C(52,5) = 2598960 possible 5-card hands |
| |
| +---------------------+---------------------------------+------+-------+-------+|
| | hand | choose formula | freq | prob | odds ||
| +---------------------+---------------------------------+------+-------+-------+|
| | royal flush | C(4,1) | 4 |1.54E-6|649739 ||
| | straight flush | C(10,1)*C(4,1) - C(4,1) | 36 |1.39E-5| 72192||
| | (less royal) | 10*4 - 4 = 36 | | | ||
| | four of a kind | C(13,1)*C(12,1)*C(4,1) | 624 |2.40E-4| 4164||
| | | 13*12*4 = 624 | | | ||
| | full house | C(13,1)*C(4,3)*C(12,2)* | 3744 |1.44E-3| 693||
| | | C(4,2) (note: page value 858 | | | ||
| | | may differ by formula variation) | | | ||
| | three of a kind | C(13,1)*C(4,3)*C(12,2)*C(4,1)^2 | 54912|2.11E-2| 46.3||
| +---------------------+---------------------------------+------+-------+-------+|
| |
| Straight flush TCL check: |
| set straight_flush [expr {(1.*36)/2598960}] --> 1.385E-5 |
| set sf_odds [expr {1./((1.*36)/2598960)}] --> 72192.0 |
| |
| Royal flush is subset of straight flush: |
| Only 4 royal flushes exist (one per suit) |
| Straight flush count excludes royal: 40 - 4 = 36 |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| CANVAS LAYOUT: GAME ENGINE GRID (populateCanvas proc) |
| 7 columns x 5 rows = 35 card boxes on canvas |
| Canvas width 700, height 300, background aquamarine4 |
| |
| Grid geometry: |
| boxwidth = 50 px, boxheight = 20 px |
| padx = 10 px, pady = 10 px |
| x1 = col*(50+10)+10, x2 = x1+50, x3 = x1+25 (center) |
| y1 = row*(20+10)+10, y2 = y1+20, y3 = y1+10 (center) |
| |
| Each cell: |
| rectangle (colored fill, black outline) |
| text overlaid at center (x3, y3) |
| text = lpick $deck (random card from 52-card deck list) |
| color = random from { red orange yellow green blue purple } |
| |
| +----+----+----+----+----+----+----+ |
| | c1 | c2 | c3 | c4 | c5 | c6 | c7 | row 0 |
| +----+----+----+----+----+----+----+ |
| | c1 | c2 | c3 | c4 | c5 | c6 | c7 | row 1 |
| +----+----+----+----+----+----+----+ |
| | c1 | c2 | c3 | c4 | c5 | c6 | c7 | row 2 |
| +----+----+----+----+----+----+----+ |
| | button area (deal, swap_card, about, report, self_help, exit ...) |
| | move_right_mouse_for_new_card (text item with B3-Motion binding) |
| +----+----+----+----+----+----+----+ |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+ | CARD INTERACTION: CLICK AND MAHJONG DELETION MECHANIC | | | | Left mouse click (Button-1) --> processClick proc | | | | | v | | canvas find overlapping x y x y (find item under cursor) | | | | | v | | handleSelection proc: | | | | +-- Case 1: same box clicked twice | | | --> clearSelection (deselect) | | | | | +-- Case 2: two different boxes, SAME text | | | --> delete BOTH boxes and their text items | | | --> clearSelection | | | (Mahjong deletion: matching cards removed) | | | | | +-- Case 3: no prior selection OR different text | | --> clearSelection (deselect old if any) | | --> set selectedid = new boxid | | --> set selectedtext = new text | | --> configure new box outline = white (highlight) | | | | Right mouse drag (B3-Motion on move_right_mouse_for_new_card text): | | moveobject proc --> lpick $deck --> shows new random card in orange | | puts new_card to console | +----------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------+
| LPICK AND DEAL: CORE UTILITY PROCS |
| |
| lpick (Suchenwirth / RS): |
| proc lpick L { lindex $L [expr {int(rand()*[llength $L])}] } |
| --> uniform random pick from list L |
| --> each card in deck has P = 1/52 chance per pick |
| |
| plainsub (utility): |
| proc plainsub {text item replacewith} { |
| string map [list $item $replacewith] $text } |
| |
| deal proc (builds deck list): |
| proc deal {args} { |
| foreach suit { \u2665 \u2666 \u2663 \u2660 } { |
| foreach item $args { |
| set value 1 |
| if item == J or Q or K or A: set value 10 |
| set kay "[append item $suit \ $value]" |
| lappend deck $kay } } |
| return $deck } |
| deal 2 3 4 5 6 7 8 9 10 A J Q K |
| |
| Resulting deck list: 52 items |
| "2 hearts 1" "3 hearts 1" ... "K spades 10" ... |
| puts "$deck new_card state equals $new_card_state" |
| --> printed to console on startup |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+ | BUTTON PANEL: GAME CONTROLS (mahjongstyle proc, canvas windows) | | | | Buttons embedded as canvas windows (canvas create window): | | | | +----------+-------------+----------------------------------------------+ | | | button | position | command | | | +----------+-------------+----------------------------------------------+ | | | deal | x=100 y=200 | deal2 --> populateCanvas 7 5 (shuffle all) | | | | swap_card| x=100 y=250 | swap_new_cards 2 --> flip_new_card | | | | about | x=200 y=200 | tk_messageBox -message $details | | | | report | x=200 y=250 | puts new_card_state ; console show | | | | self_help| x=300 y=200 | self_help --> tk_messageBox instructions | | | | exit | x=300 y=250 | exit | | | | uncover | x=400 y=200 | uncover --> raise/lower deal1 tag (flop) | | | | uncover | x=400 y=250 | uncover --> raise/lower deal1 tag (turn/river)| | | +----------+-------------+----------------------------------------------+ | | | | Special text item (right-mouse drag for new card): | | canvas create text 550 200 -text move_right_mouse_for_new_card -fill red | | bind B3-Motion --> moveobject --> lpick $deck | | | | deal2 proc also resets: | | selectedid = "" | | selectedtext = "" | +----------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------+ | TEXAS HOLDEM ODDS: OUTS AND QUICK PROBABILITY ESTIMATES | | "Outs" = number of unseen cards that improve your hand | | | | Quick estimate rules (not in page, but standard background context): | | After flop (2 cards to come): outs * 4 ~= percent chance | | After turn (1 card to come): outs * 2 ~= percent chance | | | | Probability that pocket pair becomes four of a kind: | | After pocket pair: 2 matching cards remain in 50 unseen cards | | P(hit on flop) = 2/50 + 2/49 + 2/48 ~= 0.117 (11.7%) | | | | Odds notation: | | +----------------------------+--------+----------------------------+ | | | event | odds | equivalent probability | | | +----------------------------+--------+----------------------------+ | | | specific pocket pair | 220:1 | 0.0045 (0.45%) | | | | any pocket pair | 16:1 | 0.0588 (5.88%) | | | | specific suited hand | 331:1 | 0.003 (0.30%) | | | | any suited hand | 3.25:1 | 0.235 (23.5%) | | | +----------------------------+--------+----------------------------+ | | | | Odds conversion: odds A:B --> P = B / (A+B) | | Example: 220:1 --> P = 1/221 = 0.004524... | | Inverse: P = 0.0588 --> odds = (1-P)/P = 0.9412/0.0588 ~= 16:1 | +----------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------+ | FIVE-CARD HAND RANKINGS (best to worst) | | | | +-----------+---------------------+------------------------------------------+ | | | rank | hand | example | | | +-----------+---------------------+------------------------------------------+ | | | 1 | Royal flush | A K Q J 10 (same suit) | | | | 2 | Straight flush | 9 8 7 6 5 (same suit) | | | | 3 | Four of a kind | K K K K 7 | | | | 4 | Full house | Q Q Q 5 5 | | | | 5 | Flush | A J 8 4 2 (same suit) | | | | 6 | Straight | 10 9 8 7 6 (any suits) | | | | 7 | Three of a kind | 7 7 7 K 2 | | | | 8 | Two pair | J J 4 4 9 | | | | 9 | One pair | A A 7 5 2 | | | | 10 | High card | A Q 9 5 2 (no combination) | | | +-----------+---------------------+------------------------------------------+ | | | | Winner in Texas Holdem: | | Best 5-card combination from any 2 pocket + 5 community cards | | All suits are equal (no suit beats another) | | In case of tie: pot is split equally | | | | Note: A can be used as high (above K) or low (below 2) in straights | +----------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------+
| GAME ENGINE: OVERALL PROGRAM FLOW (Texas Hold Dem Cards V2, gold Nov2018) |
| |
| package require Tk, math |
| namespace path {::tcl::mathop ::tcl::mathfunc} |
| global deck suit selectedid selectedtext new_card_state |
| | |
| v |
| Define utility procs: |
| lpick, plainsub, deal, self_help |
| populateCanvas, clearSelection, handleSelection |
| processClick, deal2, uncover, flip_new_card |
| mahjongstyle, swap_new_cards, moveobject |
| | |
| v |
| deal 2 3 4 5 6 7 8 9 10 A J Q K --> build $deck (52 items) |
| puts $deck to console |
| | |
| v |
| set win [toplevel .demo] |
| set canvas [canvas $win.canvas] |
| bind canvas Button-1 --> processClick |
| | |
| v |
| mahjongstyle $state --> embed 8 buttons as canvas windows |
| populateCanvas $canvas 7 5 --> draw 35 random card boxes |
| | |
| v |
| configure canvas: aquamarine4 bg, brown highlight, raised border 10 |
| configure console: palegreen bg, fixed 20 bold, orange border, 40x20 |
| puts " math = [math::choose 52 2] " --> 1326 to console on startup |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| PROBABILITY CONSOLE SESSION: CUT AND PASTE TCL EXAMPLES |
| All checkable in TCL console or google search engine |
| |
| Sample space for 5-card hand: |
| expr { [math::choose 52 5] } --> 2598960 |
| |
| Sample space for 2-card pocket: |
| expr { [math::choose 52 2] } --> 1326 |
| |
| Specific pocket pair probability: |
| expr { (1.*[math::choose 4 2])/[math::choose 52 2] } --> 0.004524886 |
| |
| Any pocket pair probability: |
| expr { 78./1326 } --> 0.0588... |
| |
| Any suited hand probability: |
| expr { 312./1326 } --> 0.2352... |
| |
| Straight flush probability: |
| set sf [expr { (1.*36)/2598960 }] --> 1.3861E-5 |
| set sf_odds [expr { 1./$sf }] --> 72192.0 |
| |
| Royal flush probability: |
| expr { (1.*4)/2598960 } --> 1.5390E-6 |
| |
| General utility from self_help button: |
| set answer [* 1. 2. 3. 4. 5.] --> 120 (5 factorial) |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+ | CARD STATE FLOW: DEAL, SWAP, AND REPORT | | | | Global state variables: | | deck = 52-item list (built by deal proc at startup) | | new_card_state = 0 (default) / 1 (swap mode active) | | selectedid = "" (no selection) / boxid of selected box | | selectedtext = "" (no selection) / text of selected box | | | | Button: deal | | deal2 --> populateCanvas 7 5 (full shuffle, 35 new random cards) | | resets selectedid and selectedtext to "" | | | | Button: swap_card | | swap_new_cards 2 --> new_card_state = 1 --> flip_new_card | | (flip_new_card currently stub; moveobject handles right-drag swap) | | | | Right-mouse drag (B3-Motion): | | moveobject --> $canvas coords object (follow mouse) | | new_card = lpick $deck --> random card from deck | | $canvas itemconfigure object -text new_card -fill orange | | puts new_card (to console) | | | | Button: report | | puts "new_card_state equals $new_card_state" | | console show (opens green console for copy/paste) | | | | Button: uncover_3-5 / uncover_6-7 | | canvas raise/lower deal1 tag (reveals/hides community cards) | +----------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------+ | MAHJONG DELETION ORIGIN AND POKER ADAPTATION | | | | Origin: Mahjong_Style_Deletion (baby game engine, aricb on Ask page) | | Adapted by gold Nov 2018 for Texas Hold Dem poker visualization | | | | Mahjong_Style_Deletion mechanic (preserved in poker version): | | Press in succession two tiles with the SAME text | | Both tiles should be deleted | | Right mouse press activates swap/replacement | | | | Poker adaptation differences: | | +----------------------------+------------------------------------------+ | | | original Mahjong | poker adaptation | | | +----------------------------+------------------------------------------+ | | | tile text = mahjong labels | tile text = playing card (lpick deck) | | | | fixed tile set | random card from 52-card deck per box | | | | delete matching pairs | same delete mechanic kept | | | | no suit concept | four French suits (unicode characters) | | | | no value concept | card values 1 or 10 added | | | +----------------------------+------------------------------------------+ | | | | Future extension noted: | | "Wish to study dealt values and probability of Texas Hold Dem cards" | | "Need to evaluate hands and bet on them" (planned but not implemented) | | Canvas widget: four deal stages can be raised/lowered with buttons | | and keyed canvas tags (uncover_3-5, uncover_6-7 buttons) | +----------------------------------------------------------------------------------+
Please place any comments here, Thanks.
gold 9/27/2021. Switched some comment signs ;# to #. This a big file. Check earlier editions, if not compatible. Maybe obvious, but this page was written on Windows10 Tcl ports including ActiveTCL. I assume that the reader can cut and paste on screen, what the reader needs, and tootle on to his own project and own contribution pages to the TCL Wiki.