[opentestbed] push by bluegaspode - PublicGameInfo.correctPlayerErrors was rewritten and commented.... on 2010-06-24 07:38 GMT

5 views
Skip to first unread message

opent...@googlecode.com

unread,
Jun 24, 2010, 3:38:54 AM6/24/10
to opent...@googlegroups.com
Revision: 9c89ea6695
Author: bluegaspode
Date: Thu Jun 24 00:38:31 2010
Log: PublicGameInfo.correctPlayerErrors was rewritten and commented.
Players can't call with an amount of 0 anymore to see a cheap showdown.

thank to BadBeatBot.
http://code.google.com/p/opentestbed/source/detail?r=9c89ea6695

Modified:
/junit/game/DealerTest.java
/junit/game/PublicGameInfoTest.java
/junit/game/playerTestLog_tiedPotUnevenMoney.txt
/src/game/PublicGameInfo.java

=======================================
--- /junit/game/DealerTest.java Sun Apr 4 12:38:32 2010
+++ /junit/game/DealerTest.java Thu Jun 24 00:38:31 2010
@@ -290,13 +290,13 @@

// we use one player at all seats
Player mockPlayer = new PrerecordedPlayerMock( //
- Action.raiseAction(0.02, 0.05), // player0: fold
+ Action.raiseAction(0.02, 0.05), // player0: raise
Action.callAction(0.06), // player1 (SB): call
Action.callAction(0.05), // player2 (BB): check
// -- flop --
Action.betAction(0.02), // player1: bet
Action.raiseAction(0.02, 9.69), // player2: raise (all-in)
- Action.foldAction(9.69), // player0: fold
+ Action.foldAction(9.71), // player0: fold
Action.callAction(9.69) // player1: call
);

=======================================
--- /junit/game/PublicGameInfoTest.java Sat Apr 17 03:12:27 2010
+++ /junit/game/PublicGameInfoTest.java Thu Jun 24 00:38:31 2010
@@ -208,9 +208,9 @@
gameInfo.setLimit(PublicGameInfo.NO_LIMIT);
gameInfo.setBlinds(5, 10);
gameInfo.setNumSeats(3);
- gameInfo.setPlayer(0, PublicPlayerInfo.create("player0", 100, null));
- gameInfo.setPlayer(1, PublicPlayerInfo.create("player1", 100, null));
- gameInfo.setPlayer(2, PublicPlayerInfo.create("player2", 100, null));
+ gameInfo.setPlayer(0, PublicPlayerInfo.create("player0", 200, null));
+ gameInfo.setPlayer(1, PublicPlayerInfo.create("player1", 200, null));
+ gameInfo.setPlayer(2, PublicPlayerInfo.create("player2", 200, null));
gameInfo.newHand(0, 1, 2);

gameInfo.update(Action.smallBlindAction(5), 1);
=======================================
--- /junit/game/playerTestLog_tiedPotUnevenMoney.txt Sun Apr 4 12:09:07
2010
+++ /junit/game/playerTestLog_tiedPotUnevenMoney.txt Thu Jun 24 00:38:31
2010
@@ -16,7 +16,7 @@
#gameStateChanged
#actionEvent 2 action:4 (toCall: 0.02, amount:9.69)
#gameStateChanged
-#actionEvent 0 action:0 (toCall: 9.69, amount:0.0)
+#actionEvent 0 action:0 (toCall: 9.71, amount:0.0)
#gameStateChanged
#actionEvent 1 action:2 (toCall: 9.69, amount:0.0)
#gameStateChanged
=======================================
--- /src/game/PublicGameInfo.java Mon Jun 7 13:32:52 2010
+++ /src/game/PublicGameInfo.java Thu Jun 24 00:38:31 2010
@@ -841,7 +841,7 @@

