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/>.
31 Player::Player(AI
* ai
, const std::string
& name
)
42 void Player::setCards(Card card1
, Card card2
)
48 std::string
Player::getName() const
53 std::string
Player::getAIName() const
55 return ai
->getAIName();
58 Action
Player::doTurn(const Info
& info
)
60 return ai
->doTurn(info
);
63 bool Player::isAllIn() const
65 return stack
<= 0 && wager
> 0;
68 bool Player::isOut() const
70 return stack
<= 0 && wager
<= 0;
73 bool Player::isFolded() const
78 bool Player::canDecide() const
80 return stack
> 0 && !folded
;
83 bool Player::isHuman() const
85 return dynamic_cast<AIHuman
*>(ai
) != 0;
88 void Player::onEvent(const Event
& event
)
95 static const int SC
= 17;
96 static std::string sc
[SC
] = { "b", "d", "f", "g", "h", "k", "j", "l", "m", "n", "p", "r", "s", "t", "v", "w", "ch" };
97 static const int MC
= 20;
98 static std::string mc
[MC
] = { "b", "d", "f", "g", "h", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w"
99 , "ch", "rl", "nh", "tt", "wr" };
100 static const int EC
= 12;
101 static std::string ec
[EC
] = { "f", "k", "l", "m", "n", "p", "r", "s", "t", "v", "nny", "try" };
102 static const int V
= 7;
103 static std::string v
[V
] = { "a", "e", "i", "o", "u", "oe", "ee" };
105 std::string
getRandomSyllable(bool begin
, bool end
)
111 a
= sc
[getRandom(0, SC
-1)];
112 b
= v
[getRandom(0, V
-1)];
116 a
= sc
[getRandom(0, SC
-1)];
117 b
= v
[getRandom(0, V
-1)];
121 a
= mc
[getRandom(0, MC
-1)];
122 b
= v
[getRandom(0, V
-1)];
123 if(getRandom() < 0.5) c
= ec
[getRandom(0, EC
-1)];
127 a
= mc
[getRandom(0, MC
-1)];
128 b
= v
[getRandom(0, V
-1)];
134 std::string
getRandomName(int numsyl
, bool capitalize
)
137 for(int i
= 0; i
< numsyl
; i
++)
139 result
+= getRandomSyllable(i
== 0, i
== numsyl
- 1);
142 if(capitalize
) result
[0] -= 'a' - 'A';
147 static std::string
getRandomNameImpl()
149 int r
= getRandom(0, 9);
151 if(r
< 1) numsyl
= 1;
152 else if(r
< 7) numsyl
= 2;
155 std::string result
= getRandomName(numsyl
, true);
157 /*if(getRandom() < 0.33)
160 result += 'A' + getRandom(0, 25);
167 std::set
<std::string
> usedNames
; //avoid duplicate names, it's quite important that players all have a different name, or AI's can't recognise the difference!
169 std::string
getRandomName()
173 std::string name
= getRandomNameImpl();
174 if(usedNames
.count(name
) == 0)
176 usedNames
.insert(name
);