/************************************************************************\ |* gtf is a framework for analyzing two-player zero-sum games *| |* Copyright (C) 2005 Troels Bjerre Sorensen *| |* *| |* This program is free software; you can redistribute it and/or modify *| |* it under the terms of the GNU General Public License as published by *| |* the Free Software Foundation; either version 2 of the License, or *| |* (at your option) any later version. *| |* *| |* This program is distributed in the hope that it will be useful, but *| |* WITHOUT ANY WARRANTY; without even the implied warranty of *| |* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *| |* General Public License for more details. *| |* *| |* You should have received a copy of the GNU General Public License *| |* along with this program; if not, write to the *| |* Free Software Foundation, Inc., 59 Temple Place - Suite 330, *| |* Boston, MA 02111-1307, USA. *| \************************************************************************/ package gtf.examples; import gtf.game.*; public class NolimitSingleCardPoker extends ExtensiveForm { int decksize, maxbet, ante; public String getName() { return "NLSCP."+decksize+"."+maxbet+"."+ante; } public NolimitSingleCardPoker(String decksize, String maxbet, String ante) { try { this.decksize = Integer.parseInt(decksize); this.maxbet = Integer.parseInt(maxbet); this.ante = Integer.parseInt(ante); } catch(NumberFormatException e) { System.err.println("usage: NolimitSingleCardPoker "); System.exit(1); } } public GameTree generateTree() { return new NolimitSingleCardDeal(); } private class NolimitSingleCardDeal extends RandomNode { public NolimitSingleCardDeal() { for(int p1card = 1; p1card <= decksize; p1card++) { for(int p2card = 1; p2card <= decksize; p2card++) { if(p1card != p2card) { addChild("card="+p1card, "card="+p2card, 1, new NolimitSingleCardAction(p1card, p2card, 1, 0, 0)); } } } } } private class NolimitSingleCardAction extends PlayerNode { public NolimitSingleCardAction(int p1card, int p2card, int player, int pot, int lastbet) { super(player); switch(player) { case 1: if(pot+lastbet == 0) { addChild(",check", ",p1 checks", new NolimitSingleCardAction(p1card, p2card, 2, 0, 0)); for(int bet = 1; bet+lastbet+pot <= maxbet; bet++) { addChild(",bet "+bet, ",p1 bets "+bet, new NolimitSingleCardAction(p1card, p2card, 2, pot+lastbet, bet)); } } else { addChild(",call", ",p1 calls", new GameLeaf(p1card > p2card ? pot+lastbet+ante : -(pot+lastbet+ante))); addChild(",fold", ",p1 folds", new GameLeaf(-(pot+ante))); for(int bet = 1; bet+lastbet+pot <= maxbet; bet++) { addChild(",raise "+bet, ",p1 raises "+bet, new NolimitSingleCardAction(p1card, p2card, 2, pot+lastbet, bet)); } } break; case 2: if(pot+lastbet == 0) { addChild(",p2 checks", ",check", new GameLeaf(p1card > p2card ? ante : -ante)); for(int bet = 1; bet+lastbet+pot <= maxbet; bet++) { addChild(",p2 bets "+bet, ",bet "+bet, new NolimitSingleCardAction(p1card, p2card, 1, pot+lastbet, bet)); } } else { addChild(",p2 calls", ",call", new GameLeaf(p1card > p2card ? pot+lastbet+ante : -(pot+lastbet+ante))); addChild(",p2 folds", ",fold", new GameLeaf(-(pot+ante))); for(int bet = 1; bet+lastbet+pot <= maxbet; bet++) { addChild(",p2 raises "+bet, ",raise "+bet, new NolimitSingleCardAction(p1card, p2card, 1, pot+lastbet, bet)); } } break; default: System.err.println("NolimitSingleCardPoker: invalid playernumber"); System.exit(1); break; } } } }