/**
* checks if the given action is appropriate.
- * if not (i.e. amounts to high compared to bankroll) it is adjusted to
the most similar valid action.<br>
+ * if not (i.e. amounts too high compared to bankroll) it is adjusted to
the most similar valid action.<br>
*
* This is needed because otherwise we get invalid states (like negative
bankrolls) - we also don't want
* to stop the simulation because of errors.
@@ -851,25 +851,79 @@
*/
private Action correctPlayerErrors(Action act, int s) {
PublicPlayerInfo player = getPlayer(s);
- if (act.isCall()) {
- if (act.getAmount() > player.getBankRoll()) {
- return Action.callAction(player.getBankRoll());
- }
- } else if (act.isRaise()) {
- if (Utils.roundToCents(act.getAmount() + act.getToCall()) >
player.getBankRoll()) {
+
+ switch (act.getType()) {
+
+ case Action.FOLD:
+ return Action.foldAction(affordableBet(getAmountToCall(s), player));
+ case Action.CHECK:
+ case Action.CALL:
+ if (getAmountToCall(s) <= 0.0) {
+ return Action.checkAction();
+ } else {
+ return Action.callAction(affordableBet(getAmountToCall(s), player));
+ }
+
+ case Action.BET:
+ case Action.RAISE:
+ if (getAmountToCall(s) <= 0.0) {
+ return Action.betAction(affordableBet(act.getAmount(), player));
+ } else {
+ // deal with anyone who is all in when trying to call
if (getAmountToCall(s) > player.getBankRoll()) {
return Action.callAction(player.getBankRoll());
- } else {
- double raise = Utils.roundToCents(player.getBankRoll() -
getAmountToCall(s));
+ }
+
+ // check we can afford to raise everything
+ if ((act.getAmount() + act.getToCall()) > player.getBankRoll()) {
+ Double raise = affordableBet((act.getAmount() + act.getToCall()),
player) - act.getToCall();
return Action.raiseAction(getAmountToCall(s), raise);
}
- }
- } else if (act.isBet() || act.isSmallBlind() || act.isBigBlind() ||
act.isBlind()) {
- if (act.getAmount() > player.getBankRoll()) {
- return new Action(act.getType(), 0, player.getBankRoll());
- }
- }
- return new Action(act.getType(), Utils.roundToCents(act.getToCall()),
Utils.roundToCents(act.getAmount()));
+
+ return Action.raiseAction(getAmountToCall(s), act.getAmount());
+ }
+
+ case Action.SMALL_BLIND:
+ return Action.smallBlindAction(affordableBet(act.getAmount(), player));
+
+ case Action.BIG_BLIND:
+ return Action.bigBlindAction(affordableBet(act.getAmount(), player));
+
+ case Action.POST_BLIND:
+ return Action.postBlindAction(affordableBet(act.getAmount(), player));
+
+ case Action.ALLIN_PASS:
+ return Action.allInPassAction();
+
+ case Action.MUCK:
+ return Action.muckAction();
+
+ case Action.POST_ANTE:
+ return Action.postAnte(affordableBet(act.getAmount(), player));
+
+ case Action.SIT_OUT:
+ return act;
+
+ case Action.POST_DEAD_BLIND:
+ return act;
+
+ }
+ return act;
+ }
+
+ /**
+ * Ensures that the player can afford to make the desired bet.
+ *
+ * @param bet
+ * @param player
+ * @return affordable bet
+ */
+ private double affordableBet(Double bet, PublicPlayerInfo player) {
+ if (bet <= player.getBankRoll()) {
+ return Utils.roundToCents(bet);
+ } else {
+ return Utils.roundToCents(player.getBankRoll());
+ }
}

//This method will split the pots up as necessary to the winner(s)

Felipe Kurkowski

unread,
Jun 30, 2010, 11:02:55 PM6/30/10
to opentestbed
Nice job on reconstructiong the method.
Anyway, there no test on the bet/raise action to check if the amount
is greater than the minimum (min raise).
I ran some tests and its in fact possible to raise less.
You should check out the patch I attached on Issue 24 to see how I
handled it on the previous version of the software.

On 24 jun, 00:38, opentest...@googlecode.com wrote:
> Revision: 9c89ea6695
> Author: bluegaspode
> Date: Thu Jun 24 00:38:31 2010
> Log: PublicGameInfo.correctPlayerErrors was rewritten and commented.
> Players can't call with an amount of 0 anymore to see a cheap showdown.
>
> thank to BadBeatBot.http://code.google.com/p/opentestbed/source/detail?r=9c89ea6695
Reply all
Reply to author
Forward
0 new messages