4 Copyright (c) 2010 Lode Vandevenne
7 This file is part of OOPoker.
9 OOPoker is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 OOPoker is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with OOPoker. If not, see <http://www.gnu.org/licenses/>.
23 #include "tools_terminal.h"
26 #include "io_terminal.h"
27 #include "pokermath.h"
33 Card
charsToCard(char c0
, char c1
)
35 if(c0
>= 'a' && c0
<= 'z') c0
+= ('A' - 'a');
36 if(c1
>= 'A' && c1
<= 'Z') c1
+= ('a' - 'A');
37 std::string c
; c
+= c0
; c
+= c1
;
42 Give it a string like AsTh and it returns ace of spades, ten of hearts in a vector
44 Cards are appended to the std::vector (it isn't cleared)
46 static void stringToCards(std::vector
<Card
>& cards
, const std::string
& s
)
48 for(size_t i
= 0; i
< s
.size() / 2; i
++)
50 cards
.push_back(charsToCard(s
[i
* 2 + 0], s
[i
* 2 + 1]));
55 String must have 4 chars.
58 static bool stringToHoleCards(Card
& card1
, Card
& card2
, const std::string
& s
)
60 if(s
.size() != 4) return false;
62 card1
= charsToCard(s
[0], s
[1]);
63 card2
= charsToCard(s
[2], s
[3]);
68 void runConsolePotEquityCalculator()
72 std::cout
<< std::endl
<< "Pot Equity Calculator" << std::endl
<< std::endl
;
73 std::cout
<< "values: 23456789TJQKA" << std::endl
;
74 std::cout
<< "suits: cdhs" << std::endl
;
76 std::cout
<< "enter num players (2-23): ";
78 int numPlayers
= strtoval
<int>(s
);
79 std::cout
<< std::endl
;
81 std::cout
<< "enter board cards (e.g. AsTh5h, or 'x' for none): ";
83 std::vector
<Card
> boardCards
;
84 stringToCards(boardCards
, s
);
85 std::cout
<< std::endl
;
87 std::cout
<< "enter hole cards (e.g. 5dTh): ";
89 std::vector
<Card
> holeCards
;
90 stringToCards(holeCards
, s
);
91 std::cout
<< std::endl
;
93 if(holeCards
.size() != 2)
95 std::cout
<< "please enter 4 characters, e.g. 5dTh for 5 of diamonds, ten of hearts." << std::endl
;
100 std::cout
<< "Pot Equity: " << getPotEquity(holeCards
, boardCards
, numPlayers
- 1) << std::endl
;
104 void runConsoleShowdownCalculator()
108 std::cout
<< std::endl
<< "Showdown Calculator" << std::endl
<< std::endl
;
109 std::cout
<< "values: 23456789TJQKA" << std::endl
;
110 std::cout
<< "suits: cdhs" << std::endl
;
112 std::cout
<< "enter num players (2-23): ";
114 int numPlayers
= strtoval
<int>(s
);
115 std::cout
<< std::endl
;
117 std::cout
<< "enter board cards (e.g. AsTh5h, or 'x' for none): ";
119 std::vector
<Card
> boardCards
;
120 stringToCards(boardCards
, s
);
121 std::cout
<< std::endl
;
123 std::vector
<Card
> holeCards1
, holeCards2
;
125 for(int i
= 0; i
< numPlayers
; i
++)
127 std::cout
<< "enter hole cards of player " << i
+ 1 << " (e.g. 5dTh): ";
129 std::cout
<< std::endl
;
131 if(!stringToHoleCards(c1
, c2
, s
))
133 std::cout
<< "please enter 4 characters, e.g. 5dTh for 5 of diamonds, ten of hearts." << std::endl
;
138 holeCards1
.push_back(c1
);
139 holeCards2
.push_back(c2
);
143 std::vector
<double> win
, tie
, lose
;
144 if(!getWinChanceWithKnownHands(win
, tie
, lose
, holeCards1
, holeCards2
, boardCards
))
146 std::cout
<< "invalid board cards were entered, no calculation could be done" << std::endl
;
150 std::cout
<< "Results: (chance to win, tie, lose)" << std::endl
;
151 for(int i
= 0; i
< numPlayers
; i
++)
153 std::cout
<< "Player " << i
+ 1 << " (" << holeCards1
[i
].getShortName() << " " << holeCards2
[i
].getShortName()
154 << "): " << win
[i
] << ", " << tie
[i
] << ", " << lose
[i
] << std::endl
;