an environment to develop a 6-handed no limit …mdv/courses/cm30082/projects.bho/2008-9/harv… ·...

124
An Environment to Develop a 6-handed No Limit Texas Hold’em Poker Bot Daniel Harvey Bachelor of Science in Computer Science with Honours The University of Bath April 2009

Upload: hadan

Post on 02-Sep-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

An Environment to Develop a 6-handed No Limit Texas

Hold’em Poker Bot

Daniel Harvey

Bachelor of Science in Computer Science with HonoursThe University of Bath

April 2009

Page 2: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

This dissertation may be made available for consultation within the Uni-versity Library and may be photocopied or lent to other libraries for thepurposes of consultation.

Signed:

Page 3: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

An Environment to Develop a 6-handed No Limit

Texas Hold’em Poker Bot

Submitted by: Daniel Harvey

COPYRIGHT

Attention is drawn to the fact that copyright of this dissertation rests with its author. TheIntellectual Property Rights of the products produced as part of the project belong to theUniversity of Bath (see http://www.bath.ac.uk/ordinances/#intelprop).This copy of the dissertation has been supplied on condition that anyone who consults itis understood to recognise that its copyright rests with its author and that no quotationfrom the dissertation and no information derived from it may be published without theprior written consent of the author.

Declaration

This dissertation is submitted to the University of Bath in accordance with the requirementsof the degree of Batchelor of Science in the Department of Computer Science. No portion ofthe work in this dissertation has been submitted in support of an application for any otherdegree or qualification of this or any other university or institution of learning. Exceptwhere specifcally acknowledged, it is the work of the author.

Signed:

Page 4: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Acknowledgements

A thank you to Guy McCusker for supervising this project as he has provided support anddirection throughout. Also many thanks to Tom Little for providing part of the networkingcode, as noted in the code and thanks to everyone who helped in testing.

iii

Page 5: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Abstract

The main aim of this project is to provide a flexible environment for someone with limitedprogramming skills to develop a bot in today’s most popular variant and format of poker,6-max no limit texas hold’em. The environment should allow 6 players, humans or botsto compete in a game of no limit texas hold’em. The game should be playable across anetwork and should be useable as a framework to test a poker bot. The secondary aim isto provide a poker bot that can help others improve their play and to do this I will researchstrategy on poker.

Page 6: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Contents

1 Introduction 1

1.1 Game Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 Brief History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.3 Area of interest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.4 Project Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Literature Survey 5

2.1 Literature Survey Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.2 Fundamental Theorem of Poker . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.3 Sklansky Dollars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.4 Pot Odds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.5 Morton’s theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.6 G-Bucks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.7 Poker Literature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.8 Draws and Fold Equity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.9 Bluffing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.10 Position and Implied Odds . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2.11 Humans and Poker Bots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.12 Success of Poker Bots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2.13 Opponent Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2.14 Poker Software and tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

2.15 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

ii

Page 7: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CONTENTS iii

3 Requirements 20

3.1 Game requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.2 Networking Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3.3 Bot Development Requirements . . . . . . . . . . . . . . . . . . . . . . . . . 22

3.4 User Interface Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3.5 Non-Functional Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3.6 Requirement Gathering Review . . . . . . . . . . . . . . . . . . . . . . . . . 23

4 Design 24

4.1 Class Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4.2 Class Interactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

4.3 Game Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

4.4 Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

4.5 Developing a flexible Environment . . . . . . . . . . . . . . . . . . . . . . . 31

4.6 Bot Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

4.7 Developing an un-exploitable bot . . . . . . . . . . . . . . . . . . . . . . . . 32

4.8 Pre-flop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

4.9 Flop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

4.10 Graphical User Interface Design . . . . . . . . . . . . . . . . . . . . . . . . . 33

5 Implementation and Testing 35

5.1 Code Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

5.2 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

5.3 Questionnaire . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

6 Results 41

7 Conclusion 46

7.1 Achievements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

7.2 Project Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

7.3 Further Enhancements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

7.4 Final Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

Page 8: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CONTENTS iv

8 User Documentation 50

9 User Feedback Results 52

10 Code 61

10.1 File: Bot.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

10.2 File: CallBot.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

10.3 File: Card.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

10.4 File: Client.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

10.5 File: DansBot.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

10.6 File: Game.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

10.7 File: GUI.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

10.8 File: GUIConnection.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

10.9 File: Human.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

10.10File: Player.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

10.11File: Server.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

10.12File: ThreadClass.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

10.13File: User.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

Page 9: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 1

Introduction

The project will run along my interest of the card game texas hold’em. Texas hold’emis currently the most popular variant of poker. It is normally played between 2 and 10players and in today’s game no limit is the most popular, specificially games supportingup to 6 players known as 6-max. Real-time statistical breakdowns of the popularity of thedifferent variants and formats can be seen by poker listings which record literally millionsof hands each day (www.PokerListings.com, 2008). This also shows just how popular thegame currently is. The rules of the game are stated below for convenience to the reader.

1.1 Game Rules

”A white disk called the dealer button moves around the table in a clockwise direction aftereach hand and signifies the player who acts last on all rounds after the first. The player tothe left of the dealer posts the small blind and the player to the left of that posts the big blind.These are forced bets which encourage the players to bet (much like antes in other poker vari-ants). After the blinds are posted, each player is dealt two hole-cards and the game begins.The first round of betting occurs, starting with the player to the left of the big blind. Eachplayer can choose to call the amount of the big blind, raise a particular amount, or fold.The betting round ends when all players have called the latest raise or folded. The initialcommunity cards are then dealt. Three cards are dealt face up in the center of the table,called the flop. A second round of betting occurs, always starting with the player to the leftof the dealer. The next community card, called the turn, is dealt followed by a third roundof betting. The last community card, called the river, is dealt with a final round of betting.Those remaining in the hand reveal their hole cards and the winner is the player holdingthe best five-card poker hand.” (Kan, 2007)

1

Page 10: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 1. INTRODUCTION 2

1.2 Brief History

There are different formats of texas hold’em, which is limit, pot limit and no limit. Inlimit your raise is capped to the size of the small blind but on the turn and river it iscapped to the size of the big blind and the number of times the pot can be raised in around of betting is capped. In pot limit you are allowed to raise up to the size of the pot.In no limit there is no cap and you can make a raise for the rest of your stack. Thereare many different variations of poker and the world has seen numerous changes both inpopularity and how poker is played. For about 40 years 7-card stud was the most popularbut in the seventies (www.Poker.com, 2008) texas hold’em rose in popularity and sincethen the focus has shifted from limit texas hold’em to no-limit texas hold’em. There isspeculation that pot limit omaha will be the game of the future but today the focus is verymuch on no limit texas hold’em which I will now refer to as no limit hold’em. No limithold’em is played with anything between 2 to 10 players. The internet hosts the majorityof today’s games and online tables normally allow up to 2, 4, 6, 9 or 10 players. As wellas a shift from limit to no limit there has also been a shift in popularity from 9 handed to6 handed. Currently 6 handed games dominate the field and there are a huge number ofplayers trying to improve their play for 6 handed no limit texas hold’em, this can be seenfrom Poker Listings, which store and analyze literally millions of hand histories each day.(www.PokerListings.com, 2008)

1.3 Area of interest

The rise of interest in poker as shown by the rise of entrants to the World Series of Poker(Wikipedia, 2008b) has been mirrored in the games that take place online. This has un-doubtedbly led to a rise of interest on producing software to play poker and to improveyour own play. These bits of software that try and play poker are known as poker bots,where ’bots’ is short for robots. To play both limit and no limit hold’em it requires a set ofskills, experience and a level emotional state in order to beat the average player today. It isa fact that limit hold’em bots have been more successful than no limit hold’em bots. Thisis likely due to the fact no limit adds an additional factor of being able to size your bet.Naturally humans are good at identifying patterns and this is an important skill that isnot easy to teach a poker bot and one that is important. Humans also have the capabilityto try and think what their opponents may be thinking and can analyse his or her state ofmind. This is useful information which should be used additionally to the information fromthe game. With the additional factor of bet sizing it adds additional psychological factorsand different bet sizes can mean different things from different players with different boardtextures. Therefore I believe no limit is a game that is complex to model. Currently pokerprofessionals are beating the best no limit poker bots. One of the best no limit bots isPolaris from the University of Alberta (University of Alberta, 2008). Although this bot canplay no limit hold’em it hasn’t had the same success as it has done in limit. Additionallythe bot can only play against one person or at least is not programmed specifically to play

Page 11: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 1. INTRODUCTION 3

multiple players.

The software ’poker academy’ (Poker-Academy, 2008) from the University of Alberta isstated to be the best training software available and it appeared to me the bots play poorlyin 6 handed no-limit hold’em. I trailed the software and realised the bots had no conceptof pot to stack ratio and therefore it appeared that it could not handle basic decisions.Additionally this software provides only a tool to play against a set list of poker bots andthere is no way to build your own.

1.4 Project Outline

The aim for this project is to provide a flexible environment for someone with limitedprogramming skills to develop a bot in today’s most popular variant and format of poker,6-max no limit texas hold’em. The project will involve developing an environment forplayers to play 6 handed no limit texas against other players. For this to work appropriatelyit will be important to provide a networked solution as it is very difficult to play pokeron one computer as hole cards need to be private to each player. Therefore developing anetworked solution of the game will be important. Effort will be focussed on making it assimple as possible for a bot to join the game and will look to provide a template to makeit as simple as possible for others to write a bot that works with the system.

Additionally we wish to develop a poker bot that can play well and help others improvetheir play. Ideally the bot would process large amounts of information, identify patternsand collect known data from players i.e. betting frequencies, chance to fold to a bet andmany other stats. This will help the bot assign a range of hands preflop and allow it toplay against each player differently. The bot should improve as more information becomesavailable.

Due to the time frame of this project I believe to implement everything it will be ambitiousso I wish to split the project down into different versions that I can stop off at.

Version 1

Implement the game of no limit texas hold’em so that it can be played between 6 playerson the same computer. I shall start of by writing a player class and a game class so thatit can later be split over a network.

Version 2

Allow players to be able to play over the network and therefore each use a different PC toplay. Implement a server-client approach to communicating. All actions from a player willbe sent to the server and then if an action is accepted it will be echoed but to all playersinforming them of a particular players actions.

Version 3

Provide a flexible environment for bot development and write a template for a bot class

Page 12: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 1. INTRODUCTION 4

allowing others to write their own. Introduce a simple bot that can play against 5 otherplayers.

Version 4

Expand the bot so that it uses information from players and has an awareness of position.

Version 5

Expand the bot further so that it assigns hand ranges to each player and is able to calculateits relative hand strength from this. Additionally it should be able to respond differentlyto different bet sizes and different board textures. It should build up a library on eachplayer’s tendencies and record stats on each player that can be used to its advantage.

Figure 1.1: Gantt Chart

Page 13: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 2

Literature Survey

2.1 Literature Survey Outline

It is the aim of this literature review to understand what the goal is for a long term winningpoker player and the fundamentals behind the game. It is also my goal to understand whatare the concepts a poker bot will need to apply and how do they relate to the long termgoal of the poker player. We then need to consider how we apply this information to pokerbots and what work has been done in this area and what their areas of focus are.

I wish to consider limit, pot limit and no limit in my review but to focus on no limitwhen considering concepts and decisions. The focus will be on 6-max no limit cash gamesalthough I will review other formats in my survey and in my reading.

2.2 Fundamental Theorem of Poker

David Sklansky who is a professional poker player and author has acquired 3 bracelets andis a figure head within the poker community. The fundamental theorem of poker writtenin full below was first articulated by David Sklansky.

”Every time you play a hand differently from the way you would have played it if you couldsee all your opponents’ cards, they gain; and every time you play your hand the same wayyou would have played it if you could see all their cards, they lose. Conversely, every timeopponents play their hands differently from the way they would have if they could see allyour cards, you gain; and every time they play their hands the same way they would haveplayed if they could see all your cards, you lose.” (Sklansky, 1999)

In poker we are trying to make plays that give us a positive expectation in terms of our winrate. If we can make a play that is a winning play we gain. In poker we see that makingthe winning play does not always mean we will win the hand. Instead we make plays thatwill give us expected gains so that we can maximize our chance of winning in the long run.

5

Page 14: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 6

2.3 Sklansky Dollars

The example below demonstrates how we gain from our opponent making a mistake andhow we should review the situation without being results orientated whether we win orlose.

Example 1:

The flop is: 5 8 2We are dealt JJ and make a typical raise; it is folded to the button thatcalls with 67

The flop is: 5 8 2

If we were to bet all in and get called, we would have 63 percent chance of winning. Thebutton has a straight draw which will win if he hits a 4, 9 or the different combinationsof making two pair, trips and a straight with a 3 and a 4, known as a back door straight.Therefore if we were to bet all in and get called by our opponent, we would gain as shownby the fundamental theorem of poker. We are gaining because he is playing differently tohow he would have played if he knew our hand. Although it is unlikely he would call inthis situation he may so happen to think we have a draw and put us on a holding of 34,which he has 68 percent against. Although if he turns a 4 we lose the hand we still gain,but we gain because we made a play that would on average make a profit. It is from thefundamental theorem of poker that Sklansky dollars arose. Sklansky dollars are our expectedgain in dollars (or our expect gain in the currency we are using) in this example if the potwas 200, we would on average win a pot of 132 (200 * 0.66 = 132). Although the amountwe win on average is 132 we are interested in our EV (Expected Value) which is 132 minuswhat we contributed to the pot. The amount of chips we gained from this hand on averageis our expected value from this hand or therefore our Sklansky dollars.

Phil Galfond wrote:

”if you get all in pre-flop with A-A versus J-J for 10k and you lose, you lost 10k in realdollars; however you won about 6k in Sklansky Dollars because you should win that hand80 percent of the time” (Galfond, 2007)

It is therefore a goal of a poker player to make Sklansky dollars and the focus should beon the long term. In the above example there is another factor for the button to considerbefore folding his straight draw which is his pot odds. If he has correct odds a call becomescorrect.

2.4 Pot Odds

In poker when we have the 2nd best hand it can be correct to call because of pots odds.

”In poker, pot odds are the ratio of the current size of the pot to the cost of a contemplatedcall. In other words, if the pot contains 100, and a player must call 10 to stay in thehand, then the player has 100-to-10, or 10-to-1 (commonly expressed as 10:1), pot odds.”

Page 15: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 7

(Wikipedia, 2008a)

Let’s expand example 1 to show the bet amounts.

Example 2:

The flop is: 5 8 2In a game where the small blind is 1 and the big blind is 2, where both ourstacks are 50 and We are dealt JJ and make a typical raise to 8; it is folded to the buttonthat calls with 67 suited.

The flop is: 5 8 2

We go all in and on the flop the pot is 19 and it will be 42 for the button to call to win 61.This means the button needs to win at least 40.8 percent of the time ((42/ (61+42)) * 100= 40.8) to call. The fact 19 is already in the pot means he can call with a worse hand andin poker we need to consider what odds the pot is offering us on a call. Against our pocketjacks the button has 34 percent chance to win, which isn’t enough to call. If our stacks werehalved to 25, it would be 17 to call, and the button would need to win 32 percent of the timeand against our exact holding it would be correct to call.

In the situation where both of our stacks are 25, we cannot make the button make a mistakeby calling on the flop, but this doesn’t matter as we made him already make a mistake bycalling pre-flop. When he flops a straight draw he is going to only just have the odds tocall, but there are going to be a lot of bad flops for his hand, consider the flop 9d 6h Ks, thebutton has only 21 percent chance of winning, and when he completely misses on a 9d 6h2c he has 5 percent chance of winning. This also shows when the stack to raise size ratiois small, it is unprofitable to play hands like 67 suited as the implied odds are cut downwith shallow stacks and hands such as these rely on implied odds. This means players canmake decisions that will be +EV in the hand but still not make Sklansky dollars from thehand because of a bad decision made earlier in the hand this is illustrated by example 3 thatshows how calling can be the best play even when you have the worst hand.

Example 3

From player 1’s perspective, he has to call 100 to win on average 120 (300 * 0.4). Meaningif player 1 calls he will make 20 on this decision, despite the whole situation being a losingsituation. The fact is he has invested 150 and will only win 120 on average. But If player1 folds to the 100 bet he will lose the 50 invested, so by calling he loses only 30 overallinstead of 50. So therefore player 1 should call. Assuming the hand goes to showdown eachtime, player 2 makes 10 on the turn and 30 on the river on average. But player 2 makesthe most when player 1 folds on the turn, which is a net profit of 50. This shows sometimesit is fine to fold out worse hands. Normally the equity is not so close, and if you have theplayer drawing thin you want them to call. Although this applies to cash games, where theblinds are fixed, in a tournament it is best to avoid putting all your chips in the middle astypically your cannot re-buy. Let’s assume on the river (the final card) the best hand willnot be bluffed out the pot. Meaning the best hand will always win once the river is dealt.If player 1 has 40 percent chance to win the pot with 1 more card still to come and player2 has 60 percent chance to win the pot. If the pot is 100 and both players check the turn,

Page 16: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 8

player 2 will on average win 60. As both players put equal amount in the pot he has madea net profit of 10. Instead if player 2 makes a bet of 100 on the turn and player 1 calls thepot would be 300. Player 2 would make a net profit of 30 ((300 * 0.6) - 150)). This show’smaking a bet with the best hand is profitable if we know we won’t get bluffed of our hand.

From player 1’s perspective, he has to call 100 to win on average 120 (300 * 0.4). Meaningif player 1 calls he will make 20 on this decision, despite the whole situation being a losingsituation. The fact is he has invested 150 and will only win 120 on average. But If player1 folds to the 100 bet he will lose the 50 invested, so by calling he loses only 30 overallinstead of 50. So therefore player 1 should call. Assuming the hand goes to showdown eachtime, player 2 makes 10 on the turn and 30 on the river on average. But player 2 makesthe most when player 1 folds on the turn, which is a net profit of 50. This shows sometimesit is fine to fold out worse hands. Normally the equity is not so close, and if you have theplayer drawing thin you want them to call. Although this applies to cash games, where theblinds are fixed, in a tournament it is best to avoid putting all your chips in the middle astypically your cannot re-buy.

In example 3 our EV is maximized when our opponent makes the wrong decision but inmulti-way pots our EV can be maximized when our opponents make the correct decision asshown by Morton’s theorem.

2.5 Morton’s theorem

Morton’s theorem is articulated by Andy Morton. It states that in multi-way pots, a player’sexpectation may be maximized by an opponent making a correct decision.

”The most common application of Morton’s Theorem occurs when one player holds the besthand, but there are two or more opponents on draws. In this case, the player with the besthand might make more money in the long run when an opponent folds to a bet, even if thatopponent is folding correctly and would be making a personal mistake to call a bet. Thistype of situation is sometimes referred to as implicit collusion”

This is a contrast to the fundamental theorem of poker and we actually see the fundamentaltheorem of poker always applies in a heads up pot but not always in a multi-way pot.

2.6 G-Bucks

Although reviewing a situation by looking at the Sklansky dollars gained or lost is useful itdoes not paint the complete picture. In fact we need to consider ranges to be more accuratein our analysis.

Our range is a combination of all the hands we could have that would have played the sameway as our actual hand. When looking at a hand that we lost we should consider what ourrange is. If our range gives a positive expectation in value but our specific hand this time

Page 17: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 9

round doesn’t it is still a winning play overall. We cannot simply say we made negativeSklansky dollars on this hand therefore we made a mistake. If we have a range and thebottom of our range yields a negative expectation but the rest of our range yields a positiveexpectation we need to weight our range and sum each expectation to calculate whetheroverall our play in this situation is a winning play.

Phil Galfond tied in the concept of introducing our range into Sklansky dollars by introducingGalfond Dollars.

”The way that Galfond Dollars work is similar to the way Sklansky Dollars work. However,instead of taking your hand and seeing how it does against your opponent’s hand, you takethe entire range of your hand and see how it does against his hand.” (Galfond, 2007)

G-Bucks involves weighting the likelihood of having a particular hand by calculating thenumber of combinations to have a particular hand, e.g. if we have AA or AK in our range,there are more possibilities we can be dealt AK and therefore AK should be weighted heavier.G-Buck helps us more accurately review a situation in terms of our expectation. The flawwith Sklansky dollars is if we have the bottom of our range we may think a particularplay on our part is unprofitable but this may not be the case. Going from the conceptof Sklansky dollars to G-Bucks is just one example of how the game is evolving in termsof people understanding its complexity. Phil Galfond writes an article on this and statesit would be more accurate to compare our range vs. his range but this gets complicated.This is complicated because our opponents range isn’t known whereas our range is from ourperspective although we can estimate our opponents range.

2.7 Poker Literature

The main writers in poker are David Sklansky, Ed Miller and Dan Harrington. DavidSklansky and Ed Miller wrote a book together; No Limit Hold’em Theory and Practice.David Sklansky wrote an earlier book; The Theory of Poker, which included the fundamentaltheorem of poker. Dan Harrington has written many books which consist of; Harrington onHold’em and Harrington on Cash Games. Another big hit was the book; Doyle Brunson’sSuper System: A Course in Power Poker by Doyle Brunson. Although more recently themost successful tournament and cash players in today’s games have decided to release theirown books. This includes players such as Daniel Negreanu and Phil Hellmuth who havewon 4 and 11 bracelets at the World Series of Poker respectively. Today the knowledge ofpoker is very widespread and there are many training sites which can hugely improve yourknowledge. These allow you to watch videos of poker professionals playing and they giverunning commentary on their thoughts and stop to explain concepts for a relatively low cost.This has increased the competition of the game and this means you can no longer read abook and become a winner, it now takes constant working on your game to plug your leaksand more focus on trying to play you’re A game for as long as possible.

There are now a lot more books being published around the subject of playing you’re Agame and handling downswings as the knowledge between players narrow, a recent book on

Page 18: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 10

this topic is ’The Elements of Poker’ (Angelo, 2007). Although there is a lot of advice forplayers, once a player has mastered the game so that he can beat the mid stakes typicallythought of as 200NL to 1000NL. There is still more to learn and another set of skills tomaster and recently a successful high stakes cash game poker player Cole South (known asCTS) released a book costing 1850 dollars which is aimed at the players playing the midstakes. Many believe the price to not be higher enough as it gives away secrets to pushingfrom the mid stakes into the higher stakes. Almost every poker book will address the keyconcepts such as position, pot odds, fold equity and bluffing. We see from looking at theseconcepts that they tie closely together and concentrate on one thing maximizing your EV.Poker is all about making +EV plays by considering ranges and putting people on rangesbefore the flop and narrowing this range on each street and acting in a way that will yieldthe most EV. David Sklansky once wrote in his book:

”New players (and non-players) seem to think the game centers around two things; being agood liar and being keenly aware of tells.” (Sklansky and Miller, 2007)

It is common for new players to focus on the wrong skills early on, but there are manybooks out there to learn from. David Sklansky and Ed Miller point out some of the mostimportant skills to no limit, in their book No Limit Hold’em - Theory and practice (Sklanskyand Miller, 2007)

• Manipulating the pot size

• Adjusting correctly to stack sizes

• Winning the battle of mistakes

• Reading hands

• Manipulating opponents into playing badly

All these concepts come down to maximizing our EV and the concepts below help us thinkabout our equity and how our hands compare pre-flop and post flop and how we can playdraws profitably.

2.8 Draws and Fold Equity

In ever poker pot were in we have equity. If we have a 20 percent chance to win and thepot is 100, we have 20 equity (100 * 0.2). We also have fold equity which is created by usmaking a bet. If we bet and our opponent folds 25 percent of the time and the pot is 100, wehave 25 fold equity (100 * 0.25). Fold equity helps us play draws profitably, if nobody foldedany made hand are draws would typically have 30 percent to win at showdown. Sometimesa player bets small enough for a call to be clearly correct when we are on a draw. In practicea raise may still be better; this is because if we hit our draw it means it is normally betterdisguised, allowing us to get action when we hit. If a player bets small sometimes it may

Page 19: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 11

indicate weakness and we know if we raise now and show strength we can represent a betterhand and blow him off his hand later. Therefore if we raise early we can bet when thedraw hits and on other turn cards which we believe hit our range in our opponent’s eyes.Therefore draws are normally played aggressively as we are trying to create fold equity tomake it a winning play. In the case we are on a draw and the player bets of the pot, if wecall we are relying on our implied odds when we hit our draw and or the player giving upon the hand and letting us take it away later. Sometimes we don’t have the right odds tocall but with a raise we can make it the correct play when our fold equity is high enough.In example 1 above when we went all in we cut our opponent’s fold equity to 0.

2.9 Bluffing

Firstly we bluff to make a better hand fold by betting or raising. When we bet we almostalways have fold equity even if we don’t want it. When we bluff we want to maximize ourfold equity as with a stone cold bluff we typically have close to zero equity, therefore areonly chance at winning the hand is to create fold equity because we lack actual equity fromour hand.

”A bluff involves two components: having a hand (or range of hands) in mind that youropponent might have, and betting enough to get your opponent to fold those hands. Youdon’t bluff to get your opponent to fold. You bluff to get your opponent to fold if she has aspecific hand (or a specific range of hands).” (Sklansky and Miller, 2007)

An example of when to bluff is if you raise in the cut off and the big blind calls. If heis a TAG (tight-aggressive) player than we know he would often 3-bet AK, AQ, big pairsand some other hands a small frequency, therefore when he calls he likely has a hand likeAJ, A10s, KQ more so than AK and normally a lot of low to mid pocket pairs and afew other hands i.e. J10 suited. When the flop comes Q47r (r meaning rainbow i.e. alldifferent suits) we would almost always bet this flop as it misses his range, and our rangeis still undefined as we were not given the chance to re-raise and we are not in the blinds.Therefore when he calls our bet on the flop, and a king or an ace comes we can representthis card a lot easier than he can. This card is typically a good bluffing card also known asa scare card for our opponent. If an ace comes, there are very few hands he can have thatcontain an ace. Considering he is a TAG it is unlikely he calls the flop with just an overcard therefore the only real hand he can have is AQ which is thinly weighted as it 3-betsus pre-flop. The other possibility which is unlikely is he could have a set. This is a smallrange of hands that will continue although in reality he may call with a queen because hemay know we bluff this scare card too often. Whereas in this situation we can potentiallyhave A9 to AK and our range isn’t weighted heavily towards pocket pairs like his is. Handslike AJ are very unlikely to be in his range because many people do not call a flop bet withjust an over card, especially a TAG opponent. Whereas we are betting this flop with ourwhole range because the flop misses his range and therefore our range on the turn includeshands such as AJ.

Page 20: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 12

Therefore in the same way we calculate our expected gain in situations by looking at rangesand not just a specific hand we need to apply our thoughts in how we play to looking atranges and not just single cards as well. We should realize as we progress further into ahand his range narrows and never widens. This can help us pick off bluffs for example whenplayers try to represent a hand on the river that was not in their range given their actionon the flop. Sometimes we estimate people’s ranges incorrectly but this is a skill that isacquired from experience.

2.10 Position and Implied Odds

Poker is a game of incomplete information and when we are last to act in a hand we havethe most information available to us as we have position. Therefore having position isvery important and this massively dictates the hands we play pre-flop. When we are UTG(Under The Gun) i.e. first to act pre-flop we know if we decide to play this hand we willbe out of position the whole hand from everyone outside the blinds. When we are on thebutton we will always have a positional advantage. This leads to the fact we should play atighter range UTG than on the button. We can use this knowledge to our advantage and3-bet someone who is on the button a lot more because we know his range is wider. In pokerwe need to balance card advantage, positional advantage and skill advantage and if we lackone of these we need a better advantage in the others (Talked about by Baluga Whale ina Deuces Cracked training video, where he talks about card advantage, skill advantage andpositional advantage) (Deuces-Cracked, 2008)

In poker sometimes we do not have pot odds but we can have implied odds. In the case wehave 66 and we know our opponent has AA; we may call without pot odds but if we areable to escape the hand when we don’t hit a 6 and get the money in when we do hit a 6 wehad implied odds. Pairs and suited connectors have large implied odds, but the implied oddvaries based on the type of players in the hand. The reverse is also true, which is knownas reversed implied odds. When we have AA we may have reversed implied odds, but weare not normally aware of it. We can reduce someone’s implied odds when we hold AA byraising bets pre-flop, as well as folding when they make their hand post flop. Although bygetting enough of your stack in pre-flop you will have cut their implied odds massively. Amore obvious example of reversed implied odds is when someone UTG raises, and you holdA10 in a 6 player game. In this situation you are dominated by a large proportion of hisrange, which typically consists of AJ, AQ, AK and AA. If we know his range consists ofno lesser aces than what you hold if we call and hit an ace we are setting ourselves up losea potentially large amount, unless we hit a 10 or he is running a bluff. If we pair our ace,we will likely win a small pot when he holds a worse pair. Therefore we will generally be ina scenario to win a small pot or lose a big pot.

Therefore it is more common to call an early raise with a hand with big implied odds ratherthan calling a button raise when in the blinds. In the blinds we are always out of positionand if we play a hand to win a big pot and lose a small pot we want our opponents range to

Page 21: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 13

be tight to make it ever more likely he will put his whole stack in i.e. maximize our impliedodds. Therefore as the buttons range is typically quite wide a 3-bet from the blinds is oftenbetter, but typically 3-betting small pocket pair’s blind VS button is player dependant.

2.11 Humans and Poker Bots

Poker bots have some natural advantages over humans. One is they do not have emotionsand this is a huge advantage and there have been many books written to help players conquerthis side of poker. Another advantage for a poker bot is being able to process large amountsof information and gather accurate results statistically.

A natural advantage for a human player is being able to weight situations based on anotherperson state of mind. Knowing if a player is on tilt may be hard for a bot to detect. Alsoknowledge can change fast and this proves problematic in bots. Advanced players may usebetting patterns or known facts to trick another player. An example is betting small toinduce a bluff, as generally bad players bet small with a weak hand. Another is in a headsup match, good players like to bluff with their first 3-bet as it commonly gets a lot of respectthe first time. This dynamic can become more complicated amongst players who know thisand know each other know this, therefore the mind games in poker can be hard to program.Therefore many bots choose to play in a style that is attended to be un-exploitable althoughthe best style is often to play an exploitable style to exploit your opponent. An example isbetting smaller on a rainbow dry flop, e.g. K27r. Not many hands hit this flop so if youare able to make a smaller continuation bet on this flop, and have it have the same affect,you should do this. If you opponent never adapts and you are able to bet a lot smaller withgetting the same amount of fold equity, you are playing in a way that can be exploited butit is the better play.

Humans have intuition; this is something that a poker bot will lack. We see that a poker botneeds a large number of observations to make conclusions and this is going to be a limitingfactor against a human player with good intuition.

”After a small number of observations, humans form elaborate theories about an opponent,based mostly on intuition and past experience. If a theory holds in future observations,it becomes integrated and used in future betting decisions. A human may even alter theirplay in order to test a theory. In contract, machine learning methods typically need a largenumber of observations, and build a model from statistical inferencing. These statisticalmethods are passive and slow to adapt.” (University of Alberta, 2008)

This is where it becomes hard for poker bots as they lack intuition and there are manyfactors which make it hard as discussed below:

”Opponent modeling in poker appears to have many of the characteristics of the most dif-ficult problems in machine learning - noise, uncertainty, an unbounded number of dimen-sions to explore, and a need to learn quickly and generalize from a relatively small numberof training examples, often with missing or misleading data.” (University of Alberta, 2008)

Page 22: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 14

An area to always improve is therefore trying to make good observations with as little dataas possible. Making assumptions can help improve this but we need to consider its reliabilityand weight our observations as best as possible.

2.12 Success of Poker Bots

A large amount of research has been done in Limit Hold’em and the University of Albertahas had great success in writing limit bot.

”[July 2008] In dramatic fashion, Polaris wins the 2nd man-machine showdown with arecord of 3-2-1. Polaris played against some of the best heads-up limit players in the worldand came out on top with a decisive win against Matt ’Hoss TBF’ Hawrilenko (left) andIJay ’doughnutz’ Palansky (right) in the final match” (University of Alberta, 2008)

Alberta’s limit bot I have not played against but it has beaten many professional limit botsand looks like from the articles released they have thought a lot about every aspect of thegame. As for no limit, BluffBot won a recent competition against other poker bots andit can be played against online (Bluff-Bot, 2008) I beat the bot first time and although itwasn’t awful it was probably below average in heads up play compared to the competitionfound online today. I had my friend that doesn’t play poker play against it and he alsobeat it. From playing it I am pretty sure it doesn’t widen its range based on a frequency ofrelentless re-raising, it seems as though it has a strategy and is trying to be un-exploitablebut doesn’t adapt and therefore can easily be exploited. It seems in situations where I overbet when I am representing such a narrow range it never makes a hero call, although Iwould need a bigger sample size to heavily weight this statement. I just didn’t feel pressedinto difficult decisions and found it took lines that I could exploit. An example is on alow board, where I was the pre-flop raiser, instead of checking to me like it usually does itdecided to bet out. It turned out it had a marginal over pair and in these spots I can raisewith any two cards and make it fold way too often. Even though the line of betting isn’tbad, it just made a lot of easy to read plays and overall was not a tough competitor.

2.13 Opponent Modeling

Opponent modeling is really important in no limit. For example playing draws aggressivelyis almost always the right play against a tight aggressive player but not always againsta calling station. The University of Alberta writes a lot about opponent modeling andsummarizes the importance of your opponent below.

”No poker strategy is complete without a good opponent modeling system. A strong pokerplayer must develop a dynamically changing (adaptive) model of each opponent, to iden-tify potential weaknesses. In traditional games, such as chess, this aspect of strategy isnot required to achieve a word-class level of play. In perfect information games, it hasbeen sufficient to play an objectively best move, without special regard for the opponent.”

Page 23: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 15

(Darse Billings and Szafron, 2001)

Poker is a game of incomplete information and as the article Challenge of Poker states,there is not simply a best move. In fact a better move can be created further down the linedue to your current play. An example of this is purposely making a bluff in a small pot in aplace which likely isn’t profitable. The idea behind this is, if it works you won something, butif it doesn’t it creates a bluffy image. If you’re able to cheaply create an image of someonewho is a maniac, then when the pot is big you increase the chance of getting paid on yourbig hands. This logic shows just how image and player tendencies impact the game, andhaving a good opponent modeling system is essential.

It appears Polaris the limit poker bot from the University of Alberta plays very well. Nolimit hasn’t had the same success which could partially be because more time has been spenton limit bots, although it is likely due to the fact you can size your bets in no limit. Thismakes the opponent modeling system a whole lot more complex. Not only do you havefrequencies along with board textures to consider you have sizes of bets to track in differentsituations. When someone raises on the button a little less than last time, it should impactyour response, playing back exactly the same way is a leak, it may be a minor leak butthere will be many more post flop bets which will need to be handled differently, due to theirsizing. If the bot doesn’t increase its bet size against certain opponents or in good situationsto extract value, it could be missing a lot of value in areas. There are spots where you arereally sure someone will call a bet of 40 the same amount as a bet of 40. There are timeswhere you feel like your opponent will call an over bet but fold to a smaller less than potsize bet. This is because an over bet you think will look like a bluff to your opponent whereasa smaller bet will look like it wants a call. This is something that is going to be based offyour opponent model. The opponents bet sizing is going to be a big factor in deciding thisdecision. The outcome will also be more complex, as if it’s a bet or a raise a size needs tobe established.

”Poki maintains a weight table for each opponent. The table has an entry for every possibletwo card hand, where each value is the conditional probability of the opponent having playedthose cards to the current point in the game.” (Darse Billings and Szafron, 2001)

”To get a better estimate of hand strength, each hand in the enumeration is multiplied byits corresponding probability in the weight table.” (Darse Billings and Szafron, 2001)

It also states that there are two types of weighting. One of these weighting is where it weightsits opponents hand based on how many levels of raises there were for the last betting round.This is important and in poker, we may re-raise because we believe our hand is best andwhen we get raised back we know we only beat a bluff and therefore can comfortably fold.We may raise to drive out hands that dominates us. An example is we hold K10, if wedecide to squeeze having K10o is actually pretty good. As the hands that dominate us willlikely fold e.g. A10, KJ and KQ. AK, KK and AA would almost always 4-bet pre flopmeaning when we make top pair we can expect to be good and we can try and extract valuefrom worse and not be as worried about our kicker compared to a situation where we justflat call a raise and then flop a King. Therefore information about how many times it was

Page 24: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 16

raised allows us to put our opponent on a more accurate range. Also applying the situationof the raise i.e. in the case of the play being a squeeze play it could mean the range ofre-raising has changed because of the additional factor that there was a caller. Thereforetable dynamics play a part when modeling a situation and the fact opponents interact withdifferent opponents differently. We also need to consider how an opponent plays in a handagainst one player does not mean he will play a similar manner against us. This meansthere is a lot of information to filter when applying the information we collected.

An article from the University of Alberta states several skills required.

Hand Evaluation: Accurate assessment of the current strength of our hand, and thepotential strength of our hand when the future board cards are dealt, is crucial. We needthe probability that our hand is the best, given the context of the game and the opponentswe are up against.

Unpredictability:

Our actions must not give away the strength of our hand. We must play deceptively bybluffing, slow-player, and check-raising. It is important that our betting strategy be non-deterministic, and mixes strategies in order to conceal information about our hand.

Opponent Modeling:

We must understand how our opponent plays in order to both exploit their weaknessesand defend against their strengths. We must be able to deduce the strength of hands ouropponents hold by interpreting their actions, and we must be able to anticipate how theywill play.””There are several skills required to play strong poker. These will all be requiredfor a world class poker agent:

Hand Evaluation: Accurate assessment of the current strength of our hand, and thepotential strength of our hand when the future board cards are dealt, is crucial. We needthe probability that our hand is the best, given the context of the game and the opponentswe are up against.

Unpredictability:

Our actions must not give away the strength of our hand. We must play deceptively bybluffing, slow-player, and check-raising. It is important that our betting strategy be non-deterministic, and mixes strategies in order to conceal information about our hand.

Opponent Modeling:

We must understand how our opponent plays in order to both exploit their weaknessesand defend against their strengths. We must be able to deduce the strength of hands ouropponents hold by interpreting their actions, and we must be able to anticipate how theywill play.” (Davidson, 2002)

This outlines some important areas and we have already briefly discussed the impact offuture cards in a hand when bluffing. This line of thinking should be applied all the time

Page 25: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 17

throughout poker, not just when bluffing. The unpredictability factor is listed here, and Iwould say it is only required when playing strong poker players. Being unpredictable andhaving balanced ranges is nice but not essential against many good players, although becomesa bigger factor in a game with world class poker players. The important of opponent’stendencies has been mentioned and we can see Alberta also consider it an important factoras it appears to be a common theme in their articles.

2.14 Poker Software and tools

In this section we will to research various poker tools available and to discover what hasbeen developed already. Given that poker software for the home user hasn’t been around allthat long in comparision to when poker was first played online and that new software withnew functionalities is still being released it appears that there are still gaps in the market.

Almost all main poker sites provide an option to save a history of poker hands played at thetable you were playing at to a file on your PC. There is now software on the market todaywhich will read this file and provide a player with as many useful statistics as possible overa long period of time. This will include statistics such as their winnings and how oftenthey do a particular play. There is also software that will display statistics about otherplayers in the game next to their name on the screen as you play. Software such as hold’emmanager (Hold’em-Manager, 2008) lets you choose statistics from a long list that you wishto display next to each player, then if you click on the players name it brings up a moredetailed analysis of the player, as shown in the screenshot. This is known as a HUD (HeadsUp Display Unit). Other similar software include poker tracker (Poker-Tracker, 2008) andpoker academy prospector (Poker-Academy, 2008)

Poker academy from the University of Alberta appears to have found one of the gaps we firstthought existed and infact the program was in beta when we started researching this areabut throughout the year has become more and more advanced. The idea is that people playagainst one or several of their bots they have implemented which are supposedly programmedto exploit your weaknesses and thus improve your play with the provided analysis. One ofthe programs listed features is:

”Elevate your game to new heights using the most advanced features in any poker software.Dealer options allow you to stack the deck to work on the holes in your game. Work onmid-pocket pairs by repeatedly dealing yourself pocket 7’s and learn when to fold and whento push. ” (Poker-Academy, 2008)

Although poker academy does not support the user to write their own bot they seem to covermost areas of interest an online and live poker player would need.

The software ’poker academy’ from the University of Alberta (University of Alberta, 2008)is stated to be the best training software available and it appeared to me the bots play poorlyin 6 handed no-limit hold’em although this was during the beta stage of the software. Wetrailed the software and it appeared the bots had no concept of pot to stack ratio. This was

Page 26: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 18

Figure 2.1: Heads Up Display Screenshot

shown by a bot pushing his stack in with the hand, king seven, when the only dead chipswere the blinds. We noticed the bots sometimes used small probe bets to ’see’ where theywere at on the flop, this is typically a sign of weakness and we could use this informationagainst them. In general the bots were aggressive but in an uncontrolled way and they didn’tseem to adapt to my image at the table. This made it hard to believe it could be used as atraining tool and perhaps it just shows how far behind no limit poker bots are compared tolimit poker bots. Also another factor is poker bot researcg has been almost purely done in1 vs 1 (also known as heads up) format and could just show that 6 handed no limit pokerbots have a long way to go until they can beat any enthusiastic player.

One particular tool which a poker player will use which is free to download is poker stove(RPS-Consulting, 2008) this allows you to calculate the equity any particular hand has inany situation supporting up to 10 players. You can assign a range of hands to see theaverage chance of winning against a particular hand or any range of hands. This softwaresupports only texas hold’em but there are other web based tools such as two dimes thatsupport other games. (Two-Dimes, 2008)

Lastly a poker bots that appears to be legitamate, (use it your own risk) win hold’em canapparently play on online poker sites although its strategy seems very primitive to nonexistant. (Win-Hold’em, 2008) Some sources claim it can beat games although they onlymention a strategy of pot odds which is clearly not enough, although there are some siteswhich claim you have to write the code yourself to turn it into a winning poker bot whichis probably the more likely scenerio.

Page 27: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 2. LITERATURE SURVEY 19

2.15 Conclusion

Having read the entirety of ”No Limit Hold’em - Theory and Practice” (Sklansky, 1999)and ”The Elements of Poker” (Angelo, 2007) along with playing over two hundred thousandhands of poker online within the last year it will provide a good base for the project. Wehave discussed briefly the outline of the evolution of poker strategy from the fundamentaltheorem of poker by David Sklansky to more advanced thinking. We have discussed differentfactors that effect our decisions and thought processes. We have also looked at various pokersoftware and tools currently around and discovered that there isn’t currently a product thatallows you to write and test a poker bot that is widely available from what we have seen.There may be solutions to writing a bot which can play online, claiming the bot can beatplayers online but there seems to not be an offline evironment for players to use. Infactmany of these products are a scam and we have seen from our research poker bots canonly barely beat good human players in limit heads up hold’em, and you won’t be able todownload a bot that can beat players in 6-max no limit hold’em. This can be illustrated bythe success of the University of Alberta (University of Alberta, 2008) but also from PokerListings which says:

”The only area that pokerbots are considered to be talented enough to make consistent moneyis Limit heads-up, and even there, their dominance is in question. To make matters worsefor the bots, Limit heads-up is one of the least popular games on the net - some onlinerooms don’t even offer it.” (Crowson, 2008)

We should also consider that using online poker sites as environment to test a poker bot maybe legal, but goes against the poker sites regulations and they will ban you from their site.It also isn’t fair to many players and therefore poker bots should be used in an environmentsuch as the one we will be writing.

Page 28: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 3

Requirements

We started with a top-level view of the problem, which was to view the requirements in 4catagories as follows:

• Game Functionalities - Essential

• Networking - Important

• Bot Development - Essential

• User Interface - Essential

• Non-Functional

The requirements for the project were gathered by brainstorming, bserving poker software,using experience of playing the game and by consulting the rules of the game. After writingthe literature review there was a clear idea of what the project involved and there was noprocess of gathering requirements rather to ensure all functionality was thought of. Therequirements are listed below and the importance of the requirement are marked for eachsection but within the sections there are a few variantions in importance and they have beenlabeled in brackets at the end of the requirement.

3.1 Game requirements

1. Write a class to support the entirety of the game 6 max no limit texas hold’em.

(a) Provide a method to shuffle the deck with all 4 suits present. Provide methodsto deal two cards to each player and a method to deal the flop, turn and river.

(b) Provide a class to hold a player’s details: stack size, their cards and their uniqueid.

20

Page 29: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 3. REQUIREMENTS 21

(c) Support up to 6 players in a game.

(d) Show each player’s cards on screen at the start of each hand.

(e) Insure the dealer button, small blind and big blind move across 1 each hand andthat the person first to act is correct on each street.

(f) Handle each of the actions: Check, call, bet, raise or fold as appropriate to thegame rules.

(g) When there is a bet and a raise insure that the initial raiser has a decision tocall the re-raise and that all bets are made before seeing the next card.

(h) When a player folds insure they are not involve in the rest of the hand.

(i) Insure that the minimum raise starts of as the big blind and then is equal to anyraise or bet amount that follows.

(j) When a bet, raise or call is made deduct this amount from the players stacksize. If the player makes a bet but then calls a raise, the bet should be deductedfollowed by a deduction of the raise size minus their bet size.

(k) Calculate every players hand at showdown and determine the winning hand.

(l) Show the hand left of the dealer first and then left of this player second. If thenext hand is not as good as the current best shown hand, do not show the handand muck their cards. If the hand is better show the hand.

(m) Award the player with the best hand by adding the potsize to their stack size, ifit is a draw the pot is split equally between the winners.

(n) Input will be received as a string and incorrect input should be handled by sendingback useful messages in the same format.

(o) Send data in a specified format so that a bot can receive it.

3.2 Networking Requirements

1. Provide a networked solution by implementing a server-client solution to the game.

(a) Write a server that allows clients to connect.

i. Provide a simple way for the user to specify which port number the servershould communicate to clients via.

ii. Accept incoming connections.iii. Implement threading to allow multiple clients to connect.iv. Store each thread in an array to allow for easy echo’ing of messages.v. Assign each client a unique ID.

vi. Receive incoming messages and echo messages by sending the received mes-sage to all other clients via the established connection.

Page 30: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 3. REQUIREMENTS 22

(b) Write a client that can connect to an IP address via a port number.

i. Provide a simple way for the user to specify the port number to communicatevia and the IP address of the server.

ii. Send messages via the established connection.iii. Differentiate between recieving data for the bot and messages that hold an

action sent by a player.

(c) Provide communication of actions as the transfer of strings between classes.

i. Communicate all actions that the user should see to the server. Then havethe server send a message to each client.

ii. Structure the string to record who the message is to, from, the action, thebet or raise amount and differentiate between a message for the bot and amessage sent as an action initiated by a player acting in the hand.

iii. Send hole cards to each client, using the structured string to insure eachclient receives only their cards.

iv. When the server recieves an action which is successfull send a message toall clients.

v. When the server recieves an action that is unsuccessfull send a message tothe client that sent the action.

vi. Send each action as data for a bot to process.

3.3 Bot Development Requirements

1. Provide a flexible environment for a bot to interact.

(a) Allow bots to play and connect in the same fashion as a human would.

(b) Provide a method for the bot that will receive all actions automatically.

(c) Call a method in the bot class when it is the bots turn to act.

(d) Provide a method to retrieve hole cards within the bot class.

(e) Provide a template for the bot class with the required methods to implement abot in this system.

2. Write a poker bot.

(a) Write a bot that calls every bet but otherwise will check. (Important)

(b) Write a bot that acts randomly but when it randomly decides to bet or raise itraises a random amount between 2 and 20 but only when it holds a high card.(Nice to have)

(c) Write a more advanced bot that takes into account other player traits. (Nice tohave)

Page 31: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 3. REQUIREMENTS 23

3.4 User Interface Requirements

1. Provide a way for the user to interact with the system.

2. Allow the user to be able to perform every action required.

3. Expand the user interface to provide graphics to assist a better look and feel (Nice tohave)

3.5 Non-Functional Requirements

1. The end product should require a low specification. It should be capable of running onany machine that can support java applications. (Essential)

2. The system should have at least a reasonable fault tolerence and therefore does notlock up, crash or memory leak. (Essential)

3. The system should be robust by handling and responding to inaccurate responses sentby players or bots. (Important)

4. The end product should be easy to use and require very little learning for anyone thatplays poker. (Nice to have)

5. The systems components should be well encapsulated to accomodate changes in require-ments. (Nice to have)

6. There should be high cohesion within the system to make the system maintainable.(Nice to have)

7. The development and playability of a bot should be flexible within the system. (Essen-tial)

3.6 Requirement Gathering Review

Looking back at the requirement gathering process it seems thorough enough. The intro-duction and literature review set about defining the problem and it was merely ensuring Ihad all the functionality needed to implement the game of poker and provide a chat clientsoftware integrated into the game. I found brainstorming formed a large portion of gath-ering requirements and by considering each action I was able to write the requirements forthe game class. The networking requirements required more thought although a requirementfrom the game class was missed as the game class does not handle side pots, which areformed when a player cannot meet the whole bet.

Page 32: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 4

Design

4.1 Class Design

The choice of language to be used to implement the project was decided to be Java. Thereason is that a class structured approach will fit well with this project as it naturally breaksdown into 4 sections.

• The workings of the game

• Networking

• The bot mechanics

• User Interface

Inside this section there are also natural breaks. Another reason for chosing Java was thatit supports networking well and looks to provide a simple solution to programmers. Theworkings of the game were handled by a class called the game class. There were be twofurther supporting classes player and card, which were to be used to create instances ofplayers and cards respectively. The networking code consisted of 3 classes: server, clientand thread. A server-client model was used and also threading so that the server cancommunicate with multiple clients at once. The user class is the class that will be run tostart the program. The human class inherits from user and also any bot class created willneed to do so also. Essentially the human class is an empty bot class and there is an actualclass called bot which is the template for making a bot.

24

Page 33: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 25

The class diagram above shows there are 10 classes

1. User: Super class of human and bot where bot can be any name choosen by the botdeveloper

2. Human: The default class to be run when wanting to join the server as a humanplayer, this inherits from class User.

3. Bot: The template class for a bot which inherits from class User.

4. GUI: The class containing the Graphical User Interface code.

5. Server: The class used to handle the server side.

6. Client: The class used to handle the client side.

7. Thread: The class that extends thread and handles threading to allow for support ofmultiple clients.

8. Game: The class that contains the workings of the game

9. Player: Provides attributes on the player.

10. Card: Provides information on a card and each card itself.

The project plan was followed and therefore the first bit of coding was the implementationof the game, player and card classes. The first stages was to get a working solution of thegame on a stand alone PC. Once this was complete the next stage was to implement thenetworking classes that include the classes server, client and thread along with the GUIclass. The final stage but essential to the project were the bot classes.

4.2 Class Interactions

The numbered stages below are shown in the diagram beneath in figure 4.2. This diagramshows the stages involved in starting a game.

1. This is where the human class or bot class will be ran and will automatically createan instance of the GUI class, giving the option for the user to connect as a client orserver.

2. The player chooses to connect as a client, to do so the ip address of the server isrequired as well as the port the program will be using, which is specified by the server.

3. Once the player has attempted to connect a new socket is created for the connection.

4. The server then accepts the connection.

5. Once all players have connected the server initiates a game class.

6. The game class initiates instances of player and card and starts the game.

Page 34: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 26

Figure 4.1: Class Diagram

Figure 4.2: Stages to start a game

Page 35: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 27

4.3 Game Class

The game class runs on the PC that will act as the server. All other players connect to thisserver. The game class handles everything about the poker game apart from the informationof the player’s cards, stack size and player ID. The table below shows the information to bestored and the methods that will manipulate and output the data. The game class will alsobe responsible for communicating messages but the actual communication will be done inthe client and server class. Therefore the game class identifies the message to be sent anduses a method from elsewhere.

Required Variables

Variable Name Storage and UsePlayers An instance of class player and is used to hold stack

size and unique IDPlayer cards An instance of class card and is used to hold the play-

ers hole cardsCommunity cards An instance of class card and is used to hold the com-

munity cardsPlayers Bets An array of each players bet for this roundPlayers Checked A record of whether a player has checked this cardPlayers Acted A record of whether a player has acted this roundTotal Bet The highest bet this cardPot Size The total in the pot, i.e. the amount bet by all players

this roundDealer Position The ID of the player who is the supposed dealerSmall Blind The ID of the player who is in the small blindBig Blind The ID of the player who is in the big blindUnder The Gun The ID of the player who is in under the gun, i.e. first

to actMiddle Position The ID of the player who is in middle positionCut Off The ID of the player who is in the cut offPlayer Hand Rank Keeps record of the players best hand rank

The above variables are only the top level variables involved in the game class. Inside themethods there are other variables such as the method flush which would have a count forthe number of hearts in a players hand but these are merely variables to help output ananswer and a vast amount to list.

Page 36: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 28

Required Methods

Method Name FunctionalityCreate Players Creates an instance of player class for each player on

the serverGenerate Cards Initiates a deck of 52 cardsShuffle Shuffles the packDeal Flop Sends a message to all players what the flop is for this

roundDeal Turn Sends a message to all players what the turn for this

roundDeal River Sends a message to all players what the turn for this

roundShow Cards Sends a message to each player what their hole cards

areShow Hand Sends a message containing a players best 5 card handCheck Win This handles the showdown of the hand taking into

account split pot and who is able to muck their cardsCheck Hand Calculates a players best 5 card handDecision Handles all input from the userNext Hand Resets variables and moves the dealer button and all

other positions by 1Check Decisions Checks all decisions have been completedClear Bets Clears all memory of bettingHigh Card puts all 7 cards into an array and sorts them to find

the highest cardPair puts all 7 cards into an array and looks for two cards

with the same value i.e a pairTwo Pair puts all 7 cards into an array and looks for pairsThree of a Kind puts all 7 cards into an array and looks for 3 cards

with the same valueStraight puts all 7 cards into an array and sorts them into order

of value, and looks to see if there are 5 cards wherebythe difference in value between each card is 1

Flush puts all 7 cards into an array and counts the numberof suits, if the count reaches 5 the player has a flushand the cards are sorted to determine the flushes value

Full House This uses the methods tripofSet and twoPair, if boththese return positive then the player has a full house

Full House Puts all 7 cards into an array and looks for 4 cardswith the same value

Page 37: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 29

Figure 4.3: String Structure

4.4 Communication

When a client connects to the server it is assigned a unique id, and this is used to identifyitself throughout the game. When a user performs an action it generates a string. Forexample when a user presses the ’call’ button it sends a string to the server. The first stepis for the graphical user interface to recognize this action and then compose a string. Thisstring is sent to the client class which sends the string to the server via the establishedconnection. The server receives the message and relays the message to all other clients.Each action will send a structured string to the server, which is structured as shown above.The ’to’ field if set to 9 will mean it is to be sent to everyone, but essentially you can write0 instead as the server will always assign itself the id of 0. When a server echos a messageto every client it will put a 9 in the ’from’ field because it doesn’t matter who its from asthe message contains purely information. An 8 was reserved in the ’to’ field for data thatwas intended for the bot. These messages are sent to a method in the User class which willallow the bot to receive them as the bot class inherits user. Also a 7 is reserved for datawhich contain the bots hole cards.

These messages are differentiated in the client class where it looks at the first digit to seeif it 0 to 5, 7, 8 or 9. 0 to 5 would indicate its intended for a specific player.

The diagram below should fully demonstrate how the system handles the communication ofmessages. The example of player 1 raising 8 has been used to demonstrate this.

Page 38: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 30

Figure 4.4: Pathway of Messages

Page 39: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 31

4.5 Developing a flexible Environment

When considering how to solve the problem of allowing any poker bot to be dealt in the handthe solution was established that a both human and bot should initiate a GUI so that theycan connect to the server. Once in the server they are acknowledged in the game. Whenit comes to the bot or human to act, a method is called in the User class, which both botand human inherit. When it is the humans turn to act, a method is called but it is empty,therefore no response is given but instead the human gives it’s own response by clicking abutton thus allowing the game to continue. The bot is required to fill this method with aresponse which is in the format of a string formatted as shown previously in the design.This means to write a bot you simply need a class that inherits user and has this methodcalled ’Decide’. Additionally it also requires two other methods, one to receive actions sentfrom other players, although the method can be left empty it is still required to be there.This method is ’getData’ which takes 3 strings as parameters. The final method is ’getHand’which is called when sending hole cards to all players. This method should be used to recordthe data sent to it.

4.6 Bot Development

The first step in bot development was to write a simple bot to test the environment, bystarting with a bot that simply calls every bet or if no bet has been made it checks it provideda quick solution and was useful to find bugs in the software. The next step was to developa bot that can read its own hand and act randomely. This will not take any design so thedesign of a more advanced bot is given below. The idea for a more advanced bot was a botwhich adapts over time as more information becomes available from players. By loggingeach action an accurate representation of each player’s style can be built up over time andthis information is to be used in helping the bot make decisions.

The bot to be implemented would consider the following factors:

• The average percentage of hands being played by the table and each player

• The aggression of the table and each player

• The chance a player folds to a bet on each street.

• The chance a player folds to a 3-bet pre-flop and on each later street (i.e. flop, turnand river)

• Its own relative hand strength, a factor in this will be the number of players in the pot.

• A players betting frequency on each street.

• Bet size and bands

The percentage of hands a player is playing will form the basis of estimating the range ofhands for a player. Throughout the hand there will be a range of hands assigned to each

Page 40: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 32

Figure 4.5: Range Comparisions

player. When a player opens pre-flop it will automatically assign a range based on thenumber of hands that player has played. Originally the range will be a range based on themost likely hands from how people play today. If hands go to showdown the bot can adjust itsrange if necessary for that player when it comes to assigning a range pre-flop. For examplea player raises in early position with 54s which gets to showdown. Most likely the rangewill be changed by dropping some broad-way hands and adding small suited connectors butkeeping the percentage the same but noting the range is more polarized to big pairs andsuited connectors rather than just high picture cards. There is to be an algorithm for eachdecision involving all factors. Figure 4.5 above shows two different ranges both covering 10percent.

4.7 Developing an un-exploitable bot

Professional poker players try to be un-exploitable although sometimes playing in an ex-ploitable way is the most profitable. This is the case when your opponent will not exploityou. Treating bet sizes the same would certainly be a flaw, therefore by grouping a playersbet it will allow to bot to make better decisions

Each time a player makes a bet it will be added to a band. The bands will be as follows:

• Band 1: 0 to 1/4 pot

• Band 2: (1/4 * pot size) to (1/2 * pot size)

• Band 3: (1/2 * pot size) to (3/4 * pot size)

• Band 4: (3/4 * pot size) to (1 * pot size)

Page 41: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 33

• Band 5: (1 * pot size) to (1 1/2 * pot size)

• Band 6: (1 1/2 * pot size) to (2 * pot size)

• Band 7: Greater than (2 * pot size)

This will mean if a player repeatedly makes a very small bet, it will start to get noticed andthis well help the bot treat different bet sizes differently.

4.8 Pre-flop

Each player is assigned 3 values, percentage of hands being played, percentage of handsraised preflop and aggression factor. Aggression factor is calculated by taking the numberof times the player makes a bet or raises and dividing by the number of times the playercalls. From these values a set range will be assigned, which is to be based on a chosencommon range. As more information becomes available this range is to be changed to forma more accurate representation.

4.9 Flop

There will be an important factor calculated each time on the flop. It will take a playersrange and the flop and calculate the chance this player has flopped a hand and the chancehe has flopped a drawing hand with more than 6 outs. If both figures are low, the bot willbet about 3/4 pot by default. Each player will have a chance to fold to a bet on the flop.This factor is to be used with the chance the player has made a hand to determine if the botshould bet or not. If the chance a player has made a hand is above a certain percent thenthe bot compares its hand to the range of the players to calculate its relative hand strength.

4.10 Graphical User Interface Design

To connect the user has to provide an IP address and port number and therefore a windowto do this was required. Also an area to display information about the game and a way tochoose from the following actions: check, call, fold, bet and raise. There is a need for aninput box to type the bet or raise amount. Given these requirements the following designfollowed as seen below. The intention was to keep it simple, additionally the area thatdisplays information was firstly implemented as simple as possible with text. If there wastime we would expand it to show pictures of cards rather than text.

Page 42: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 4. DESIGN 34

Figure 4.6: Graphical User Interface

Page 43: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 5

Implementation and Testing

5.1 Code Review

The aim of this section is to provide an overview of the implementation. I will look at keysnippets of code to achieve this. Below is code taken from the game class, and is the codethat handles the action of a raise. I thought this was appropriate as the game class is thebiggest class and handling actions makes up a large part of the class and a raise is the themost complex action to handle.

Listing 5.1: Code handling a raisei f ( i n p u t . e q u a l s ( ” r a i ” ) ) {

i f ( t o t a l B e t > 0) {rAmount = I n t e g e r . p a r s e I n t ( inputAmount ) ;i f ( rAmount >= rAmountMax ) {

rAmountMax = rAmount ;} else {

rAmount = rAmountMax ;g u i . sendMsg ( inputID + ”9” + ”Your r a i s e i s too smal l , ” +

rAmount + ” r a i s e d i n s t e a d \n” ) ;}i f ( ( rAmount + ( t o t a l B e t − p l a y e r B e t s [ pos ] ) ) <

p l a y e r [ pos ] . s t a c k S i z e ) {p l a y e r [ pos ] . s t a c k S i z e = p l a y e r [ pos ] . s t a c k S i z e − ( rAmount +

( t o t a l B e t − p l a y e r B e t s [ pos ] ) ) ;po t = pot + ( rAmount + ( t o t a l B e t − p l a y e r B e t s [ pos ] ) ) ;t o t a l B e t = t o t a l B e t + rAmount ;p l a y e r B e t s [ pos ] = t o t a l B e t ;p l a y e r A c t e d [ pos ] = 1 ;g u i . sendMsg ( ”99 Player ” + pos + ” r a i s e s ” + rAmount +

”\n” ) ;} else {

rAmount = p l a y e r [ pos ] . s t a c k S i z e − ( t o t a l B e t −p l a y e r B e t s [ pos ] ) ;

35

Page 44: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 5. IMPLEMENTATION AND TESTING 36

g u i . sendMsg ( ”99 Player ” + pos + ” i s Al l−IN : an a d d i t i o n a lr a i s e o f ” + rAmount + ”\n” ) ;

p l a y e r [ pos ] . s t a c k S i z e = p l a y e r [ pos ] . s t a c k S i z e − ( rAmount +( t o t a l B e t − p l a y e r B e t s [ pos ] ) ) ;

po t = pot + ( rAmount + ( t o t a l B e t − p l a y e r B e t s [ pos ] ) ) ;t o t a l B e t = t o t a l B e t + rAmount ;p l a y e r B e t s [ pos ] = t o t a l B e t ;p l a y e r A c t e d [ pos ] = 1 ;

}g u i . sendData ( ”8” + pos + ” r a i ” + rAmount ) ;

} else {g u i . sendMsg ( inputID + ”9” + ” There i s no b e t t o r a i s e , t r y

u s i n g t h e command ’ b e t ’ ” ) ;wrongInput = true ;

}}

The code above in figure 5.1 handles a raise, if there is a raise then input will equal ”rai”,therefore if there has been a raise we can check if there has been a bet already, as you cannotraise without a bet. Therefore if the total bet is greater than 0 we can continue otherwise amessage is sent back to the user, the id of the player who sent the action is recorded whenthe action is recieved as inputID. Therefore inputID can be used in the ’to’ position of thestring and wrongInput is set to true so that the system knows the action wasn’t valid andwe are still waiting for a valid response from the same player. If these two conditions aresatisifed the raise amount held in the string is converted to an integer:

rAmount = Integer.parseInt(inputAmount);

It then checks to see if the amount raised is greater than the current minimum raise denotedby ’rAmountMax’, if it is not the raise is set to the minimum amount since these are therules that if you annouce a raise and you raise too small it is rounded to the smallestamount. A message is sent to the user to inform them of this. A comparison is then carriedout. The variable totalBet holds the biggest bet made by someone so far, and playerBets[pos]is an array of bets for each player, where pos is the id of the player who made this raise.Therefore totalBet - playerBets[pos] will return the amount this player owes the pot already.It then takes this sum and adds it to their additional raise to see if it is smaller than theirstack size or not. Depending on whether it is or not it is handled seperately. In both casesit updates totalBet to be equal to the new largest bet, and then assigns this bet to the playerwhose decision we are handling since we know they made this total bet. The amount is alsoadded to the pot and the player is flagged as having acted once at least and a message toeveryone is given to update everyone with what just happened. This bit of code is the mostcomplex of all the code that handles the actions but the other actions are dealt with in asimilar fashion.

Page 45: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 5. IMPLEMENTATION AND TESTING 37

Listing 5.2: Method thats called when bots turn to act

/∗ This method i s c a l l e d when i t i s t h e b o t ’ s turn .The method needs t o end w i t h g u i . sendMsg ( x )Where X i s ”9” then t h e i n t e g e r num f o l l o w e d by ” che ” , ” c a l ” ,

” b e t ” , ” r a i ” or ” f o l ”f o l l o w e d by t h e b e t or r a i s e amount i f a p p l i c a b l e ∗/

public void Decide ( ) {

}

Listing 5.3: Retrieving Action

/∗ This method i s c a l l e d a u t o m a t i c a l l y f o r each a c t i o n .Data i s s e n t t o t h i s method in t h e f o l l o w i n g format :− User ID : The user t h a t d id t h e a c t i o n− Deci s ion : The u s e r s d e c i s i o n , where t h e f i r s t 3 c h a r a c t e r s

r e p r e s e n tt h e a c t i o n s check , c a l l , be t , r a i s e or f o l d (” che ” , ” c a l ” , ” b e t ” ,

” r a i ” or ” f o l ”)− Amount : The amount t h a t was b e t or r a i s e d i f a p p l i c a b l e ∗/

public void getData ( S t r i n g UserID , S t r i n g Decis ion , S t r i n gAmount ) {

}

Listing 5.4: Retrieving Hole Cards

public void getHand ( S t r i n g to , S t r i n g v1 , S t r i n g s1 , S t r i n g v2 ,S t r i n g s2 ) {x = I n t e g e r . p a r s e I n t ( t o ) ;v a l u e 1 = c o n v e r t ( v1 ) ;v a l u e 2 = c o n v e r t ( v2 ) ;i f (num == x ) {

card1 . s e t V a l u e ( v a l u e 1 ) ;card1 . s e t S u i t ( I n t e g e r . p a r s e I n t ( s1 ) ) ;card2 . s e t V a l u e ( v a l u e 2 ) ;card2 . s e t S u i t ( I n t e g e r . p a r s e I n t ( s2 ) ) ;

}}

}

The Listings 5.2, 5.3 and 5.4 are the only required methods for the bot and both methods’getHand’ and ’getData’ can be left blank. This has been included as the main aim of thisproject was to provide a flexible environment and this code can be used to demonstrate thatit is. Listing 5.2 shows the method that is called when it is the bots turn to act. This

Page 46: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 5. IMPLEMENTATION AND TESTING 38

method is intended to provide as much analysis as possible before sending a string usingthe send message function in the gui. An example would be gui.sendMsg(”9 + this.num +”che”). where ”this.num” is the ID of the bot. Listing 5.3 shows the method to retrieveeach action. To be of use it is will need to record the string ’Decision’. The UserID holdsthe ID of the player who sent the action. The Listing 5.3 retrieves the hole cards of the bot,and in the bot template it creates two instances of class card and assigns 1 to each of thebots hole cards. Therefore in the bot template the cards can be accessed by variables ’card1’and ’card2’.

The code below is what differentiates a string so it can be handled correctly. If a string startswith 8, it is required to be recieved by ’getData’ in the bot class, ’RecieveMsg’ handles thisin the GUI and therefore the code below in the client class called this method when ’s’ equals”8”. When ’s’ equals ”7” it means the rest of the string contains hole card information forthe bot and this is handled by ’RecieveHand’ in the GUI which passes it on to the method’getHand’ in the bot class.

Listing 5.5: Differentiating messages

S t r i n g s = message . s u b s t r i n g ( 0 , 1 ) ;S t r i n g s2 = message . s u b s t r i n g ( 1 , 2 ) ;i f ( s . e q u a l s ( ”0” ) | | s . e q u a l s ( ”1” ) | | s . e q u a l s ( ”2” ) | |

s . e q u a l s ( ”3” ) | | s . e q u a l s ( ”4” ) | | s . e q u a l s ( ”5” ) | |s . e q u a l s ( ”6” ) | | s . e q u a l s ( ”7” ) | | s . e q u a l s ( ”8” ) | |s . e q u a l s ( ”9” ) ) {g u i . RecieveMsg ( message . s u b s t r i n g ( 2 ) , s , s2 ) ;i f ( s . e q u a l s ( ”8” ) ) {

g u i . RecieveData ( message . s u b s t r i n g ( 1 , 2 ) ,message . s u b s t r i n g ( 2 , 5 ) , message . s u b s t r i n g ( 5 ) ) ;

}i f ( s2 . e q u a l s ( ”7” ) ) {

g u i . RecieveHand ( message . s u b s t r i n g ( 0 , 1 ) ,message . s u b s t r i n g ( 2 , 3 ) ,message . s u b s t r i n g ( 3 , 4 ) ,message . s u b s t r i n g ( 4 , 5 ) ,message . s u b s t r i n g ( 5 , 6 ) ) ;

}} else {

g u i . Rec ieve ( message ) ;}

5.2 Testing

Two types of testing were done, one was to find known bugs done by myself throughoutthe implementation and the other was done by users who volunteered to test, they moreassessed the software rather than tried to find a problem with the software. I have found a

Page 47: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 5. IMPLEMENTATION AND TESTING 39

couple of bugs which unfortunately haven’t been corrected, one is that the stack size for aplayer does not get reset when they loses all their chips, instead it tries to continue and thebest solution currently is to click ’start’ on the server to restart the hand. Split pots aren’tworking properly and this is something that has taken up to much time trying to resolve.The last problem found is the bots sometimes do not respond but its believe to be down tohaving too many bots on one computer.

When user testing was carred out, everyone was given a project briefing to read, which isshown below:

”My aim in this project was to provide a flexible environment for someone with limitedprogramming skills to be able to develop a poker bot to play in today’s most popular variantand format of poker, 6-max no limit texas hold’em. I have developed a framework for peopleto play against poker bots as well as other people. The game will be played across a network.To join the game that I will be hosting, load a command prompt and browse to the directoryyou saved the code to. Then type ”java Human” this will load the game and to join the gameclick connect and then put the IP address as 87.194.118.101 and the port number as 3000.Once in the game you can chat by typing text in the box and clicking the send button, onceeveryone is ready I will start the game and we will play for up to 15 minutes. If at any timeyou wish to quit just let me know and press the quit button or simply close the program.Afterward testing, if you are a programmer I will show you the flexibility of creating yourown bot and then there will be questionnaire for you to complete. The questionnaire will beanonymous and not used for any other reason other than to analyse of my project. If youare happy to continue to help me to test my project please sign below:”

I did just as much testing with people online and therefore it was not possible to obtainsignatures from everyone but they understood the conditions and agreed to carry out testingcommunicating across the internet. Feedback was still received to the questions. A blankquestionnaire is featured on the next page.

Page 48: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 5. IMPLEMENTATION AND TESTING 40

5.3 Questionnaire

Page 49: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 6

Results

The general view from user feedback was that it was easy to join the server, the usabil-ity varies between 2’s and 3’s and generally people considered the amount of informationavailable during the game was about right although that it could be presented better.

Game requirements

Requirement Description Test Input / Test Vali-dation

Success

Provide a method to shuf-fle the deck with all 4 suitspresent. Provide methods todeal two cards to each playerand a method to deal the flop,turn and river.

Provided by built inmethod shuffle

yes

Provide a class to hold aplayer’s details: stack size,their cards and their uniqueid.

Provided by class card yes

Support up to 6 players in agame.

Testing the game nu-merous times, the 7thperson in the game can-not play

yes

Provide a class to hold aplayer’s details: stack size,their cards and their uniqueid.

Provided by class card yes

Show each player’s cards onscreen at the start of eachhand.

Seen by each user intesting

yes

41

Page 50: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 6. RESULTS 42

Requirement Description Test Input / Test Vali-dation

Success

Insure the dealer button, smallblind and big blind moveacross 1 each hand and thatthe person first to act is cor-rect on each street.

nextHand method uses amethod called increase-Pos to move the posi-tions by 1

yes

Handle each of the actions:Check, call, bet, raise or foldas appropriate to the gamerules.

Every action has beenhandled, each actiondone during testing

yes

When there is a bet and araise insure that the initialraiser has a decision to callthe re-raise and that all betsare made before seeing thenext card.

This has been tested bymaking player x raiseand player y re-raiseand the code has beenanalysed in the section’Implementation

yes

When a player folds insurethey are not involve in the restof the hand.

had a problems with thisbut recent attemps haveworked

yes (couldhave aproblem)

Insure that the minimum raisestarts of as the big blind andthen is equal to any raise orbet amount that follows.

As shown in the section’Implementation’

yes

When a bet, raise or call ismade deduct this amount fromthe players stack size. If theplayer makes a bet but thencalls a raise, the bet should bededucted followed by a deduc-tion of the raise size minustheir bet size.

As shown in the section’Implement’

yes

Calculate every players handat showdown and determinethe winning hand.

I have checked everyplayers hand in a 6handed game and resultsare always correct overa large sample of closeto 100 hands

yes

Award the player with the besthand by adding the potsize totheir stack size, if it is a drawthe pot is split equally betweenthe winners.

tested but does the gamedoes not function prop-erly in the case of a splitpot

no

Input will be received as astring and incorrect inputshould be handled by sendingback useful messages in thesame format.

handled thoroughly withfeedback to the user inreal time

yes

Send data in a specified for-mat so that a bot can receiveit.

This is done by themethod sendData

yes

Page 51: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 6. RESULTS 43

Networking Requirements

Requirement Description Test Input / Test Vali-dation

Success

Provide a simple way forthe user to specify whichport number the server shouldcommunicate to clients via.

Performed by GUICon-nect

yes Acceptincomingconnec-tions.

Inbuilt method accept whichworked

yes

Implement threading to allowmultiple clients to connect.

Threading was imple-mented allowing multi-ple clients to send mes-sages to the server si-multaneously

yes

Store each thread in an arrayto allow for easy echo’ing ofmessages.

An array was used yes

Assign each client a uniqueID.

The server had the ID 0and each client took + 1from that

yes

Receive incoming messagesand echo messages by send-ing the received message toall other clients via the estab-lished connection.

messages were success-fully echo’d

yes

Write a client that can con-nect to an IP address via aport number.

A client would connectvia IP / Port No.

yes

Provide a simple way for theuser to specify the port num-ber to communicate via andthe IP address of the server.

GUIConnect providedthese functionalities

yes

Send messages via the estab-lished connection.

messages initiated fromthe GUI sent to theclient and thread classes

yes

Page 52: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 6. RESULTS 44

Requirement Description Test Input / Test Vali-dation

Success

Differentiate between reciev-ing data for the bot and mes-sages that hold an action sentby a player.

A messaging system ofa string starting with an’8’ was used for datathat the bot was meantto receive

yes

Provide communication of ac-tions as the transfer of stringsbetween classes

All communication wasdone via strings

yes

Communicate all actions thatthe user should see to theserver. Then have the serversend a message to each client.

this process occured yes

Structure the string to recordwho the message is to, from,the action, the bet or raiseamount and differentiate be-tween a message for the botand a message sent as an ac-tion initiated by a player act-ing in the hand.

This was achieved

end hole cards to each client,using the structured stringto insure each client receivesonly their cards.

This was written in thegame class, the methodbeing showCards andimplemented in the botclass as getHand

yes

When the server recieves anaction which is successfullsend a message to all clients.

Good sending of in-formation was imple-mented and tested viauser evaluation

yes

When the server recieves anaction that is unsuccessfullsend a message to the clientthat sent the action.

This happens in the casethey check when a bethas been made, bet whena bet has been made andcall when there is no betto call

yes

Send each action as data for abot to process.

Send via sendData han-dled by the GUI

yes

Page 53: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 6. RESULTS 45

Bot Development Requirements

Requirement Description Test Input / Test Vali-dation

Success

Allow bots to play and connectin the same fashion as a hu-man would.

This is true as the hu-man class is essentiallyan empty bot class

yes

Provide a method for the botthat will receive all actions au-tomatically.

This was supported bythe method getData inthe bot class

yes

Call a method in the bot classwhen it is the bots turn to act.

This method is calledDecide

yes

Provide a method to retrievehole cards within the bot class.

This method is calledgetHand

yes

Provide a template for the botclass with the required meth-ods to implement a bot in thissystem.

Called bot.java yes

Write a poker bot. I wrote two bots yesWrite a bot that calls every betbut otherwise will check.

Found in CallBot.java yes

Write a bot that acts randomlybut when it randomly decidesto bet or raise it raises a ran-dom amount between 2 and 20but only when it holds a highcard.

Found in DansBot.java yes

Write a more advanced botthat takes into account otherplayer traits.

Did not do no

User Interface Requirements

Requirement Description Test Input / Test Vali-dation

Success

Provide a way for the user tointeract with the system.

Achieved via the GUI yes

Allow the user to be able toperform every action required.

Check, call, bet, raiseand fold all work

yes

Expand the user interface toprovide graphics to assist abetter look and feel

Only graphics in termsof buttons and menusand 1 picture waspresent

partially

Page 54: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 7

Conclusion

7.1 Achievements

This project was heavily focussed on coding and to have reached up to version 3 of myproject plan was an achievement. Therefore the following was achieved:

• Wrote a program that allowed people to play the game of no limit texas hold’em

• Coded the project to support 6 players in the same game

• Supported online play, thus allowing players to play over a network

• Provided an easy method to write a bot that can interact with the game

• Developed the system to allow bots to join in the same way a human does

• Wrote a template for a bot that will interact with the system, including a method thatreceives every action automatically

• Wrote a bot that’s strategy is to call any bet and check otherwise

• Wrote a more advanced bot that would act randomly and when it decided to raise itwould raise a random amount between 1 and 20 when it held a high card

• Every ’game requirement’ was met as specified in the requirements section

From testing it can be seen virtually every other functional requirements was also met andthe non function requirements 1, 2, 3, 7 were definately met because there is no reason tobelieve anything else is needed from a system to run this program, the program does notcrash and the program handles inaccurate responses. Point 3 was handled well because ittold people what they had done wrong and improved the speed of play. Points 4, 5 and 6were likely also met to an extent and not as fully as the others. For point 4 some userssaid the system was hard to use and these responses normally came from non programmersand non poker players who had maybe played poker once or twice but were wanting to testthe system.

46

Page 55: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 7. CONCLUSION 47

Non Functional Requirements

1. The end product should require a low specification. It should be capable of running onany machine that can support java applications. (Essential)

2. The system should have at least a reasonable fault tolerence and therefore does notlock up, crash or memory leak. (Essential)

3. The system should be robust by handling and responding to inaccurate responses sentby players or bots. (Important)

4. The end product should be easy to use and require very little learning for anyone thatplays poker. (Nice to have)

5. The systems components should be well encapsulated to accomodate changes in require-ments. (Nice to have)

6. There should be high cohesion within the system to make the system maintainable.(Nice to have)

7. The development and playability of a bot should be flexible within the system. (Essen-tial)

7.2 Project Analysis

We believe the project was succesful and achieved its main aims and some secondary aims.Although it did complete every aim the project was always set out to allow room for any givenpace fast or slow. Perhaps some areas were overlooked in the complexity, one particulararea would be the sending of messages throughout the system. Within the game itself wherethere are only a few decisions to handle although situations can arise whereby a playermakes a bet and someone re-raises, then the game needs to insure the original raiser isallowed to act again and that they know that the bet to call is (the re-raise minus their bet).Also if someone were to bet 35 the minimum raise is now 35 and the system handled allthese complications. The bot class is particularly pleasing as it is kept simple and shouldallow for someone with little programming skills to write their own bot, this view is alsoreflected by those that tested the system. In the bot class it had just three methods, andonly one required code with as little as two lines of code for it to work. Therefore it appearsthe bot creation process is flexibile and simple for someone to do. Although the main aimwas acheived there were other secondary goals that were not complete. A complex bot wasnot written although a bot was written that makes a decision based on its cards but it isstill very primitive. The GUI was not developed as thorough as one might have liked, whichbrings me on to the discussion of futher enhancements that could be made to the system.

Page 56: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 7. CONCLUSION 48

7.3 Further Enhancements

The further enhancements that would be made are firstly to complete bot development andto improve the GUI. It would be useful to have add graphics into the game allowing playersto see images of the cards. User testing showed that some people found it hard to followthe game due to there being alot of text. This could certainely could be solved by usinggraphics in some places. Other than that a good feature for this project would be analysison the players play. If this project is used for its purpose of developing and testing bots ananalysis on win rate, percentage of hands played and other meaningful stats would proveuseful similar to that of hold’em manager (Hold’em-Manager, 2008) and poker tracker(Poker-Tracker, 2008). Also a feature to run a set number of hands without any outputother than the end analysis when all players are bots would be a good feature for quick bottesting. This would allow bots to play thousands of hands in a short space of time andwould enable people to make quicker conclusions about a bots level of play. Additionally atimeout feature would be useful in the case a bot is programmed to make a wrong decisionand then does nothing after and in the case a human player leaves his computer during thegame. This feature would keep the game going and on any online poker site it would beconsidered essential. Furthermore one user mentioned the following:

”I think it would be useful to have three separate areas in the program. One for pokeroutput, one for chatting and one for debug output.”

This appears to be good advice, as the main problem was a cluttered screen of text, the pointbeing made that when people chat during the game there is even more text in one place.This is definately a good further enhancement for the project, that is seperating chat andgame information.

7.4 Final Words

This project has provided not just what it was designed to do but has set up the framework todevelop into what other software products have done, perhaps by producing hand historiesit could expand across all areas. The difference is these other software products haven’tventured into bot development, and it could be that there is alot to learn and alot more tocome over the next couple of year in advancedments in bot development at 6-max no limittexas hold’em.

Page 57: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Bibliography

Angelo, T. (2007), The Elements of Poker, Tommy Angelo.

Bluff-Bot (2008), ‘Bluff bot’, http: // www. bluffbot. com/ online/ play. php .

Crowson, A. (2008), ‘The poker robots: More than meets the eye?’.

Darse Billings, Aaron Davidson, J. S. and Szafron, D. (2001), ‘The challenge of poker’.

Davidson, A. (2002), ‘Opponent modeling in poker: Learning and acting in a hostile anduncertain environment’.

Deuces-Cracked (2008), ‘Deuces cracked’, http: // www. deucescracked. com .

Galfond, P. (2007), ‘G-bucks’.

Hold’em-Manager (2008), ‘Hold’em manager’, http: // www. pokertracker. com .

Kan, M. H. (2007), ‘Postgame analysis of poker decisions’.

Poker-Academy (2008), ‘Poker academy’, http: // www. poker-academy. com .

Poker-Tracker (2008), ‘Poker tracker’, http: // www. pokertracker. com .

RPS-Consulting (2008), ‘Poker stove’, http: // www. pokerstove. com .

Sklansky, D. (1999), The Theory of Poker, 3rd Edition, Two Plus Two Publishing LLC.

Sklansky, D. and Miller, E. (2007), No Limit Hold’em Theory and Practice, second print,Two Plus Two Publishing LLC.

Two-Dimes (2008), ‘Two dimes’, http: // twodimes. net/ poker/ .

University of Alberta (2008), http: // poker. cs. ualberta. ca .

Wikipedia (2008a), ‘Pot odds’, http: // en. wikipedia. org/ wiki/ Pot_ odds .

Wikipedia (2008b), ‘World series of poker’, http: // en. wikipedia. org/ wiki/ World_

Series_ of_ Poker .

Win-Hold’em (2008), ‘Win hold’em poker bot’, http: // www. brothersoft. com/

winholdem-64805. html .

www.Poker.com (2008), ‘The history of poker’, http: // www. poker. com/

history-of-poker. htm .

www.PokerListings.com (2008), ‘Poker listings’, http: // www. pokerlistings. com/

market-pulse/ general-stats .

49

Page 58: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 8

User Documentation

To start a game of poker firstly you will have to load a class that inherits from the classUser. If you wish to play as a human, browse to the directory the code is saved to incommand prompt and type ’java Human’. This will load a box which needs to be resized. Ifyou wish to be a bot you can type ’java CallBot’, java ’DansBot’ or if you made your ownbot just run that instead. Once one of these classes have been run you will see a window asshown on the following page as step 1

The next step is to click on connect and then choose either to be a server or a client. Torun a game you will need one server and 5 clients. The server will be dealt in the gameso designate one player to host the game. If you are a server you will have to enter theport number and please ensure you have allowed access through this port on any firewallyou may have. Also choose a port that is free for use, I reccommend a port over 3000. Ifyou are a client you will have to enter an IP address as well as the port number as shownon the following page as step 2

Once connected it is best to resize the bot to ensure you can see all the buttons. There isa known problem with buttons dissapearing which can be resolved with resizing the window,also there is a need to scroll as the game does not self scroll. Once all the players or botshave connected the server is required to click ’start’. This will start the game and dealeveryone a hand, when you are dealt a hand remember the blinds are counted as a bet soany bet placed bigger than the big blind is a raise. If a player loses their stack, it is best forthe server to click ’start’ this will re-deal a hand but reset everyones stack size to 200. Thefirst 5 clients to join the server will be the players dealt in the hand therefore if players arejoining to observe they will need to join after the players.

50

Page 59: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 8. USER DOCUMENTATION 51

Figure 8.1: Step 1

Figure 8.2: Step 2

Page 60: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 9

User Feedback Results

52

Page 61: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 9. USER FEEDBACK RESULTS 53

1

Page 62: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 9. USER FEEDBACK RESULTS 54

2

Page 63: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 9. USER FEEDBACK RESULTS 55

3

Page 64: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 9. USER FEEDBACK RESULTS 56

4

Page 65: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 9. USER FEEDBACK RESULTS 57

5

Page 66: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 9. USER FEEDBACK RESULTS 58

6

Page 67: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 9. USER FEEDBACK RESULTS 59

7

Page 68: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CHAPTER 9. USER FEEDBACK RESULTS 60

8

Page 69: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

Chapter 10

Code

• Bot.java - The template class for a bot

• CallBot.java - An implementation of a bot that calls any bet otherwise will check

• Card.java - Holds the value of a card

• Client.java - The code used to connect as a client to the server

• DansBot.java - A more advanced implementation of a bot

• Game.java - The Game class, proccesses the poker game

• GUI.java - Displays the interface and handles user input

• GUIConnection.java - Displays the box to specify the IP address and port number

• Human.java - The class to be run when playing as a human

• Player.java - Stores details about a player e.g. stack size

• Server.java - The code used to connect as a server

• ThreadClass.java - Implements threading to allow multiple clients to connect to theserver

• User.java - Super class of both bot and human class

61

Page 70: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

6210.1 File: Bot.java

/∗ This c l a s s i s t he t emp la t e f o r someone to de v e l op et h e i r own bo t .

I t connec t s t he same way as a user would ∗/

pub l i c c l a s s Bot extends User {pr iva te in t num, x , va lue1 , va l ue2 ;pr iva te GUI gu i ;pr iva te Card card1 , card2 ;

pub l i c s t a t i c void main ( S t r i n g [ ] a rg s ) {Bot bo t = new Bot ( ) ;

}

pub l i c Bot ( ) {// c r e a t e s t he GUIgu i = new GUI( t h i s ) ;

}

pub l i c void setNum( in t num) {// the b o t s user i dt h i s . num = num;

}

/∗ This method i s c a l l e d when i t i s t h e bo t ’ s turn .The method needs to end wi th gu i . sendMsg ( x )Where X i s ”9” then the i n t e g e r num f o l l ow e d by

” che ” , ” c a l ” , ” b e t ” , ” r a i ” or ” f o l ”f o l l ow e d by the b e t or r a i s e amount i f a p p l i c a b l e

∗/pub l i c void Decide ( ) {

}

/∗ This method i s c a l l e d a u t oma t i c a l l y f o r eachac t i on .

Data i s s en t to t h i s method in the f o l l o w i n gformat :

− User ID : The user t h a t d id the a c t i on− Dec i s ion : The us e r s dec i s i on , where the f i r s t 3

c ha r a c t e r s r e p r e s en tt he a c t i o n s check , c a l l , be t , r a i s e or f o l d

(” che ” , ” c a l ” , ” b e t ” , ” r a i ” or ” f o l ”)

− Amount : The amount t h a t was b e t or r a i s e d i fa p p l i c a b l e ∗/

pub l i c void getData ( S t r i n g UserID , S t r i n gDecis ion , S t r i n g Amount) {

}

pub l i c in t conve r t ( S t r i n g s ) {i f ( s . e q u a l s ( ”T” ) ) {

return 10 ;}i f ( s . e q u a l s ( ”Q” ) ) {

return 11 ;}i f ( s . e q u a l s ( ”K” ) ) {

return 12 ;}i f ( s . e q u a l s ( ”A” ) ) {

return 13 ;}i f ( s . e q u a l s ( ”9” ) ) {

return 9 ;}i f ( s . e q u a l s ( ”8” ) ) {

return 8 ;}i f ( s . e q u a l s ( ”7” ) ) {

return 7 ;}i f ( s . e q u a l s ( ”6” ) ) {

return 6 ;}i f ( s . e q u a l s ( ”5” ) ) {

return 5 ;}i f ( s . e q u a l s ( ”4” ) ) {

return 4 ;}i f ( s . e q u a l s ( ”3” ) ) {

return 3 ;}i f ( s . e q u a l s ( ”2” ) ) {

return 2 ;}return 0 ;

Page 71: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

63}

pub l i c void getHand ( S t r i n g to , S t r i n g v1 , S t r i n gs1 , S t r i n g v2 , S t r i n g s2 ) {x = In t e g e r . p a r s e In t ( to ) ;va l ue1 = conver t ( v1 ) ;va l ue2 = conver t ( v2 ) ;i f (num == x ) {

card1 . s e tVa lue ( va lue1 ) ;card1 . s e t S u i t ( I n t e g e r . p a r s e In t ( s1 ) ) ;card2 . s e tVa lue ( va lue2 ) ;card2 . s e t S u i t ( I n t e g e r . p a r s e In t ( s2 ) ) ;

}}

}

10.2 File: CallBot.java

pub l i c c l a s s Cal lBot extends User {pr iva te in t num, x , va lue1 , va l ue2 ;pr iva te GUI gu i ;pr iva te S t r i n g l a s tD e c i s i o n ;pr iva te Card card1 , card2 ;

pub l i c s t a t i c void main ( S t r i n g [ ] a rg s ) {Cal lBot c a l l b o t = new Cal lBot ( ) ;

}

pub l i c Cal lBot ( ) {gu i = new GUI( t h i s ) ;

}

pub l i c void setNum( in t num) {t h i s . num = num;

}

pub l i c void Decide ( ) {i f ( l a s tD e c i s i o n . e q ua l s ( ” che ” ) ) {

gu i . sendMsg ( ”9” + t h i s . num + ”che ” ) ;} e l s e i f ( ( l a s tD e c i s i o n . e q ua l s ( ” b e t ” ) ) | |

( l a s tD e c i s i o n . e q ua l s ( ” c a l ” ) ) | |( l a s tD e c i s i o n . e q ua l s ( ” r a i ” ) ) ) {

gu i . sendMsg ( ”9” + t h i s . num + ” ca l ” ) ;

gu i . sendMsg ( ”9” + t h i s . num + ”che ” ) ;}i f ( l a s tD e c i s i o n . e q ua l s ( ” f o l ” ) ) {

gu i . sendMsg ( ”9” + t h i s . num + ”che ” ) ;gu i . sendMsg ( ”9” + t h i s . num + ” ca l ” ) ;

}}

pub l i c void getData ( S t r i n g UserID , S t r i n gDecis ion , S t r i n g Amount) {l a s tD e c i s i o n = Dec i s ion ;

}

pub l i c void getHand ( S t r i n g to , S t r i n g v1 , S t r i n gs1 , S t r i n g v2 , S t r i n g s2 ) {

x = In t e g e r . p a r s e In t ( to ) ;i f ( v1 . e q ua l s ( ”T” ) ) {

va lue1 = 10 ;}i f ( v1 . e q ua l s ( ”Q” ) ) {

va lue1 = 11 ;}i f ( v1 . e q ua l s ( ”K” ) ) {

va lue1 = 12 ;}i f ( v1 . e q ua l s ( ”A” ) ) {

va lue1 = 13 ;}i f ( v2 . e q ua l s ( ”T” ) ) {

va lue2 = 10 ;}i f ( v2 . e q ua l s ( ”Q” ) ) {

va lue2 = 11 ;}i f ( v2 . e q ua l s ( ”K” ) ) {

va lue2 = 12 ;}i f ( v2 . e q ua l s ( ”A” ) ) {

va lue2 = 13 ;}

i f (num == x ) {card1 = new Card ( ) ;card2 = new Card ( ) ;card1 . s e tVa lue ( va lue1 ) ;card1 . s e t S u i t ( I n t e g e r . p a r s e In t ( s1 ) ) ;

Page 72: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

64card2 . s e tVa lue ( va lue2 ) ;card2 . s e t S u i t ( I n t e g e r . p a r s e In t ( s2 ) ) ;

}}

}

10.3 File: Card.java

pub l i c c l a s s Card {in t s u i t , v a l u e ;

pub l i c void s e tVa lue ( in t v ) {va l u e = v ;

}

pub l i c void s e t S u i t ( in t s ) {s u i t = s ;

}

pub l i c in t ge tVa lue ( ) {return va l u e ;

}

pub l i c in t g e t S u i t ( ) {return s u i t ;

}

pub l i c char ge tSu i tC ( ) {i f ( s u i t == 0) {

return ’ c ’ ;}i f ( s u i t == 1) {

return ’ d ’ ;}i f ( s u i t == 2) {

return ’ h ’ ;}i f ( s u i t == 3) {

return ’ s ’ ;}return 0 ;

}

pub l i c char getValueC ( ) {i f ( va l u e == 2) {

return ’ 2 ’ ;}i f ( va l u e == 3) {

return ’ 3 ’ ;}i f ( va l u e == 4) {

return ’ 4 ’ ;}i f ( va l u e == 5) {

return ’ 5 ’ ;}i f ( va l u e == 6) {

return ’ 6 ’ ;}i f ( va l u e == 7) {

return ’ 7 ’ ;}i f ( va l u e == 8) {

return ’ 8 ’ ;}i f ( va l u e == 9) {

return ’ 9 ’ ;}i f ( va l u e == 10) {

return ’T ’ ;}i f ( va l u e == 11) {

return ’ J ’ ;}i f ( va l u e == 12) {

return ’Q ’ ;}i f ( va l u e == 13) {

return ’K ’ ;}i f ( va l u e == 14) {

return ’A ’ ;}return 0 ;

}}

Page 73: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

6510.4 File: Client.java

/∗Cred i t goes to ” In t r o du c t i on to JAVA ProgrammingThird Edi t ion , Y. Danie l Liang .”

This i s t he th read c r ea t e d by the c l i e n t . I t i n t e r a c t sw i th the ThreadClass t h r ead s

and t h e r e f o r e has s im i l a r i n s t anc e v a r i a b l e s andmethods .

The base code was Writ ten By Tom L i t t l e March 2006 , Iadapted i t to s u i t my p r o j e c t w i th h i s permis s ion∗/

import j a va . u t i l . Date ;import j a va . ne t . ∗ ;import j a va . i o . ∗ ;

c la s s c l i e n t extends Thread{

pr iva te S t r i n g user , IPAddress , message ;pr iva te in t portNUM , number , x ;pr iva te Socke t Sock ;pr iva te Buf feredReader b u f f ;pr iva te InputStream in ;pr iva te OutputStream out ;pr iva te Prin tWri ter p i n t e r ;pr iva te GUI gu i ;

// Cons t ruc tor save s the por t number , IPAddressand GUI in s t anc e

pub l i c c l i e n t ( in t portNUM , S t r i n g IPAddress ,GUI gu i )

{t h i s . portNUM = portNUM ;t h i s . IPAddress = IPAddress ;t h i s . gu i = gu i ;

}

pub l i c void run ( ){

try {

//new Socke t g e t s accep t ed bySe r v e rSocke t in s e r v e r . j a va

Sock = new Socke t ( IPAddress ,portNUM) ;

in = Sock . ge t InputS t ream () ;out = Sock . getOutputStream () ;

//Read and wr i t e d e v i s e sp i n t e r = new Prin tWri ter ( out ,

true ) ;b u f f = new Buf feredReader (new

InputStreamReader ( in ) ) ;

/∗Objec t inpu t stream acc ep t st he Date ( ) Ob jec t s en t

by the Ob jec t ou tpu t stream inThreadClass which i s then

wrapped and save s as ” da te ”∗/Objec t InputStream oin = new

Objec t InputStream ( in ) ;Date da te =

( Date ) oin . r eadOb jec t ( ) ;

//This reads the c l i e n t s indexnumber and save s i t

DataInputStream d i s = newDataInputStream ( in ) ;

number = d i s . r ead In t ( ) ;

gu i . Rec ieve ( ”\nYou are C l i e n t” + number + ” : Connecteda t ” + date . t o S t r i n g ( ) +” . . . ” ) ;

/∗This method save s the c l i e n tindex number in the GUI sot h a t

i t can p r i n t t he c l i e n t andi t s number in the t e x tarea ∗/

gu i . Number ( number ) ;

gu i . Rec ieve ( ”\ n99Please t ypeyour t e x t your wish tosend in the bottom t e x t

Page 74: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

66box . I f you wish to q u i tt h e connect ion , p l e a s ep r e s s ’ Quit ’ or t ype’ q u i t ’ ” ) ;

// l e t s t h e user inpu t t e x tgu i . setME( true ) ;

x = 5 ;whi le ( x == 5) {

// t h i s r e c i e v e s anyt e x t s en t

message =b u f f . readLine ( ) ;

i f ( message . e q ua l s ( ” q u i t ” ) ) {gu i . Rec ieve ( ”99The

s e r v e r hasc l o s e d .You arenowd i sconnec ted ,goodbye . . . ” ) ;

out . f l u s h ( ) ;Sock . c l o s e ( ) ;gu i . d i s p o s e ( ) ; // c l o s e s

GUIx = 6 ;

// b r eak sl oop

}

// t h i s p r i n t s t her e c i e v e d message

i f ( message . l e n g t h ( ) <3) {

gu i . Rec ieve ( message ) ;} e l s e {S t r i n g s = message . s u b s t r i n g (0 ,1 ) ;S t r i n g s2 = message . s u b s t r i n g (1 ,2 ) ;i f ( s . e q u a l s ( ”0” ) | | s . e q ua l s ( ”1” ) | |

s . e q u a l s ( ”2” ) | | s . e q ua l s ( ”3” ) | |

s . e q ua l s ( ”4” ) | | s . e q ua l s ( ”5” ) | |s . e q ua l s ( ”6” ) | | s . e q ua l s ( ”7” ) | |s . e q ua l s ( ”8” ) | | s . e q ua l s ( ”9” ) ) {gu i . RecieveMsg ( message . s u b s t r i n g (2) , s ,

s2 ) ;i f ( s . e q u a l s ( ”8” ) ) {

gu i . RecieveData ( message . s u b s t r i n g (1 ,2 ) ,message . s u b s t r i n g (2 ,5 ) ,message . s u b s t r i n g (5) ) ;

}i f ( s2 . e q u a l s ( ”7” ) ) {

gu i . RecieveHand ( message . s u b s t r i n g (0 ,1 ) ,message . s u b s t r i n g (2 ,3 ) ,message . s u b s t r i n g (3 ,4 ) ,message . s u b s t r i n g (4 ,5 ) ,message . s u b s t r i n g (5 ,6 ) ) ;

}} e l s e {

gu i . Rec ieve ( message ) ;}

}// f l u s h e s

b u f f e r . .out . f l u s h ( ) ;

}

} catch ( UnknownHostException uhe ) {gu i . Rec ieve ( ”Error :

Cannot f i n d theho s t . ” ) ;

} catch ( IOExcept ion i o e ) {gu i . Rec ieve ( ”Error :

Cannot connect tothe ho s t . ” ) ;

} catch ( ClassNotFoundExcept ion cn f e ) {gu i . Rec ieve ( ”C las s Not

Found Except ion ” ) ;}

} //end o f run ( )

Page 75: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

67//Used to send t e x t to the ThreadClass t h r ead spub l i c void Send ( S t r i n g s t r i n g ){

// Pr in tWri terp i n t e r . p r i n t l n ( s t r i n g ) ;

/∗ I f t h e c l i e n t has chosen to q u i t i tc l o s e s t he s o c k e t

and d i s p o s e s o f t he GUI and break s thel oop ∗/

try {i f ( s t r i n g . e q u a l s ( ” q u i t ” ) )

{Sock . c l o s e ( ) ;gu i . d i s p o s e ( ) ;x = 6 ;

}

} catch ( IOExcept ion i o e e ) {

}}

} //end o f c l a s s

10.5 File: DansBot.java

import j a va . u t i l . Random ;

pub l i c c l a s s DansBot extends User {pr iva te in t num, x , va lue1 , va l ue2 ;pr iva te GUI gu i ;pr iva te S t r i n g l a s tD e c i s i o n ;pr iva te Card card1 , card2 ;

pub l i c s t a t i c void main ( S t r i n g [ ] a rg s ) {DansBot dansbo t = new DansBot ( ) ;

}

pub l i c DansBot ( ) {gu i = new GUI( t h i s ) ;

}

pub l i c void setNum( in t num) {t h i s . num = num;card1 = new Card ( ) ;card2 = new Card ( ) ;

}

pub l i c void Decide ( ) {Random genera to r = new Random() ;in t r = gene ra to r . n e x t I n t (20) ;Random genera to r2 = new Random() ;in t r2 = genera to r2 . n e x t I n t (20) ;i f ( r2 < 10) {

i f ( ( card1 . ge tVa lue ( ) > 10) | |( card2 . ge tVa lue ( ) > 10) ) {

gu i . sendMsg ( ”9” + t h i s . num + ” ra i ” +r ) ;

gu i . sendMsg ( ”9” + t h i s . num + ” be t ” +r ) ;

gu i . sendMsg ( ”9” + t h i s . num + ” ca l ” ) ;gu i . sendMsg ( ”9” + t h i s . num + ”che ” ) ;

}} e l s e {

gu i . sendMsg ( ”9” + t h i s . num + ” ca l ” ) ;gu i . sendMsg ( ”9” + t h i s . num + ”che ” ) ;

}}

pub l i c void getData ( S t r i n g UserID , S t r i n gDecis ion , S t r i n g Amount) {l a s tD e c i s i o n = Dec i s ion ;

}

pub l i c in t conve r t ( S t r i n g s ) {i f ( s . e q u a l s ( ”T” ) ) {

return 10 ;}i f ( s . e q u a l s ( ”Q” ) ) {

return 11 ;}i f ( s . e q u a l s ( ”K” ) ) {

return 12 ;}i f ( s . e q u a l s ( ”A” ) ) {

Page 76: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

68return 13 ;

}i f ( s . e q u a l s ( ”9” ) ) {

return 9 ;}i f ( s . e q u a l s ( ”8” ) ) {

return 8 ;}i f ( s . e q u a l s ( ”7” ) ) {

return 7 ;}i f ( s . e q u a l s ( ”6” ) ) {

return 6 ;}i f ( s . e q u a l s ( ”5” ) ) {

return 5 ;}i f ( s . e q u a l s ( ”4” ) ) {

return 4 ;}i f ( s . e q u a l s ( ”3” ) ) {

return 3 ;

}i f ( s . e q u a l s ( ”2” ) ) {

return 2 ;}return 0 ;

}

pub l i c void getHand ( S t r i n g to , S t r i n g v1 , S t r i n gs1 , S t r i n g v2 , S t r i n g s2 ) {x = In t e g e r . p a r s e In t ( to ) ;va l ue1 = conver t ( v1 ) ;va l ue2 = conver t ( v2 ) ;i f (num == x ) {

card1 . s e tVa lue ( va lue1 ) ;card1 . s e t S u i t ( I n t e g e r . p a r s e In t ( s1 ) ) ;card2 . s e tVa lue ( va lue2 ) ;card2 . s e t S u i t ( I n t e g e r . p a r s e In t ( s2 ) ) ;

}}

}

10.6 File: Game.java

/∗ This c l a s s i s r e s p o n s i b l e f o r p r o c e s s i n g the game ∗/

import j a va . awt . ∗ ;import j a va . awt . e ven t . ∗ ;import j a va . i o . ∗ ;import j a va . l ang . ∗ ;import j a va . u t i l . ∗ ;

pub l i c c l a s s Game {pr iva te GUI gu i = new GUI( nu l l ) ;Card [ ] card = new Card [ 5 2 ] ;Card [ ] f l o p = new Card [ 3 ] ;Card turn = new Card ( ) ;Card r i v e r = new Card ( ) ;P layer [ ] p l a y e r = new Player [ 6 ] ;in t [ ] p l a y e rBe t s = new in t [ 6 ] ;in t [ ] p l ayerChecks = new in t [ 6 ] ;

Page 77: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

69in t [ ] p l aye rAc ted = new in t [ 6 ] ;in t [ ] playerHandRank = new in t [ 6 ] ;in t [ ] [ ] p layerHand = new in t [ 6 ] [ 6 ] ;in t t o t a lBe t , pot , rAmountMax ;in t dea l e rPos = −1;in t sma l lB l i nd = 0 ;in t b i gB l i n d = 1 ;in t UTG = 2;in t MP = 3;in t CO = 4;in t playerGo = −1;in t a l l I n s ;in t pos ;in t s t r e e t ;boolean wrongInput ;

pub l i c void game ( ) {

}

pub l i c void setGUI (GUI g ) {gu i = g ;

}

pub l i c void sendMsg ( S t r i n g msg ) {gu i . sendMessage (msg ) ;

}

pub l i c void c r e a t eP l a y e r s ( in t num) {in t n = 0 ;for (n = 0 ; n < num; n++){

// c r e a t e s n number o f p l a y e r s w i th 200 ch i p sp l a y e r [ n ] = new Player (200) ;

}}

/∗ t h i s method g ene ra t e s an array o f cards , which ho l d s a 52 card deck ∗/pub l i c void genera teCards ( ) {

in t x , y , z = 0 ;

for ( x = 2 ; x < 15 ; x++) {for ( y = 0 ; y < 4 ; y++) {

card [ z ] = new Card ( ) ;card [ z ] . s e tVa lue ( x ) ;

Page 78: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

70card [ z ] . s e t S u i t ( y ) ;z = z + 1 ;

}}

}

pub l i c void s h u f f l e ( ) {in t z ;C o l l e c t i o n s . s h u f f l e ( Arrays . a sL i s t ( card ) ) ;

}

/∗ Al l cards are d e a l t bu t t he f l o p , turn and r i v e r are not r e v e a l e d u n t i l needed ∗/pub l i c void dea l ( ) {

p l a y e r [ 0 ] . newHand( card [ 0 ] , card [ 1 ] ) ;p l a y e r [ 1 ] . newHand( card [ 2 ] , card [ 3 ] ) ;p l a y e r [ 2 ] . newHand( card [ 4 ] , card [ 5 ] ) ;p l a y e r [ 3 ] . newHand( card [ 6 ] , card [ 7 ] ) ;p l a y e r [ 4 ] . newHand( card [ 8 ] , card [ 9 ] ) ;p l a y e r [ 5 ] . newHand( card [ 1 0 ] , card [ 1 1 ] ) ;f l o p [ 0 ] = card [ 1 2 ] ;f l o p [ 1 ] = card [ 1 3 ] ;f l o p [ 2 ] = card [ 1 4 ] ;turn = card [ 1 5 ] ;r i v e r = card [ 1 6 ] ;

}

/∗ send messages to a l l u s e r s what t he f l o p i s ∗/pub l i c void dea lF l op ( ) {

gu i . sendMsg ( ”99FLOP: ” + f l o p [ 0 ] . getValueC () + f l o p [ 0 ] . g e tSu i tC ( ) + ” ” + f l o p [ 1 ] . getValueC () +f l o p [ 1 ] . g e tSu i tC ( ) + ” ” + f l o p [ 2 ] . getValueC () + f l o p [ 2 ] . g e tSu i tC ( ) + ”\n” ) ;

gu i . sendData ( ”89 che0 ” ) ;}

/∗ send messages to a l l u s e r s what t he turn i s ∗/pub l i c void dealTurn ( ) {

gu i . sendMsg ( ”99TURN: ” + turn . getValueC () + turn . ge tSu i tC ( ) + ”\n” ) ;gu i . sendData ( ”89 che0 ” ) ;

}

/∗ send messages to a l l u s e r s what t he r i v e r i s ∗/pub l i c void dea lR i v e r ( ) {

gu i . sendMsg ( ”99RIVER: ” + r i v e r . getValueC () + r i v e r . g e tSu i tC ( ) + ”\n” ) ;gu i . sendData ( ”89 che0 ” ) ;

}

Page 79: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

71/∗ send messages to each p l a y e r t e l l i n g them what t h e i r cards are ∗/pub l i c void showCards ( ) {

S t r i n g s , s2 ;gu i . sendMsg ( ”99Your ho l e cards are . . . ” ) ;s = ”09” + p l a y e r [ 0 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 0 ] . p layerCards [ 0 ] . g e tSu i tC ( ) + ” ” +

p l a y e r [ 0 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 0 ] . p l ayerCards [ 1 ] . g e tSu i tC ( ) + ”\n” ;s2 = ”07” + p l a y e r [ 0 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 0 ] . p layerCards [ 0 ] . g e t S u i t ( ) +

p l a y e r [ 0 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 0 ] . p l ayerCards [ 1 ] . g e t S u i t ( ) + ”\n” ;gu i . sendMsg ( s ) ;gu i . sendHand ( s2 ) ;s = ”19” + p l a y e r [ 1 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 1 ] . p layerCards [ 0 ] . g e tSu i tC ( ) + ” ” +

p l a y e r [ 1 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 1 ] . p l ayerCards [ 1 ] . g e tSu i tC ( ) + ”\n” ;s2 = ”17” + p l a y e r [ 1 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 1 ] . p layerCards [ 0 ] . g e t S u i t ( ) +

p l a y e r [ 1 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 1 ] . p l ayerCards [ 1 ] . g e t S u i t ( ) + ”\n” ;gu i . sendMsg ( s ) ;gu i . sendHand ( s2 ) ;s = ”29” + p l a y e r [ 2 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 2 ] . p layerCards [ 0 ] . g e tSu i tC ( ) + ” ” +

p l a y e r [ 2 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 2 ] . p l ayerCards [ 1 ] . g e tSu i tC ( ) + ”\n” ;s2 = ”27” + p l a y e r [ 2 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 2 ] . p layerCards [ 0 ] . g e t S u i t ( ) +

p l a y e r [ 2 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 2 ] . p l ayerCards [ 1 ] . g e t S u i t ( ) + ”\n” ;gu i . sendMsg ( s ) ;gu i . sendHand ( s2 ) ;s = ”39” + p l a y e r [ 3 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 3 ] . p layerCards [ 0 ] . g e tSu i tC ( ) + ” ” +

p l a y e r [ 3 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 3 ] . p l ayerCards [ 1 ] . g e tSu i tC ( ) + ”\n” ;s2 = ”37” + p l a y e r [ 3 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 3 ] . p layerCards [ 0 ] . g e t S u i t ( ) +

p l a y e r [ 3 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 3 ] . p l ayerCards [ 1 ] . g e t S u i t ( ) + ”\n” ;gu i . sendMsg ( s ) ;gu i . sendHand ( s2 ) ;s = ”49” + p l a y e r [ 4 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 4 ] . p layerCards [ 0 ] . g e tSu i tC ( ) + ” ” +

p l a y e r [ 4 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 4 ] . p l ayerCards [ 1 ] . g e tSu i tC ( ) + ”\n” ;s2 = ”47” + p l a y e r [ 4 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 4 ] . p layerCards [ 0 ] . g e t S u i t ( ) +

p l a y e r [ 4 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 4 ] . p l ayerCards [ 1 ] . g e t S u i t ( ) + ”\n” ;gu i . sendMsg ( s ) ;gu i . sendHand ( s2 ) ;s = ”59” + p l a y e r [ 5 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 5 ] . p layerCards [ 0 ] . g e tSu i tC ( ) + ” ” +

p l a y e r [ 5 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 5 ] . p l ayerCards [ 1 ] . g e tSu i tC ( ) + ”\n” ;s2 = ”57” + p l a y e r [ 5 ] . p layerCards [ 0 ] . getValueC () + p l a y e r [ 5 ] . p layerCards [ 0 ] . g e t S u i t ( ) +

p l a y e r [ 5 ] . p layerCards [ 1 ] . getValueC ( ) + p l a y e r [ 5 ] . p l ayerCards [ 1 ] . g e t S u i t ( ) + ”\n” ;gu i . sendMsg ( s ) ;gu i . sendHand ( s2 ) ;

}

/∗ This method i s c a l l e d on showdown ∗/pub l i c void showHand ( in t p ) {

i f ( playerHandRank [ p ] == 0) {

Page 80: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

72gu i . sendMsg ( ”99 Player ” + p + ” has h i gh card : ” + playerHand [ p ] [ 0 ] + ” k i c k e r 1 : ” + playerHand [ p ] [ 1 ]

+ ” k i c k e r 2 : ” + playerHand [ p ] [ 2 ] + ” k i c k e r 3 : ” + playerHand [ p ] [ 3 ] + ” k i c k e r 4 : ” +playerHand [ p ] [ 4 ] + ”\n” ) ;

}i f ( playerHandRank [ p ] == 1) {

gu i . sendMsg ( ”99 Player ” + p + ” has a pa i r o f : ” + playerHand [ p ] [ 0 ] + ” k i c k e r 1 : ” + playerHand [ p ] [ 1 ]+ ” k i c k e r 2 : ” + playerHand [ p ] [ 2 ] + ” k i c k e r 3 : ” + playerHand [ p ] [ 3 ] + ” k i c k e r 4 : ” +playerHand [ p ] [ 4 ] + ”\n” ) ;

}i f ( playerHandRank [ p ] == 2) {

gu i . sendMsg ( ”99 Player ” + p + ” has two pa i r : ” + playerHand [ p ] [ 0 ] + ” ’ s and ” + playerHand [ p ] [ 1 ] +” ’ s ” + ” wi th k i c k e r : ” + playerHand [ p ] [ 2 ] + ”\n” ) ;

}i f ( playerHandRank [ p ] == 3) {

gu i . sendMsg ( ”99 Player ” + p + ” has t h r e e ” + playerHand [ p ] [ 0 ] + ” ’ s w i th k i c k e r 1 : ” +playerHand [ p ] [ 1 ] + ” k i c k e r 2 : ” + playerHand [ p ] [ 2 ] + ”\n” ) ;

}i f ( playerHandRank [ p ] == 4) {

gu i . sendMsg ( ”99 Player ” + p + ” has a s t r a i g h t ( ” + playerHand [ p ] [ 0 ] + ” ” + playerHand [ p ] [ 1 ] + ” ” +playerHand [ p ] [ 2 ] + ” ” + playerHand [ p ] [ 3 ] + ” ” + playerHand [ p ] [ 4 ] + ” ) \n” ) ;

}i f ( playerHandRank [ p ] == 5) {

gu i . sendMsg ( ”99 Player ” + p + ” has a ” + playerHand [ p ] [ 0 ] + ” h i gh f l u s h ” + ” ( ” + playerHand [ p ] [ 0 ]+ ” ” + playerHand [ p ] [ 1 ] + ” ” + playerHand [ p ] [ 2 ] + ” ” + playerHand [ p ] [ 3 ] + ” ” +playerHand [ p ] [ 4 ] + ” ) \n” ) ;

}i f ( playerHandRank [ p ] == 6) {

gu i . sendMsg ( ”99 Player ” + p + ” has a f u l l house ” + playerHand [ p ] [ 0 ] + ” ’ s f u l l o f ” +playerHand [ p ] [ 1 ] + ” ’ s \n” ) ;

}i f ( playerHandRank [ p ] == 7) {

gu i . sendMsg ( ”99 Player ” + p + ” has 4 o f a k ind ” + playerHand [ p ] [ 0 ] + ” wi th k i c k e r : ” +playerHand [ p ] [ 1 ] + ” ’ s \n” ) ;

}}

/∗ This method hand l e s t he showdown o f t he hand t a k i n g i n t o account s p l i t po t and who i s a b l e to muck t h e i rcards ∗/

pub l i c void checkWin ( ) {in t h i g h e s t = −1;in t playerNum = 0;in t tempPlayer = 0 ;in t x = −1;in t s p l i tCoun t = 0 ;in t sp l i tPotAmount = 0 ;

Page 81: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

73in t [ ] w inn ingP layer s = new in t [ 6 ] ;boolean s p l i t P o t = f a l s e ;boolean muck = true ; ;

i f ( p l a y e rBe t s [ sma l lB l i nd ] != −1) {checkHand ( sma l lB l i nd ) ;

}i f ( p l a y e rBe t s [ b i gB l i n d ] != −1) {

checkHand ( b i gB l i n d ) ;}i f ( p l a y e rBe t s [UTG] != −1) {

checkHand (UTG) ;}i f ( p l a y e rBe t s [MP] != −1) {

checkHand (MP) ;}i f ( p l a y e rBe t s [CO] != −1) {

checkHand (CO) ;}i f ( p l a y e rBe t s [ dea l e rPos ] != −1) {

checkHand ( dea l e rPos ) ;}

for ( in t a = 0 ; a < 6 ; a++) {muck = true ;i f ( x == CO) {

x = dea l e rPos ;}i f ( x == MP) {

x = CO;}i f ( x == UTG) {

x = MP;}i f ( x == b i gB l i n d ) {

x = UTG;}i f ( x == sma l lB l i nd ) {

x = b i gB l i n d ;}i f ( x == −1) {

x = sma l lB l i nd ;}

Page 82: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

74i f ( playerHandRank [ x ] == h i g h e s t ) {

tempPlayer = compareHand ( x , playerNum ) ;i f ( ( tempPlayer != playerNum ) && ( tempPlayer != −1) ) {

showHand ( tempPlayer ) ;muck = f a l s e ;

}i f ( tempPlayer != −1) {

playerNum = tempPlayer ;}i f ( tempPlayer == − 1) {

s p l i t P o t = true ;w inn ingP layer s [ x ] = 1 ;s p l i tCoun t++;

}}i f ( playerHandRank [ x ] > h i g h e s t ) {

for ( in t y = 0 ; y < 6 ; y++) {winn ingP layer s [ y ] = 0 ;

}s p l i t P o t = f a l s e ;playerNum = x ;h i g h e s t = playerHandRank [ x ] ;showHand ( playerNum ) ;muck = f a l s e ;

}i f (muck == true ) {

gu i . sendMsg ( ”99 Player ” + x + ” mucks\n” ) ;}

}i f ( s p l i t P o t == f a l s e ) {

gu i . sendMsg ( ”99 Player : ” + playerNum + ” wins ” + pot + ”\n” ) ;p l a y e r [ playerNum ] . s t a c k S i z e = p l a y e r [ playerNum ] . s t a c k S i z e + pot ;

} e l s e {for ( in t z = 0 ; z < 6 ; z++) {

i f ( w inn ingP layer s [ z ] == 1) {sp l i tPotAmount = ( pot / s p l i tCoun t ) ;gu i . sendMsg ( ”99 Player : ” + z + ” wins ” + sp l i tPotAmount + ” in a s p l i t po t ” ) ;p l a y e r [ z ] . s t a c k S i z e = p l a y e r [ z ] . s t a c k S i z e + sp l i tPotAmount ;

}}

}}

/∗ t h i s compares hands between p l a y e r s to f i n d the h i g h e s t rank hand ∗/pub l i c in t compareHand ( in t p1 , in t p2 ) {

Page 83: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

75for ( in t x = 0 ; x < 5 ; x++) {

i f ( playerHand [ p1 ] [ x ] > playerHand [ p2 ] [ x ] ) {return p1 ;

}i f ( playerHand [ p2 ] [ x ] > playerHand [ p1 ] [ x ] ) {

return p2 ;}

}return −1;

}

/∗ This method de termines a p l a y e r s b e s t 5 card hand ∗/pub l i c void checkHand ( in t x ) {in t [ ] ans = new in t [ 6 ] ;

ans = quads ( p l a y e r [ x ] . p l ayerCards [ 0 ] , p l a y e r [ x ] . p l ayerCards [ 1 ] ) ;i f ( ans [ 0 ] == 0) {

ans = f u l lHou s e ( p l a y e r [ x ] . p l ayerCards [ 0 ] , p l a y e r [ x ] . p l ayerCards [ 1 ] ) ;i f ( ans [ 0 ] == 0) {

ans = f l u s h ( p l a y e r [ x ] . p l ayerCards [ 0 ] , p l a y e r [ x ] . p l ayerCards [ 1 ] ) ;i f ( ans [ 0 ] == 0) {

ans = s t r a i g h t ( p l a y e r [ x ] . p l ayerCards [ 0 ] , p l a y e r [ x ] . p l ayerCards [ 1 ] , 0) ;i f ( ans [ 0 ] == 0) {

ans = s t r a i g h t ( p l a y e r [ x ] . p l ayerCards [ 0 ] , p l a y e r [ x ] . p l ayerCards [ 1 ] , 1) ;i f ( ans [ 0 ] == 0) {

ans = t r i p s o r S e t ( p l a y e r [ x ] . p l ayerCards [ 0 ] , p l a y e r [ x ] . p l ayerCards [ 1 ] ) ;i f ( ans [ 0 ] == 0) {

ans = twoPair ( p l a y e r [ x ] . p l ayerCards [ 0 ] , p l a y e r [ x ] . p l ayerCards [ 1 ] ) ;i f ( ans [ 1 ] == 0) {

ans = pa i r ( p l a y e r [ x ] . p l ayerCards [ 0 ] , p l a y e r [ x ] . p l ayerCards [ 1 ] ) ;i f ( ans [ 0 ] == 0) {

ans = highCard ( p l a y e r [ x ] . p l ayerCards [ 0 ] , p l a y e r [ x ] . p l ayerCards [ 1 ] ) ;playerHandRank [ x ] = 0 ;playerHand [ x ] [ 0 ] = ans [ 0 ] ;p layerHand [ x ] [ 1 ] = ans [ 1 ] ;p layerHand [ x ] [ 2 ] = ans [ 2 ] ;p layerHand [ x ] [ 3 ] = ans [ 3 ] ;p layerHand [ x ] [ 4 ] = ans [ 4 ] ;

} e l s e {playerHandRank [ x ] = 1 ;playerHand [ x ] [ 0 ] = ans [ 0 ] ;p layerHand [ x ] [ 1 ] = ans [ 1 ] ;p layerHand [ x ] [ 2 ] = ans [ 2 ] ;p layerHand [ x ] [ 3 ] = ans [ 3 ] ;p layerHand [ x ] [ 4 ] = ans [ 4 ] ;

Page 84: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

76}

} e l s e {playerHandRank [ x ] = 2 ;playerHand [ x ] [ 0 ] = ans [ 0 ] ;p layerHand [ x ] [ 1 ] = ans [ 1 ] ;p layerHand [ x ] [ 2 ] = ans [ 2 ] ;p layerHand [ x ] [ 3 ] = ans [ 3 ] ;p layerHand [ x ] [ 4 ] = ans [ 4 ] ;

}} e l s e {

playerHandRank [ x ] = 3 ;playerHand [ x ] [ 0 ] = ans [ 0 ] ;p layerHand [ x ] [ 1 ] = ans [ 1 ] ;p layerHand [ x ] [ 2 ] = ans [ 2 ] ;p layerHand [ x ] [ 3 ] = ans [ 3 ] ;p layerHand [ x ] [ 4 ] = ans [ 4 ] ;

}} e l s e {

playerHandRank [ x ] = 4 ;playerHand [ x ] [ 0 ] = ans [ 0 ] ;p layerHand [ x ] [ 1 ] = ans [ 1 ] ;p layerHand [ x ] [ 2 ] = ans [ 2 ] ;p layerHand [ x ] [ 3 ] = ans [ 3 ] ;p layerHand [ x ] [ 4 ] = ans [ 4 ] ;

}} e l s e {

playerHandRank [ x ] = 4 ;playerHand [ x ] [ 0 ] = ans [ 0 ] ;p layerHand [ x ] [ 1 ] = ans [ 1 ] ;p layerHand [ x ] [ 2 ] = ans [ 2 ] ;p layerHand [ x ] [ 3 ] = ans [ 3 ] ;p layerHand [ x ] [ 4 ] = ans [ 4 ] ;

}} e l s e {

playerHandRank [ x ] = 5 ;playerHand [ x ] [ 0 ] = ans [ 0 ] ;p layerHand [ x ] [ 1 ] = ans [ 1 ] ;p layerHand [ x ] [ 2 ] = ans [ 2 ] ;p layerHand [ x ] [ 3 ] = ans [ 3 ] ;p layerHand [ x ] [ 4 ] = ans [ 4 ] ;

}} e l s e {

playerHandRank [ x ] = 6 ;playerHand [ x ] [ 0 ] = ans [ 0 ] ;p layerHand [ x ] [ 1 ] = ans [ 1 ] ;

Page 85: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

77playerHand [ x ] [ 2 ] = ans [ 2 ] ;p layerHand [ x ] [ 3 ] = ans [ 3 ] ;p layerHand [ x ] [ 4 ] = ans [ 4 ] ;

}} e l s e {

playerHandRank [ x ] = 7 ;playerHand [ x ] [ 0 ] = ans [ 0 ] ;p layerHand [ x ] [ 1 ] = ans [ 1 ] ;p layerHand [ x ] [ 2 ] = ans [ 2 ] ;p layerHand [ x ] [ 3 ] = ans [ 3 ] ;p layerHand [ x ] [ 4 ] = ans [ 4 ] ;

}}

/∗ This method hand l e s a u s e r s dec i s i on , i t manages i n c o r r e c t inpu t as w e l l as managing b e t s made l a r g e r thana p l a y e r s s t a c k ∗/

pub l i c void d e c i s i o n ( ) {in t b e t ;in t rAmount = 0 ;in t inputID = 99;boolean nh = f a l s e ;

wrongInput = f a l s e ;

i f ( p l a y e rBe t s [ pos ] == −1 | | p l a y e r [ pos ] . s t a c k S i z e <= 0) {// p l a y e r has f o l d e d or has no s t a c k − do no th ingi f ( pos != dea l e rPos ) {

pos = increasePos ( pos ) ;i f ( p l a y e rBe t s [ pos ] == −1 | | p l a y e r [ pos ] . s t a c k S i z e == 0) {

} e l s e {gu i . sendMsg ( ”99 Player ” + pos + ” ( ” + p l a y e r [ pos ] . s t a c k S i z e + ” ) ” + ” to ac t : ” + ” Pot

S i z e : ” + pot + ” Bet to c a l l : ” + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;gu i . sendMsg ( pos + ”9Your turn ” ) ;

}d e c i s i o n ( ) ;

}} e l s e {

S t r i n g inpu t = new S t r i n g ( ) ;S t r i n g inputAmount = new S t r i n g ( ) ;

i npu t = gu i . l a s t ( ) ;inputID = gu i . l a s t ID ( ) ;i f ( inpu t . l e n g t h ( ) > 3) {

inputAmount = inpu t . s u b s t r i n g (3) ;i npu t = inpu t . s u b s t r i n g (0 ,3 ) ;

Page 86: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

78}System . out . p r i n t l n ( ”\nUser ” + inputID + ” inpu t : ” + inpu t + ”\n” ) ;i f ( inputID == pos ) {

i f ( ( inpu t . e q u a l s ( ” che ” ) ) | | ( inpu t . e q ua l s ( ” c a l ” ) ) | | ( inpu t . e q ua l s ( ” f o l ” ) ) | |( inpu t . e q ua l s ( ” b e t ” ) ) | | ( inpu t . e q ua l s ( ” r a i ” ) ) ) {

// Player Ca l l si f ( inpu t . e q ua l s ( ” c a l ” ) ) {

i f ( t o t a l B e t − p l a y e rBe t s [ pos ] > 0) { // i f t h e r e i s a b e t to c a l li f ( ( t o t a l B e t − p l a y e rBe t s [ pos ] ) >= p l a y e r [ pos ] . s t a c k S i z e ) { // i f t h e amount to c a l l i s

g r e a t e r than the s t a c k s i z ep l a y e rBe t s [ pos ] = p l a y e rBe t s [ pos ] + p l a y e r [ pos ] . s t a c k S i z e ;gu i . sendMsg ( ”99 Player ” + pos + ” Ca l l s ” + p l a y e r [ pos ] . s t a c k S i z e + ” and i s ALL−IN” ) ;gu i . sendData ( ”8” + pos + ” ca l ” + p l a y e r [ pos ] . s t a c k S i z e ) ;po t = pot + p l a y e r [ pos ] . s t a c k S i z e ;p l a y e r [ pos ] . s t a c k S i z e = 0 ;p l aye rAc ted [ pos ] = 1 ;

} e l s e {gu i . sendMsg ( ”99 Player ” + pos + ” Ca l l s ” + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;gu i . sendData ( ”8” + pos + ” ca l ” + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;p l a y e r [ pos ] . s t a c k S i z e = p l a y e r [ pos ] . s t a c k S i z e − ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ;po t = pot + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ;p l a y e rBe t s [ pos ] = p l a y e rBe t s [ pos ] + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ;p l aye rAc ted [ pos ] = 1 ;

}} e l s e {

gu i . sendMsg ( inputID + ”9” + ”There i s no b e t to c a l l ” ) ;wrongInput = true ;

}}

// Player Fo ldsi f ( inpu t . e q ua l s ( ” f o l ” ) ) {

i f ( t o t a l B e t == 0) {gu i . sendMsg ( inputID + ”9” + ”You can check ! ” ) ;wrongInput = true ;

} e l s e {p l a y e rBe t s [ pos ] = −1;p l aye rAc ted [ pos ] = 1 ;gu i . sendMsg ( ”99 Player ” + pos + ” f o l d s ” ) ;gu i . sendData ( ”8” + pos + ” f o l 0 ” ) ;

}}

i f ( inpu t . e q ua l s ( ” che ” ) ) {i f ( p l a y e rBe t s [ pos ] == t o t a l B e t ) {

Page 87: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

79p layerChecks [ pos ] = 1 ;p l aye rAc ted [ pos ] = 1 ;gu i . sendMsg ( ”99 Player ” + pos + ” check s ” ) ;gu i . sendData ( ”8” + pos + ”che0 ” ) ;

} e l s e {gu i . sendMsg ( inputID + ”9” + ”You cannot check , a b e t has been made” ) ;wrongInput = true ;

}}

// Player Betsi f ( inpu t . e q ua l s ( ” b e t ” ) ) {

i f ( t o t a l B e t > 0) {gu i . sendMsg ( inputID + ”9” + ”A p l a y e r has a l r e ady bet , you can e i t h e r ’ r a i s e ’ , ’ c a l l ’

or ’ f o l d ’ ” ) ;wrongInput = true ;

} e l s e {p l a y e rBe t s [ pos ] = In t e g e r . p a r s e In t ( inputAmount ) ;gu i . sendMsg ( ”99 Player ” + pos + ” b e t s ” + inputAmount ) ;i f ( p l a y e rBe t s [ pos ] >= 2) {

i f ( p l a y e rBe t s [ pos ] >= p l a y e r [ pos ] . s t a c k S i z e ) {p l a y e rBe t s [ pos ] = p l a y e r [ pos ] . s t a c k S i z e ;gu i . sendMsg ( ”99 Player ” + pos + ” i s ALL−IN : ” + p l a y e rBe t s [ pos ] + ”\n” ) ;

}i f ( p l a y e rBe t s [ pos ] > 0) {

t o t a l B e t = t o t a l B e t + p l a y e rBe t s [ pos ] ;p l a y e r [ pos ] . s t a c k S i z e = p l a y e r [ pos ] . s t a c k S i z e − p l a y e rBe t s [ pos ] ;po t = pot + p l a y e rBe t s [ pos ] ;rAmountMax = p l a y e rBe t s [ pos ] ;

} e l s e {p l a y e rBe t s [ pos ] = p l a y e rBe t s [ pos ] ∗ − 1 ;i f ( p l a y e rBe t s [ pos ] > p l a y e r [ pos ] . s t a c k S i z e ) {

p l a y e rBe t s [ pos ] = p l a y e r [ pos ] . s t a c k S i z e ;}t o t a l B e t = t o t a l B e t + p l a y e rBe t s [ pos ] ;po t = pot + p l a y e rBe t s [ pos ] ;rAmountMax = p l a y e rBe t s [ pos ] ;

}gu i . sendMsg ( ”99 pot : ” + pot ) ;p l aye rAc ted [ pos ] = 1 ;

} e l s e {gu i . sendMsg ( inputID + ”9” + ”Your b e t has to be a t l e a s t a b i g b l i n d \n” ) ;p l a y e rBe t s [ pos ] = 0 ;wrongInput = true ;

}

Page 88: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

80gu i . sendData ( ”8” + pos + ” b e t ” + p l a y e rBe t s [ pos ] ) ;

}}

// Player Raisesi f ( inpu t . e q ua l s ( ” r a i ” ) ) {

i f ( t o t a l B e t > 0) {rAmount = In t e g e r . p a r s e In t ( inputAmount ) ;i f ( rAmount >= rAmountMax) {

rAmountMax = rAmount ;} e l s e {

rAmount = rAmountMax ;gu i . sendMsg ( inputID + ”9” + ”Your r a i s e i s too smal l , ” + rAmount + ” r a i s e d

i n s t e a d \n” ) ;}

i f ( ( rAmount + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) < p l a y e r [ pos ] . s t a c k S i z e ) {p l a y e r [ pos ] . s t a c k S i z e = p l a y e r [ pos ] . s t a c k S i z e − ( rAmount + ( t o t a l B e t −

p l a y e rBe t s [ pos ] ) ) ;po t = pot + ( rAmount + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;t o t a l B e t = t o t a l B e t + rAmount ;p l a y e rBe t s [ pos ] = t o t a l B e t ;p l aye rAc ted [ pos ] = 1 ;gu i . sendMsg ( ”99 Player ” + pos + ” r a i s e s ” + rAmount + ”\n” ) ;

} e l s e {rAmount = p l a y e r [ pos ] . s t a c k S i z e − ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ;gu i . sendMsg ( ”99 Player ” + pos + ” i s Al l−IN : an a d d i t i o n a l r a i s e o f ” + rAmount +

”\n” ) ;p l a y e r [ pos ] . s t a c k S i z e = p l a y e r [ pos ] . s t a c k S i z e − ( rAmount + ( t o t a l B e t −

p l a y e rBe t s [ pos ] ) ) ;po t = pot + ( rAmount + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;t o t a l B e t = t o t a l B e t + rAmount ;p l a y e rBe t s [ pos ] = t o t a l B e t ;p l aye rAc ted [ pos ] = 1 ;

}gu i . sendData ( ”8” + pos + ” ra i ” + rAmount ) ;

} e l s e {gu i . sendMsg ( inputID + ”9” + ”There i s no b e t to ra i s e , t r y us ing the command ’ b e t ’ ” ) ;wrongInput = true ;

}}

}i f ( wrongInput == true ) {

wrongInput = f a l s e ;gu i . sendMsg ( inputID + ”9” + ”Wrong Input ” ) ;

Page 89: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

81} e l s e {i f ( checkDec i s ionsComple te (0) == 6) { // a l l d e c i s i o n s have been made

pos = sma l lB l i nd ;c l e a rBe t s ( ) ;in t c = 0 ;for ( in t a = 0 ; a < 6 ; a++) {

i f ( p l a y e r [ a ] . s t a c k S i z e == 0 | | p l a y e rBe t s [ a ] == −1) {c++;

}}i f ( c == 6) {

s t r e e t = 0 ;dea lF l op ( ) ;dealTurn ( ) ;d ea lR i v e r ( ) ;checkWin ( ) ;po t = 0 ;nextHand ( ) ;

}nh = f a l s e ;i f ( s t r e e t == 4) {

s t r e e t = 0 ;checkWin ( ) ;po t = 0 ;c l e a rBe t s ( ) ;nh = true ;

}i f ( s t r e e t == 3) {

s t r e e t = 4 ;d ea lR i v e r ( ) ;pos = sma l lB l i nd ;gu i . sendMsg ( ”99 Player ” + pos + ” ( ” + p l a y e r [ pos ] . s t a c k S i z e + ” ) ” + ” to ac t : ” + ” Pot

S i z e : ” + pot + ” Bet to c a l l : ” + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;gu i . sendMsg ( pos + ”9Your turn ” ) ;

}i f ( s t r e e t == 2) {

s t r e e t = 3 ;dealTurn ( ) ;pos = sma l lB l i nd ;gu i . sendMsg ( ”99 Player ” + pos + ” ( ” + p l a y e r [ pos ] . s t a c k S i z e + ” ) ” + ” to ac t : ” + ” Pot S i z e :

” + pot + ” Bet to c a l l : ” + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;gu i . sendMsg ( pos + ”9Your turn ” ) ;

}i f ( s t r e e t == 1) {

s t r e e t = 2 ;

Page 90: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

82dea lF l op ( ) ;pos = sma l lB l i nd ;gu i . sendMsg ( ”99 Player ” + pos + ” ( ” + p l a y e r [ pos ] . s t a c k S i z e + ” ) ” + ” to ac t : ” + ” Pot S i z e :

” + pot + ” Bet to c a l l : ” + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;gu i . sendMsg ( pos + ”9Your turn ” ) ;

}i f ( nh == true ) {

nextHand ( ) ;nh = f a l s e ;

}} e l s e {

i f ( ( p l a y e r [ 0 ] . s t a c k S i z e == 0) && ( p l a y e r [ 1 ] . s t a c k S i z e == 0) && ( p l a y e r [ 2 ] . s t a c k S i z e == 0) &&( p l a y e r [ 3 ] . s t a c k S i z e == 0) && ( p l a y e r [ 4 ] . s t a c k S i z e == 0) && ( p l a y e r [ 5 ] . s t a c k S i z e == 0) ) {

} e l s e {pos = increasePos ( pos ) ;i f ( p l a y e rBe t s [ pos ] == −1 | | p l a y e r [ pos ] . s t a c k S i z e == 0) {} e l s e {

gu i . sendMsg ( ”99 Player ” + pos + ” ( ” + p l a y e r [ pos ] . s t a c k S i z e + ” ) ” + ” to ac t : ” + ” PotS i z e : ” + pot + ” Bet to c a l l : ” + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;

gu i . sendMsg ( pos + ”9Your turn ” ) ;d e c i s i o n ( ) ;

}}

}}

}}

}

/∗ This method r e s e t s v a r i a b l e s and moves the d e a l e r bu t t on 1 p lace , t hus s h i f t i n g everyones p o s i t i o n by 1and then s h u f f l e s and d e a l s t he nex t hand ∗/

pub l i c void nextHand ( ) {sma l lB l i nd = increasePos ( sma l lB l i nd ) ;b i gB l i n d = increasePos ( b i gB l i n d ) ;UTG = increasePos (UTG) ;MP = increasePos (MP) ;CO = increasePos (CO) ;dea l e rPos = increasePos ( dea l e rPos ) ;p layerGo = UTG;s t r e e t = 1 ;c l e a rBe t s ( ) ;for ( in t g = 0 ; g < 6 ; g++) {

p l a y e rBe t s [ g ] = 0 ;}gu i . sendMsg ( ”99 Player ” + ( dea l e rPos ) + ” i s t he d e a l e r ” ) ;

Page 91: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

83gu i . sendMsg ( ”99 Player ” + ( sma l lB l i nd ) + ” po s t s sma l l b l i n d $1” ) ;gu i . sendData ( ”8” + sma l lB l i nd + ” be t1 ” ) ;gu i . sendMsg ( ”99 Player ” + ( b i gB l i n d ) + ” po s t s b i g b l i n d $2\n” ) ;gu i . sendData ( ”8” + sma l lB l i nd + ” be t2 ” ) ;po t = pot + 3 ;p l a y e r [ sma l lB l i nd ] . s t a c k S i z e = p l a y e r [ sma l lB l i nd ] . s t a c k S i z e − 1 ;p l a y e r [ b i gB l i n d ] . s t a c k S i z e = p l a y e r [ b i gB l i n d ] . s t a c k S i z e − 2 ;gu i . sendMsg ( ”99Pot i s : $” + pot ) ;p l a y e rBe t s [ sma l lB l i nd ] = 1 ;p l a y e rBe t s [ b i gB l i n d ] = 2 ;t o t a l B e t = 2 ;rAmountMax = 2 ;pos = playerGo ;a l l I n s = 0 ;genera teCards ( ) ;s h u f f l e ( ) ;d ea l ( ) ;showCards ( ) ;gu i . sendMsg ( ”99 Player ” + pos + ” ( ” + p l a y e r [ pos ] . s t a c k S i z e + ” ) ” + ” to ac t : ” + ” Pot S i z e : ” + pot + ”

Bet to c a l l : ” + ( t o t a l B e t − p l a y e rBe t s [ pos ] ) ) ;gu i . sendMsg ( pos + ”9Your turn ” ) ;

}

pub l i c in t increasePos ( in t p ) {i f ( p < 6) {

p++;}i f ( p == 6) {

p = 0 ;}return p ;

}

/∗ check a l l d e c i s i o n s have been made by a l l p l a y e r s ∗/pub l i c in t checkDec i s ionsComple te ( in t c ) {

in t xx ;for ( xx = 0 ; xx < 6 ; xx++) {

i f ( p l aye rAc ted [ xx ] == 0) {c−−;

}i f ( ( p l a y e rBe t s [ xx ] == −1) | | ( p l a y e r [ xx ] . s t a c k S i z e == 0) ) {

c++;} e l s e {

i f ( t o t a l B e t > 0) {i f ( p l a y e rBe t s [ xx ] == t o t a l B e t ) {

Page 92: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

84c++;

}} e l s e {

i f ( p l ayerChecks [ xx ] == 1) {c++;

}}

}}return c ;

}

pub l i c void c l e a rBe t s ( ) {in t x ;for ( x = 0 ; x < 6 ; x++) {

i f ( p l a y e rBe t s [ x ] >= 0) { // i . e not f o l d e dp l aye rAc ted [ x ] = 0 ;p l a y e rBe t s [ x ] = 0 ;p l ayerChecks [ x ] = 0 ;t o t a l B e t = 0 ;rAmountMax = 0 ;i f ( ( p l a y e rBe t s [ x ] == −1) | | ( p l a y e r [ x ] . s t a c k S i z e == 0) ) {

p laye rAc ted [ x ] = 1 ;}

}}

}

/∗ pu t s a l l 7 cards i n t o an array and s o r t s them to f i n d the h i g h e s t card ∗/pub l i c in t [ ] highCard (Card pCard1 , Card pCard2 ) {

in t [ ] sevenCards = new in t [ 7 ] ;in t [ ] answer = new in t [ 5 ] ;

sevenCards [ 0 ] = f l o p [ 0 ] . ge tVa lue ( ) ;sevenCards [ 1 ] = f l o p [ 1 ] . ge tVa lue ( ) ;sevenCards [ 2 ] = f l o p [ 2 ] . ge tVa lue ( ) ;sevenCards [ 3 ] = turn . ge tVa lue ( ) ;sevenCards [ 4 ] = r i v e r . ge tVa lue ( ) ;sevenCards [ 5 ] = pCard1 . ge tVa lue ( ) ;sevenCards [ 6 ] = pCard2 . ge tVa lue ( ) ;

Arrays . s o r t ( sevenCards ) ;

answer [ 0 ] = sevenCards [ 6 ] ;

Page 93: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

85answer [ 1 ] = sevenCards [ 5 ] ;answer [ 2 ] = sevenCards [ 4 ] ;answer [ 3 ] = sevenCards [ 3 ] ;answer [ 4 ] = sevenCards [ 2 ] ;

return answer ;}

/∗ pu t s a l l 7 cards i n t o an array and l o o k s f o r two cards wi th the same va l u e i . e a pa i r ∗/pub l i c in t [ ] p a i r (Card pCard1 , Card pCard2 ) {

Card [ ] sevenCards = new Card [ 7 ] ;in t [ ] k i c k e r = new in t [ 5 ] ;in t [ ] answer = new in t [ 5 ] ;in t x , y , z , c , h i g h e s t = 0 ;

sevenCards [ 0 ] = f l o p [ 0 ] ;sevenCards [ 1 ] = f l o p [ 1 ] ;sevenCards [ 2 ] = f l o p [ 2 ] ;sevenCards [ 3 ] = turn ;sevenCards [ 4 ] = r i v e r ;sevenCards [ 5 ] = pCard1 ;sevenCards [ 6 ] = pCard2 ;

for ( x = 0 ; x < 7 ; x++) {for ( y = 0 ; y < 7 ; y++) {

i f ( ( sevenCards [ x ] . ge tVa lue ( ) == sevenCards [ y ] . ge tVa lue ( ) ) && ( x != y ) ) {i f ( sevenCards [ x ] . ge tVa lue ( ) > h i g h e s t ) {

h i g h e s t = sevenCards [ x ] . ge tVa lue ( ) ;}

}}

}c = 0 ;i f ( h i g h e s t > 0) {

for ( z = 0 ; z < 7 ; z++) {i f ( sevenCards [ z ] . ge tVa lue ( ) != h i g h e s t ) {

k i c k e r [ c ] = sevenCards [ z ] . ge tVa lue ( ) ;c++;

}}Arrays . s o r t ( k i c k e r ) ;

}answer [ 0 ] = h i g h e s t ;answer [ 1 ] = k i c k e r [ 4 ] ;

Page 94: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

86answer [ 2 ] = k i c k e r [ 3 ] ;answer [ 3 ] = k i c k e r [ 2 ] ;answer [ 4 ] = 0 ;return answer ;

}

/∗ pu t s a l l 7 cards i n t o an array and l o o k s f o r p a i r s ∗/pub l i c in t [ ] twoPair (Card pCard1 , Card pCard2 ) {

Card [ ] sevenCards = new Card [ 7 ] ;in t [ ] k i c k e r = new in t [ 3 ] ;in t [ ] answer = new in t [ 5 ] ;in t x , y , z , c ;in t pa i r1 = 0 ;in t pa i r2 = 0 ;

sevenCards [ 0 ] = f l o p [ 0 ] ;sevenCards [ 1 ] = f l o p [ 1 ] ;sevenCards [ 2 ] = f l o p [ 2 ] ;sevenCards [ 3 ] = turn ;sevenCards [ 4 ] = r i v e r ;sevenCards [ 5 ] = pCard1 ;sevenCards [ 6 ] = pCard2 ;

for ( x = 0 ; x < 7 ; x++) {for ( y = 0 ; y < 7 ; y++) {

i f ( ( sevenCards [ x ] . ge tVa lue ( ) == sevenCards [ y ] . ge tVa lue ( ) ) && ( x != y ) ) {i f ( sevenCards [ x ] . ge tVa lue ( ) > pa i r1 ) {

pa i r1 = sevenCards [ x ] . ge tVa lue ( ) ;}

}}

}

for ( x = 0 ; x < 7 ; x++) {for ( y = 0 ; y < 7 ; y++) {

i f ( ( sevenCards [ x ] . ge tVa lue ( ) == sevenCards [ y ] . ge tVa lue ( ) ) && ( x != y ) &&( sevenCards [ x ] . ge tVa lue ( ) != pa i r1 ) ) {i f ( sevenCards [ x ] . ge tVa lue ( ) > pa i r2 ) {

pa i r2 = sevenCards [ x ] . ge tVa lue ( ) ;}

}}

}

c = 0 ;

Page 95: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

87i f ( ( pa i r1 > 0) && ( pa i r2 > 0) ) {

for ( z = 0 ; z < 7 ; z++) {i f ( ( sevenCards [ z ] . ge tVa lue ( ) != pa i r1 ) && ( sevenCards [ z ] . ge tVa lue ( ) != pa i r2 ) ) {

k i c k e r [ c ] = sevenCards [ z ] . ge tVa lue ( ) ;c++;

}}Arrays . s o r t ( k i c k e r ) ;

}answer [ 0 ] = pa i r1 ;answer [ 1 ] = pa i r2 ;answer [ 2 ] = k i c k e r [ 2 ] ;answer [ 3 ] = 0 ;answer [ 4 ] = 0 ;return answer ;

}

/∗ pu t s a l l 7 cards i n t o an array and l o o k s f o r 3 cards wi th the same va l u e ∗/pub l i c in t [ ] t r i p s o r S e t (Card pCard1 , Card pCard2 ) { // 3 o f a k ind

Card [ ] sevenCards = new Card [ 7 ] ;in t [ ] k i c k e r = new in t [ 5 ] ;in t [ ] answer = new in t [ 5 ] ;in t x , y , z , a , c , h i g h e s t = 0 ;

sevenCards [ 0 ] = f l o p [ 0 ] ;sevenCards [ 1 ] = f l o p [ 1 ] ;sevenCards [ 2 ] = f l o p [ 2 ] ;sevenCards [ 3 ] = turn ;sevenCards [ 4 ] = r i v e r ;sevenCards [ 5 ] = pCard1 ;sevenCards [ 6 ] = pCard2 ;

for ( x = 0 ; x < 7 ; x++) {for ( y = 0 ; y < 7 ; y++) {

for ( z = 0 ; z < 7 ; z++) {i f ( ( sevenCards [ x ] . ge tVa lue ( ) == sevenCards [ y ] . ge tVa lue ( ) ) && ( sevenCards [ x ] . ge tVa lue ( ) ==

sevenCards [ z ] . ge tVa lue ( ) ) && ( x != z ) && ( x != y ) && ( y != z ) ) {i f ( sevenCards [ x ] . ge tVa lue ( ) > h i g h e s t ) {

h i g h e s t = sevenCards [ x ] . ge tVa lue ( ) ;}

}}

}}c = 0 ;

Page 96: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

88i f ( h i g h e s t > 0) {

for ( a = 0 ; a < 7 ; a++) {i f ( sevenCards [ a ] . ge tVa lue ( ) != h i g h e s t ) {

k i c k e r [ c ] = sevenCards [ a ] . ge tVa lue ( ) ;c++;

}}Arrays . s o r t ( k i c k e r ) ;

}answer [ 0 ] = h i g h e s t ;answer [ 1 ] = k i c k e r [ 4 ] ;answer [ 2 ] = k i c k e r [ 3 ] ;answer [ 3 ] = 0 ;answer [ 4 ] = 0 ;return answer ;

}

/∗ pu t s a l l 7 cards i n t o an array and s o r t s them in t o order o f va lue , and l o o k s to see i f t h e r e are 5 cardswhereby the d i f f e r e n c e in va l u e between each card i s 1 ∗/

pub l i c in t [ ] s t r a i g h t (Card pCard1 , Card pCard2 , in t ace ) {in t [ ] sevenCards = new in t [ 7 ] ;in t [ ] tempSevenCards = new in t [ 7 ] ;in t [ ] p S t r a i g h t = new in t [ 6 ] ;in t [ ] answer = new in t [ 5 ] ;in t count = 0 ;in t f i r s tCoun t = 0 ;in t y , tempX = 0;in t b = 0 ;

sevenCards [ 0 ] = f l o p [ 0 ] . ge tVa lue ( ) ;sevenCards [ 1 ] = f l o p [ 1 ] . ge tVa lue ( ) ;sevenCards [ 2 ] = f l o p [ 2 ] . ge tVa lue ( ) ;sevenCards [ 3 ] = turn . ge tVa lue ( ) ;sevenCards [ 4 ] = r i v e r . ge tVa lue ( ) ;sevenCards [ 5 ] = pCard1 . ge tVa lue ( ) ;sevenCards [ 6 ] = pCard2 . ge tVa lue ( ) ;

i f ( ace == 1) {for ( in t z = 0 ; z < 7 ; z++) {

i f ( sevenCards [ z ] == 14) {sevenCards [ z ] = 1 ;

}}

}

Page 97: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

89Arrays . s o r t ( sevenCards ) ;

for ( in t a = 0 ; a < 6 ; a++) {b = a + 1 ;i f ( sevenCards [ a ] != sevenCards [ b ] ) {

tempSevenCards [ f i r s tCoun t ] = sevenCards [ a ] ;f i r s tCoun t++;

}}tempSevenCards [ f i r s tCoun t ] = sevenCards [ 6 ] ;sevenCards = tempSevenCards ;

for ( in t x = 0 ; x < 6 ; x++) {y = x + 1 ;i f ( sevenCards [ y ] == ( sevenCards [ x ] + 1) ) {

i f ( x == ( tempX + 1) | | ( count == 0) ) {pS t r a i g h t [ count ] = sevenCards [ x ] ;count++;pS t r a i g h t [ count ] = sevenCards [ y ] ;tempX = x ;

} e l s e {i f ( count < 4) {

count = 0 ;}

}}

}

i f ( count > 3) {answer [ 0 ] = pS t r a i g h t [ count ] ;answer [ 1 ] = pS t r a i g h t [ ( count − 1) ] ;answer [ 2 ] = pS t r a i g h t [ ( count − 2) ] ;answer [ 3 ] = pS t r a i g h t [ ( count − 3) ] ;answer [ 4 ] = pS t r a i g h t [ ( count − 4) ] ;

}

return answer ;}

/∗ pu t s a l l 7 cards i n t o an array and counts t he number o f s u i t s , i f t h e count r eaches 5 the p l a y e r has af l u s h and the cards are s o r t e d to determine the f l u s h e s va l u e ∗/

pub l i c in t [ ] f l u s h (Card pCard1 , Card pCard2 ) {Card [ ] sevenCards = new Card [ 7 ] ;in t [ ] diamonds = new in t [ 7 ] ;in t [ ] h e a r t s = new in t [ 7 ] ;

Page 98: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

90in t [ ] c l u b s = new in t [ 7 ] ;in t [ ] spades = new in t [ 7 ] ;in t [ ] answer = new in t [ 5 ] ;in t diamondCount = 0 , heartCount = 0 , c lubCount = 0 , spadeCount = 0 , x = 0 , y , z ;

sevenCards [ 0 ] = f l o p [ 0 ] ;sevenCards [ 1 ] = f l o p [ 1 ] ;sevenCards [ 2 ] = f l o p [ 2 ] ;sevenCards [ 3 ] = turn ;sevenCards [ 4 ] = r i v e r ;sevenCards [ 5 ] = pCard1 ;sevenCards [ 6 ] = pCard2 ;

for ( x = 0 ; x < 7 ; x++) {i f ( sevenCards [ x ] . g e t S u i t ( ) == 0) {

c l u b s [ c lubCount ] = sevenCards [ x ] . ge tVa lue ( ) ;c lubCount++;

}i f ( sevenCards [ x ] . g e t S u i t ( ) == 1) {

diamonds [ diamondCount ] = sevenCards [ x ] . ge tVa lue ( ) ;diamondCount++;

}i f ( sevenCards [ x ] . g e t S u i t ( ) == 2) {

h ea r t s [ heartCount ] = sevenCards [ x ] . ge tVa lue ( ) ;heartCount++;

}i f ( sevenCards [ x ] . g e t S u i t ( ) == 3) {

spades [ spadeCount ] = sevenCards [ x ] . ge tVa lue ( ) ;spadeCount++;

}}

i f ( c lubCount >= 5) {Arrays . s o r t ( c l u b s ) ;y = 6 ;for ( z = 0 ; z < 5 ; z++) {

answer [ z ] = c l u b s [ y ] ;y−−;

}}

i f ( diamondCount >= 5) {Arrays . s o r t ( diamonds ) ;y = 6 ;for ( z = 0 ; z < 5 ; z++) {

Page 99: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

91answer [ z ] = diamonds [ y ] ;y−−;

}}

i f ( heartCount >= 5) {Arrays . s o r t ( h e a r t s ) ;y = 6 ;for ( z = 0 ; z < 5 ; z++) {

answer [ z ] = hea r t s [ y ] ;y−−;

}}

i f ( spadeCount >= 5) {Arrays . s o r t ( spades ) ;y = 6 ;for ( z = 0 ; z < 5 ; z++) {

answer [ z ] = spades [ y ] ;y−−;

}}return answer ;

}

/∗ This uses t he methods t r i p o f S e t and twoPair , i f bo th t h e s e r e tu rn p o s i t i v e then the p l a y e r has a f u l lhouse ∗/

pub l i c in t [ ] f u l lHou s e (Card pCard1 , Card pCard2 ) {in t [ ] t r i p s o r S e t = new in t [ 4 ] ;in t [ ] p a i r = new in t [ 4 ] ;in t [ ] twoPair = new in t [ 3 ] ;in t [ ] answer = new in t [ 5 ] ;

t r i p s o r S e t = t r i p s o r S e t ( pCard1 , pCard2 ) ;pa i r = pa i r ( pCard1 , pCard2 ) ;twoPair = twoPair ( pCard1 , pCard2 ) ;

i f ( ( t r i p s o r S e t [ 0 ] != pa i r [ 0 ] ) && ( pa i r [ 0 ] != 0) ) {answer [ 0 ] = t r i p s o r S e t [ 0 ] ;answer [ 1 ] = pa i r [ 0 ] ;answer [ 3 ] = 0 ;answer [ 4 ] = 0 ;

} e l s e {i f ( t r i p s o r S e t [ 0 ] != twoPair [ 1 ] && ( twoPair [ 1 ] != 0) ) {

answer [ 0 ] = t r i p s o r S e t [ 0 ] ;

Page 100: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

92answer [ 1 ] = twoPair [ 1 ] ;answer [ 3 ] = 0 ;answer [ 4 ] = 0 ;

}}

return answer ;}

/∗ Puts a l l 7 cards i n t o an array and l o o k s f o r 4 cards wi th the same va l u e ∗/pub l i c in t [ ] quads (Card pCard1 , Card pCard2 ) {

in t [ ] sevenCards = new in t [ 7 ] ;in t [ ] answer = new in t [ 5 ] ;in t quadCount = 0 ;in t quadIs = 0 ;in t k i c k e r = 0 ;in t h i g h e s tK i c k e r = 0 ;

sevenCards [ 0 ] = f l o p [ 0 ] . ge tVa lue ( ) ;sevenCards [ 1 ] = f l o p [ 1 ] . ge tVa lue ( ) ;sevenCards [ 2 ] = f l o p [ 2 ] . ge tVa lue ( ) ;sevenCards [ 3 ] = turn . ge tVa lue ( ) ;sevenCards [ 4 ] = r i v e r . ge tVa lue ( ) ;sevenCards [ 5 ] = pCard1 . ge tVa lue ( ) ;sevenCards [ 6 ] = pCard2 . ge tVa lue ( ) ;

for ( in t x = 0 ; x < 7 ; x++) {for ( in t y = 0 ; y < 7 ; y++) {

i f ( x != y ) {i f ( sevenCards [ x ] == sevenCards [ y ] ) {

quadCount++;quadIs = sevenCards [ x ] ;

} e l s e {i f ( sevenCards [ y ] > h i g h e s tK i c k e r ) {

h i g h e s tK i c k e r = sevenCards [ y ] ;}

}}

i f ( quadCount == 4) {answer [ 0 ] = quadIs ;answer [ 1 ] = h i g h e s tK i c k e r ;answer [ 2 ] = 0 ;answer [ 3 ] = 0 ;answer [ 4 ] = 0 ;

Page 101: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

93}

}quadCount = 0 ;h i g h e s tK i c k e r = 0 ;

}

return answer ;}

}

10.7 File: GUI.java

/∗ The base code was Writ ten By Tom L i t t l e March 2006 , I adapted i t to s u i t my p r o j e c t w i th h i s permis s ion ∗/

import j a va . awt . ∗ ;import j a va . awt . e ven t . ∗ ;import j a vax . swing . ∗ ;import j a va . u t i l . Date ;import j a va . ne t . ∗ ;import j a va . i o . ∗ ;

c la s s GUI extends JFrame implements Act i onL i s t ene r{

pr iva te Game game ;pr iva te GUI gu i ;pr iva te User userType ;

pr iva te JButton Send , Quit , S tar t , Ca l l , Check , Fold , Bet , Raise ;pr iva te JLabe l t i t l e = new JLabe l ( ) ;pr iva te JPanel panel , panel2 , pane l3 ;pr iva te JTextArea rep l y , r e c i e v e ;pr iva te S t r i n g user = ” n u l l ” , IPAddress , las tMsg , l a s tA c t i o n = ”” ;pr iva te in t portNUM , number , lastMsgID ;pr iva te BorderLayout layou t1 , l ayou t2 , l a you t 4 ;pr iva te FlowLayout l a you t 3 ;pr iva te JScro l lPane s c r o l l e r 1 , s c r o l l e r 2 ;pr iva te JMenuBar bar ;pr iva te JMenu Connect ;pr iva te JRadioButtonMenuItem c l i e n tB = new JRadioButtonMenuItem (”Connect as C l i e n t . . . ” ) ;pr iva te JRadioButtonMenuItem serverB = new JRadioButtonMenuItem (”Connect as Server . . . ” ) ;pr iva te ButtonGroup b t g = new ButtonGroup ( ) ;pr iva te ButtonGroup b t g g g = new ButtonGroup ( ) ;pr iva te GUIConnection guiCON ;

Page 102: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

94pr iva te s e r v e r s e r v i n g ;pr iva te c l i e n t c l i n t o n s ;pr iva te boolean i s S e r v e r ;

pub l i c s t a t i c void main ( S t r i n g [ ] a rg s ){}

pub l i c GUI( User u ){

userType = u ;pack ( ) ;s e t T i t l e ( ”Poker” ) ;s e t V i s i b l e ( true ) ;

i n i t i a l i s e ( ) ;s e tTex t ( ) ;s e t T i t l e ( ) ;s e tBu t t on s ( ) ;setMenu ( ) ;s e tPane l ( ) ;setFrame ( ) ;

}

// Panels and l a y o u t s are s o r t e d herepub l i c void i n i t i a l i s e ( ){

pane l = new JPanel ( ) ;pane l2 = new JPanel ( ) ;pane l3 = new JPanel ( ) ;

l a you t 1 = new BorderLayout ( ) ;l a you t 2 = new BorderLayout ( ) ;l a you t 3 = new FlowLayout ( ) ;

pane l . s e tLayou t ( l a you t 1 ) ;pane l2 . s e tLayou t ( l a you t 2 ) ;pane l3 . s e tLayou t ( l a you t 3 ) ;

}

//Two t e x t areas are mounted onto s c r o l l e r s herepub l i c void s e tTex t ( ){

s c r o l l e r 1 = new JScro l lPane ( r e p l y = new JTextArea (7 , 30) ) ;s c r o l l e r 2 = new JScro l lPane ( r e c i e v e = new JTextArea (20 , 30) ) ;

Page 103: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

95r e c i e v e . s e tTex t ( ”You are not y e t Connected . . . ” ) ;

//Both t e x t areas s t a r t as u n e d i t a b l e b e f o r e connec t ionr e p l y . s e t E d i t a b l e ( f a l s e ) ;r e p l y . setLineWrap ( true ) ;r e p l y . setWrapStyleWord ( true ) ;r e p l y . s e tFont (new Font ( ”Square721 BT” , Font .PLAIN, 12) ) ;

r e c i e v e . s e t E d i t a b l e ( f a l s e ) ;r e c i e v e . setLineWrap ( true ) ;r e c i e v e . setWrapStyleWord ( true ) ;r e c i e v e . s e tFont (new Font ( ”Square721 BT” , Font .PLAIN, 12) ) ;

}

// s e t s t he t i t l epub l i c void s e t T i t l e ( ){

// image i s s e t to s e r v e r a t d e f u l t changes l a t e r . .t i t l e . s e tHor i z on t a lA l i gnmen t ( JLabe l .CENTER) ;//a c r ea t ed t i t l e made in Adobe Photoshopt i t l e . s e t I c on (new ImageIcon ( ” s e r v e r . g i f ” ) ) ;

}

// s e t s t he bu t t on s . . .pub l i c void s e tBu t t on s ( ){

Send = new JButton ( ”Send” ) ;S t a r t = new JButton ( ” s t a r t ” ) ;Quit = new JButton ( ”Quit ” ) ;Check = new JButton ( ”Check” ) ;Ca l l = new JButton ( ” Ca l l ” ) ;Fold = new JButton ( ”Fold ” ) ;Bet = new JButton ( ”Bet” ) ;Raise = new JButton ( ”Raise ” ) ;Send . addAc t i onL i s t ener ( t h i s ) ;S t a r t . addAc t i onL i s t ener ( t h i s ) ;Quit . addAc t i onL i s t ener ( t h i s ) ;Check . addAc t i onL i s t ener ( t h i s ) ;Ca l l . addAc t i onL i s t ener ( t h i s ) ;Fold . addAc t i onL i s t ener ( t h i s ) ;Bet . addAc t i onL i s t ener ( t h i s ) ;Raise . addAc t i onL i s t ener ( t h i s ) ;

}

//Menu bar i s where you connect and s e l f −communicate

Page 104: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

96pub l i c void setMenu ( ){

bar = new JMenuBar ( ) ;Connect = new JMenu( ”Connect” ) ;bar . add ( Connect ) ;

/∗These are drop downs from the menus in theform o f rad io bu t t on s ∗/Connect . add ( c l i e n tB ) ;Connect . add ( serverB ) ;

//Grouped here in a bu t t on groupb t g . add ( c l i e n tB ) ;b t g . add ( serverB ) ;

serverB . addAc t i onL i s t ener ( t h i s ) ;c l i e n tB . addAc t i onL i s t ener ( t h i s ) ;

}

/∗This adds to a l t h e pane l s ready to be l oaded onto theFrame∗/pub l i c void s e tPane l ( ){

pane l . add ( t i t l e , l a y ou t 1 .CENTER) ;pane l2 . add ( s c r o l l e r 1 , l a you t 2 .SOUTH) ;pane l2 . add ( s c r o l l e r 2 , l a you t 2 .NORTH) ;

}

/∗This s e t t he l a y ou t of , add the menu bar too , and addsthe pane l s too the Frame which i s t h i s i n s t anc e o f GUI∗/pub l i c void setFrame ( ){

setJMenuBar ( bar ) ;l a you t 4 = new BorderLayout ( ) ;getContentPane ( ) . s e tLayou t ( l a you t 4 ) ;getContentPane ( ) . add ( panel , l a y ou t 4 .NORTH) ;getContentPane ( ) . add ( panel2 , l a y ou t 4 .CENTER) ;getContentPane ( ) . add ( panel3 , l a y ou t 4 .SOUTH) ;

}

pub l i c boolean i s I n t ( S t r i n g t e x t )

Page 105: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

97{

try {I n t e g e r . p a r s e In t ( t e x t ) ;return true ;

}catch ( NumberFormatException n fe ) {

return f a l s e ;}

}

/∗There are seven p o s s i b l e a c t i o n s t h a t can be performed socon s e quen t l y q u i t e a b i g method . Most o t h e r a c t i o n s are l o c k e d outu n t i l t h e user has connected us ing the Connect Menu Bar∗/pub l i c void act ionPer formed ( Act ionEvent ae ){

// t h i s s o r t s which rad io bu t t on has been chosenS t r i n g s t r i n g = ae . getActionCommand ( ) ;

i f ( ae . g e tSource ( ) instanceof JMenuItem ) {

// I f Server i s Chosen . .i f ( ”Connect as Server . . . ” . e q ua l s ( s t r i n g ) ) {

//A new window opens so the user can connect . .guiCON = new GUIConnection ( th is , ” s e r v e r ” ) ;guiCON . pack ( ) ;guiCON . s e t T i t l e ( ”Poker” ) ;guiCON . s e t V i s i b l e ( true ) ;

}

// I f C l i e n t i s Chosen . . .i f ( ”Connect as C l i e n t . . . ” . e q ua l s ( s t r i n g ) ) {

//A new window opens so the user can connect . .guiCON = new GUIConnection ( th is , ” c l i e n t ” ) ;guiCON . pack ( ) ;guiCON . s e t T i t l e ( ”Poker” ) ;guiCON . s e t V i s i b l e ( true ) ;

}

}

Page 106: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

98

// I f The Quit bu t t on i s pushed . . t h i s can be acce s s w i t hou t c onn e c i v i t yi f ( ae . g e tSource ( ) == Quit ) {

i f ( user . e q u a l s ( ” c l i e n t ” ) ) {c l i n t o n s . Send ( ” q u i t ” ) ;

}e l s e i f ( user . e q u a l s ( ” s e r v e r ” ) ) {

s e r v i n g . Send ( ” q u i t ” ) ;System . e x i t (0) ;

}e l s e // here the program e x i t s i f user q u i t s b e f o r e connec t ing{

System . e x i t (0) ;}

}

i f ( ! user . e q u a l s ( ” n u l l ” ) ) // check s c o n n e c t i v i t y{

i f ( ae . g e tSource ( ) == S t a r t ) {startGame ( ) ;

}i f ( ae . g e tSource ( ) == Check ) {

sendMsg ( ”9” + t h i s . number + ”che ” ) ;}i f ( ae . g e tSource ( ) == Ca l l ) {

sendMsg ( ”9” + t h i s . number + ” c a l ” ) ;}i f ( ae . g e tSource ( ) == Fold ) {

sendMsg ( ”9” + t h i s . number + ” f o l ” ) ;}i f ( ae . g e tSource ( ) == Bet ) {

i f ( i s I n t ( r e p l y . g e tTex t ( ) . tr im ( ) ) == true ) {sendMsg ( ”9” + t h i s . number + ” b e t ” + r e p l y . g e tTex t ( ) . tr im ( ) ) ;r e p l y . cu t ( ) ;

}}i f ( ae . g e tSource ( ) == Raise ) {

i f ( i s I n t ( r e p l y . g e tTex t ( ) . tr im ( ) ) == true ) {sendMsg ( ”9” + t h i s . number + ” ra i ” + r e p l y . g e tTex t ( ) . t r im ( ) ) ;r e p l y . cu t ( ) ;

}}

}

Page 107: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

99// I f t h e Send Button i s pushedi f ( ! user . e q u a l s ( ” n u l l ” ) ) // check s c o n n e c t i v i t y{

i f ( ae . g e tSource ( ) == Send ) {i f ( user . e q ua l s ( ” c l i e n t ” ) ) {

//Method Recieve p r i n t s out a s t r i n g on the GUIRecieve ( ” C l i e n t ” + t h i s . number + ” : ” + r e p l y . g e tTex t ( ) . tr im ( ) ) ;

/∗ c l i n t o n s i s an in s t an c e o f c l i e n t c r ea t e d when connected toc l i e n t

see In f o method . . i t sends the t e x t to the c l i e n t t h read ∗/c l i n t o n s . Send ( ” C l i e n t ” + t h i s . number + ” : ” +

r e p l y . g e tTex t ( ) . tr im ( ) ) ;

}e l s e {

Recieve ( ” Server : ” + r e p l y . g e tTex t ( ) . tr im ( ) ) ;

/∗ s e r v i n g i s an in s t anc e o f s e r v e r c r ea t e d in In f o andthe t e x t i s s en t to the s e r v i n g th read ∗/s e r v i n g . Send ( ” Server : ” + r e p l y . g e tTex t ( ) . tr im ( ) ) ;

}

//This s e l e c t s a l l t h e t e x t and d e l e t e s i tr e p l y . s e l e c t A l l ( ) ;r e p l y . cu t ( ) ;

}}

}

pub l i c void sendMessage ( S t r i n g msg ) {// I f t h e Send Button i s pushedi f ( user . e q u a l s ( ” c l i e n t ” ) ) // check s c o n n e c t i v i t y{

//Method Recieve p r i n t s out a s t r i n g on the GUIRecieve ( ” C l i e n t ” + t h i s . number + ” : ” + msg ) ;

/∗ c l i n t o n s i s an in s t an c e o f c l i e n t c r ea t e d when connected to c l i e n tsee In f o method . . i t sends the t e x t to the c l i e n t t h read ∗/c l i n t o n s . Send ( ”99 C l i e n t ” + t h i s . number + ” : ” + msg ) ;

} e l s e {Recieve ( ” Server : ” + msg ) ;

Page 108: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

100

/∗ s e r v i n g i s an in s t anc e o f s e r v e r c r ea t e d in In f o andthe t e x t i s s en t to the s e r v i n g th read ∗/s e r v i n g . Send ( ”99 Server : ” + msg ) ;

}

//This s e l e c t s a l l t h e t e x t and d e l e t e s i tr e p l y . s e l e c t A l l ( ) ;r e p l y . cu t ( ) ;

}

pub l i c void sendData ( S t r i n g msg ) {// I f t h e Send Button i s pushedi f ( user . e q u a l s ( ” c l i e n t ” ) ) // check s c o n n e c t i v i t y{

//Method Recieve p r i n t s out a s t r i n g on the GUIRecieveData (msg . s u b s t r i n g (1 ,2 ) , msg . s u b s t r i n g (2 ,5 ) , msg . s u b s t r i n g (5) ) ;

/∗ c l i n t o n s i s an in s t an c e o f c l i e n t c r ea t e d when connected to c l i e n tsee In f o method . . i t sends the t e x t to the c l i e n t t h read ∗/c l i n t o n s . Send (msg ) ;

} e l s e {RecieveData (msg . s u b s t r i n g (1 ,2 ) , msg . s u b s t r i n g (2 ,5 ) , msg . s u b s t r i n g (5) ) ;

/∗ s e r v i n g i s an in s t anc e o f s e r v e r c r ea t e d in In f o andthe t e x t i s s en t to the s e r v i n g th read ∗/s e r v i n g . Send (msg ) ;

}

//This s e l e c t s a l l t h e t e x t and d e l e t e s i tr e p l y . s e l e c t A l l ( ) ;r e p l y . cu t ( ) ;

}

pub l i c void sendHand ( S t r i n g msg ) {// I f t h e Send Button i s pushedi f ( user . e q u a l s ( ” c l i e n t ” ) ) // check s c o n n e c t i v i t y{

//Method Recieve p r i n t s out a s t r i n g on the GUIRecieveHand (msg . s u b s t r i n g (0 ,1 ) , msg . s u b s t r i n g (2 ,3 ) , msg . s u b s t r i n g (3 ,4 ) , msg . s u b s t r i n g (4 ,5 ) ,

msg . s u b s t r i n g (5 ,6 ) ) ;

/∗ c l i n t o n s i s an in s t an c e o f c l i e n t c r ea t e d when connected to c l i e n tsee In f o method . . i t sends the t e x t to the c l i e n t t h read ∗/

Page 109: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

101c l i n t o n s . Send (msg ) ;

} e l s e {RecieveHand (msg . s u b s t r i n g (0 ,1 ) , msg . s u b s t r i n g (2 ,3 ) , msg . s u b s t r i n g (3 ,4 ) , msg . s u b s t r i n g (4 ,5 ) ,

msg . s u b s t r i n g (5 ,6 ) ) ;

/∗ s e r v i n g i s an in s t anc e o f s e r v e r c r ea t e d in In f o andthe t e x t i s s en t to the s e r v i n g th read ∗/s e r v i n g . Send (msg ) ;

}

//This s e l e c t s a l l t h e t e x t and d e l e t e s i tr e p l y . s e l e c t A l l ( ) ;r e p l y . cu t ( ) ;

}

pub l i c void sendMsg ( S t r i n g msg ) {// I f t h e Send Button i s pushedi f ( user . e q u a l s ( ” c l i e n t ” ) ) // check s c o n n e c t i v i t y{

//Method Recieve p r i n t s out a s t r i n g on the GUIRecieveMsg (msg , msg . s u b s t r i n g (0 ,1 ) , msg . s u b s t r i n g (1 ,2 ) ) ;

/∗ c l i n t o n s i s an in s t an c e o f c l i e n t c r ea t e d when connected to c l i e n tsee In f o method . . i t sends the t e x t to the c l i e n t t h read ∗/c l i n t o n s . Send (msg ) ;

} e l s e {RecieveMsg (msg . s u b s t r i n g (2) , msg . s u b s t r i n g (0 ,1 ) , msg . s u b s t r i n g (1 ,2 ) ) ;

/∗ s e r v i n g i s an in s t anc e o f s e r v e r c r ea t e d in In f o andthe t e x t i s s en t to the s e r v i n g th read ∗/s e r v i n g . Send (msg ) ;

}

//This s e l e c t s a l l t h e t e x t and d e l e t e s i tr e p l y . s e l e c t A l l ( ) ;r e p l y . cu t ( ) ;

}

pub l i c void s end In fo ( S t r i n g msg ) {// I f t h e Send Button i s pushedi f ( ! user . e q u a l s ( ” n u l l ” ) ) // check s c o n n e c t i v i t y{

/∗ c l i n t o n s i s an in s t an c e o f c l i e n t c r ea t e d when connected to c l i e n t

Page 110: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

102see In f o method . . i t sends the t e x t to the c l i e n t t h read ∗/c l i n t o n s . Send ( ”99” + msg ) ;

} e l s e {Recieve ( ” Server : ” + msg ) ;

/∗ s e r v i n g i s an in s t anc e o f s e r v e r c r ea t e d in In f o andthe t e x t i s s en t to the s e r v i n g th read ∗/s e r v i n g . Send ( ”99 Server : ” + msg ) ;

}

//This s e l e c t s a l l t h e t e x t and d e l e t e s i tr e p l y . s e l e c t A l l ( ) ;r e p l y . cu t ( ) ;

}

/∗This i s c a l l e d from the GUIConnection once the app rop r i a t ein fo rmat ion has been en t e r ed t h e r e . This c r e a t e s t he s e r v e r orc l i e n t t h r ead s r e s p e c t i v e l y ∗/

pub l i c void In f o ( in t portNUM , S t r i n g IPAddress , S t r i n g user ){

/∗Port number , IP Address and user ( c l i e n t or s e r v e r ) havebeen passed from the GUIConnection c l a s s and saved ∗/t h i s . portNUM = portNUM ;t h i s . IPAddress = IPAddress ;t h i s . u ser = user ;

i f ( user . e q ua l s ( ” c l i e n t ” ) ) {pane l3 . add ( Send ) ;

pane l3 . add ( Quit ) ;pane l3 . add ( Check ) ;pane l3 . add ( Ca l l ) ;pane l3 . add ( Fold ) ;pane l3 . add ( Bet ) ;pane l3 . add ( Raise ) ;

guiCON . d i s p o s e ( ) ;

// r e s e t s t he T i t l e to c l i e n tt i t l e . s e t I c on (new ImageIcon ( ” c l i e n t . g i f ” ) ) ;

/∗ pa s s e s i t s e l f t o t he c l i e n t t h read so i t canbe a c c e s s s e d ∗/c l i n t o n s = new c l i e n t (portNUM , IPAddress , t h i s ) ;// i s S e r v e r = f a l s e ;

Page 111: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

103

c l i n t o n s . s t a r t ( ) ;}

e l s e {pane l3 . add ( Send ) ;

pane l3 . add ( S t a r t ) ;pane l3 . add ( Quit ) ;pane l3 . add ( Check ) ;pane l3 . add ( Ca l l ) ;pane l3 . add ( Fold ) ;pane l3 . add ( Bet ) ;pane l3 . add ( Raise ) ;

guiCON . d i s p o s e ( ) ;

// s e r v e r j u s t needs por t numbers e r v i n g = new s e r v e r (portNUM , t h i s ) ;// i s S e r v e r = t rue ;

s e r v i n g . s t a r t ( ) ;}

}

/∗These l a s t t h r e e methods are j u s t sma l l methods acce s s edby the ThreadClass threads , c l i e n t threads , s e r v e r th readand by the GUIConnection c l a s s ∗/

//Appends a s t r i n g to the r e c i e v i n g t e x t f i e l dpub l i c void Recieve ( S t r i n g s t r i n g ){

r e c i e v e . append ( ”\n” + s t r i n g ) ;l a s tMsg = s t r i n g ;

}

pub l i c void RecieveData ( S t r i n g UserID , S t r i n g Decis ion , S t r i n g Amount){

userType . getData (UserID , Decis ion , Amount) ;

}

pub l i c void RecieveHand ( S t r i n g to , S t r i n g v1 , S t r i n g s1 , S t r i n g v2 , S t r i n g s2 )

Page 112: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

104{

userType . getHand ( to , v1 , s1 , v2 , s2 ) ;}

pub l i c void RecieveMsg ( S t r i n g s t r i n g , S t r i n g userID , S t r i n g sentID ){

in t x = 99 ;in t x2 = 99 ;i f ( s t r i n g . l e n g t h ( ) < 2) {} e l s e {

i f ( userID . e q ua l s ( ”0” ) | | userID . e q ua l s ( ”1” ) | | userID . e q ua l s ( ”2” ) | | userID . e q ua l s ( ”3” ) | |userID . e q ua l s ( ”4” ) | | userID . e q ua l s ( ”5” ) | | userID . e q ua l s ( ”9” ) ) {try {

x = In t e g e r . p a r s e In t ( userID ) ;} catch ( NumberFormatException n fe ) {

System . out . p r i n t l n ( ” l o l ” + nfe ) ;}i f ( sentID . e q ua l s ( ”0” ) | | sentID . e q ua l s ( ”1” ) | | sentID . e q ua l s ( ”2” ) | | sentID . e q ua l s ( ”3” ) | |

sentID . e q ua l s ( ”4” ) | | sentID . e q ua l s ( ”5” ) | | userID . e q ua l s ( ”9” ) ) {try {

x2 = In t e g e r . p a r s e In t ( sentID ) ;} catch ( NumberFormatException n fe ) {

System . out . p r i n t l n ( ” l o l ” + nfe ) ;}

}i f ( x == t h i s . number | | x == 9) {

r e c i e v e . append ( ”\n” + s t r i n g ) ;l a s tMsg = s t r i n g ;lastMsgID = x2 ;

i f ( user . e q u a l s ( ” c l i e n t ” ) ) {} e l s e {

i f ( ! sentID . e q ua l s ( ”9” ) ) {game . d e c i s i o n ( ) ;

}}

}i f ( x == t h i s . number ) {

i f ( l a s tMsg . e q ua l s ( ”Your turn ” ) ) {userType . Decide ( ) ;

}}

} e l s e {}

}

Page 113: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

105}

pub l i c S t r i n g l a s t ( ) {return t h i s . l a s tMsg ;

}

pub l i c in t l a s t ID ( ) {return t h i s . las tMsgID ;

}

// Saves a c e r t a i n number to t h i s i n s t an c e ( e . g . c l i e n t number 5)pub l i c void Number ( in t number ){

t h i s . number = number ;userType . setNum( t h i s . number ) ;

}

// Al lows user inpu t in the r e p l y t e x t area , a f t e r connec t ionpub l i c void setME( boolean a ){

r e p l y . s e t E d i t a b l e ( a ) ;}

pub l i c void startGame ( ) {game = new Game() ;game . setGUI ( t h i s ) ;game . c r e a t eP l a y e r s (6) ;for ( in t x = 0 ; x < 1 ; x++) {

game . nextHand ( ) ;}

}

//end o f c l a s s}

10.8 File: GUIConnection.java

/∗This i s j u s t d e s i gned to be a sma l l pop up window . I de s i gned i t t h i s way becauseI t hough t i t would l o o k messy on the main GUI and would make the a p p l i c a t i o n too l a r g eCred i t goes to ” In t r o du c t i on to JAVA Programming Third Edi t ion , Y. Danie l Liang .

Page 114: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

106The base code was Writ ten By Tom L i t t l e March 2006 , I adapted i t to s u i t my p r o j e c t w i th h i s permis s ion ∗/

import j a va . awt . ∗ ;import j a va . awt . e ven t . ∗ ;import j a vax . swing . ∗ ;

c la s s GUIConnection extends JFrame implements Act i onL i s t ene r{

pr iva te FlowLayout f l ow = new FlowLayout ( ) ;pr iva te BorderLayout border = new BorderLayout ( ) ;pr iva te JButton CBUTTON = new JButton ( ”Connect” ) ;pr iva te JPanel pane l = new JPanel ( ) ;pr iva te JPanel pane l x = new JPanel ( ) ;pr iva te S t r i n g user , IPAddress ;pr iva te in t portNUM ;pr iva te JTex tF i e l d Number = new JTex tF i e l d (5) ;pr iva te JTex tF i e l d Address = new JTex tF i e l d (5) ;pr iva te GUI gu i ;

//The user i s determined on which rad io bu t t on has been s e l e c t e dpub l i c GUIConnection (GUI gui , S t r i n g user ){

// Saves the passed i n s t anc e o f GUI so i t can be acce s s edt h i s . gu i = gu i ;t h i s . u ser = user ;

// Se t s t he pane l l a y o u t spane l . s e tLayou t ( f l ow ) ;pane l x . s e tLayou t ( f l ow ) ;

// adds va r i ou s t h i n g s to them . .pane l . add (new JLabe l ( ”Port Number” ) ) ;pane l . add (Number ) ;

// C l i e n t r e q u i r e s e x t r a inpu t f o r t he IPi f ( user . e q u a l s ( ” c l i e n t ” ) ) {

pane l . add (new JLabe l ( ” IPAddress ” ) ) ;pane l . add ( Address ) ;

}

//This i s t he ”Connect . . . ” bu t t onpane l x . add (CBUTTON, border .CENTER) ;

CBUTTON. addAc t i onL i s t ener ( t h i s ) ;

Page 115: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

107

//Then the Frame i s pe i c ed t o g e t h e rgetContentPane ( ) . add ( panel , border .NORTH) ;getContentPane ( ) . add ( pane lx , border .SOUTH) ;

}

pub l i c void act ionPer formed ( Act ionEvent ae ){

try {

// i f t h ey c l i c k connect . .i f ( ae . g e tSource ( ) == CBUTTON) {

portNUM = In t e g e r . p a r s e In t (Number . g e tTex t ( ) . tr im ( ) ) ;

i f ( user . e q u a l s ( ” c l i e n t ” ) ) {IPAddress = Address . g e tTex t ( ) . tr im ( ) ;

}e l s e {

//an a r b i t r a r y addre s s which i s n t used by s e r v e rIPAddress = ” l o c a l h o s t ” ;

}

// Sends the r e c i e v e d i n f o to the GUIgu i . In f o (portNUM , IPAddress , user ) ;

}

} catch ( NumberFormatException n fe ) {/∗ has no e f f e c t i f a bogus inpu t i s en t e r edas a por t Number∗/

}

}

//end o f c l a s s}

10.9 File: Human.java

pub l i c c l a s s Human extends User {

Page 116: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

108pr iva te GUI gu i ;

pub l i c s t a t i c void main ( S t r i n g [ ] a rg s ){

Human human = new Human() ;}

pub l i c Human() {GUI gu i = new GUI( t h i s ) ;

}

pub l i c void Decide ( ) {

}

pub l i c void getData ( S t r i n g UserID , S t r i n g Decis ion , S t r i n g Amount) {

}}

10.10 File: Player.java

pub l i c c l a s s Player {Card [ ] p layerCards = new Card [ 2 ] ;in t s t a c k S i z e ;in t cl ientNum ;

pub l i c Player ( in t s ) {s t a c k S i z e = s ;

}

pub l i c in t num() {return cl ientNum ;

}

pub l i c void newHand(Card cardA , Card cardB ) {p layerCards [ 0 ] = new Card ( ) ;p layerCards [ 1 ] = new Card ( ) ;p layerCards [ 0 ] = cardA ;p layerCards [ 1 ] = cardB ;

}}

Page 117: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

10910.11 File: Server.java

/∗Cred i t goes to ” In t r o du c t i on To JAVA Programming ,Third Ed i t i on . By Y. Danie l Liang .” This was o r i g i n a l l yin t ended to be in the GUI bu t because o f t he Se r ve rSocke tl i s t e n i n g in a l oop I r e a l i s e d i t was the reason the programwas f r e e z i n g . The th read a l l ow s c on t r o l to bo th t h i s and the GUI .

The base code was Writ ten By Tom L i t t l e March 2006 , I adapted i t to s u i t my p r o j e c t w i th h i s permis s ion ∗/

import j a va . u t i l . Date ;import j a va . ne t . ∗ ;import j a va . i o . ∗ ;

c la s s s e r v e r extends Thread{

pr iva te S t r i n g user , IPAddress ;pr iva te in t portNUM , number , x ;pr iva te Socke t Sock ;pr iva te GUI gu i ;pr iva te ThreadClass th read ;

//The GUI in s t an c e i s aga in needed to be passedpub l i c s e r v e r ( in t portNUM , GUI gu i ){

t h i s . portNUM = portNUM ;t h i s . gu i = gu i ;

}

pub l i c void run ( ){

try {// the method to pa s t e t e x t i n t o the gu igu i . Rec ieve ( ”\nYou are connected a t por t number ” + portNUM + ” . Waiting f o r C l i e n t s . . ” ) ;

Se r v e rSocke t shh = new Serve rSocke t (portNUM) ;Sock = shh . accep t ( ) ;number = 1 ; // a s s i gned to each c l i e n t

/∗ t h r ead t a k e s bo th the i n s t anc e o f GUI and t h i s i n s t anc e o f s e r v e rbecause i t needs to acc e s s t he Decrement method and the Recievemethod in gu i ∗/

Page 118: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

110t h r ead = new ThreadClass ( Sock , number , gui , t h i s ) ;

/∗Two s t a t i c methods t h a t c r e a t e an ArrayLis t tosave each th read o f c l a s s ThreadClass ∗/ThreadClass . CreateArray ( ) ;ThreadClass . addToArray ( th read ) ;

// l e t s user inpu t t e x tgu i . setME( true ) ;

t h r ead . s t a r t ( ) ;

// j u s t a cons tan t to keep the l oop go ing . .x = 5 ;whi le ( x == 5) {

number++;Sock = shh . accep t ( ) ;t h r ead = new ThreadClass ( Sock , number , gui , t h i s ) ;t h r ead . addToArray ( th read ) ;t h r ead . s t a r t ( ) ;

}

} catch ( UnknownHostException e ) {gu i . Rec ieve ( ”Error : Cannot f i n d the ho s t . ” ) ;

} catch ( IOExcept ion e ) {gu i . Rec ieve ( ”Error : Cannot connect to the ho s t . ” ) ;

}

}

/∗Ca l l e d by the GUI when t e x t has been entered , t h i s j u s tl o op s over a l l t h e t h r ead s o f ThreadClass and sends the sames t r i n g , u s ing the ”Send” method and the s t a t i c getThreadto acce s s t he array and re tu rn a th read ∗/

pub l i c void Send ( S t r i n g s t r i n g ){

for ( in t i = 0 ; i < ThreadClass . ArraySize ( ) ; i++) {ThreadClass threadC = ThreadClass . getThread ( i ) ;threadC . Send ( s t r i n g ) ;

}}

Page 119: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

111/∗Used once a c l i e n t c l o s e s , so t h a t index o f each c l i e n ti s decremented and the nex t c l i e n t to j o i n i s a s s i gned thep r e v i ou s c l i e n t ’ s number∗/pub l i c void Decrement ( ){

number−−;}

//end o f c l a s s . . .}

10.12 File: ThreadClass.java

/∗Cred i t goes to ” In t r o du c t i on to JAVA Programming Third Edi t ion , Y. Danie l Liang .”Here i s where the main communication between c l i e n t and s e r v e r i s done . Eachthreaded in s t anc e o f t h i s c l a s s can communicate wi th the th readed i n s t an c e o f t hec l i e n t c l a s s . I t a c c ep t s messages and sends them f r e e l y .

The base code was Writ ten By Tom L i t t l e March 2006 , I adapted i t to s u i t my p r o j e c t w i th h i s permis s ion ∗/

import j a va . ne t . ∗ ;import j a va . i o . ∗ ;import j a va . u t i l . Date ;import j a va . u t i l . ArrayLis t ;

c la s s ThreadClass extends Thread{

pr iva te Socke t Sock ;pr iva te InputStream in ;pr iva te OutputStream out ;pr iva te S t r i n g message , temp ;pr iva te Prin tWri ter p i n t e r ;pr iva te Buf feredReader b u f f ;pr iva te in t number , x ;pr iva te GUI gu i ;pr iva te s e r v e r SIVE ;

/∗ S t a t i c ArrayLi s t s t o r e s a l l t h e i n s t an c e s o f ThreadClassand t h e r e f o r e has to be s t a t i c ∗/pr iva te s t a t i c ArrayLis t array ;

// S t a t i c method c r e a t e t he ArrayLis t

Page 120: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

112pub l i c s t a t i c void CreateArray ( ){

array = new ArrayLis t ( ) ;}

//This adds a new Thread every t ime one i s c r ea t e d . .pub l i c s t a t i c void addToArray ( ThreadClass th read ){

array . add ( th read ) ;}

//Used in the l oop o f Send method in s e r v e r c l a s spub l i c s t a t i c in t ArraySize ( ){

return array . s i z e ( ) ;}

//Returns ThreadClass from the g i v en index ” i ” in the ArrayLis tpub l i c s t a t i c ThreadClass getThread ( in t i ){

ThreadClass threadC = ( ThreadClass ) array . g e t ( i ) ;return threadC ;

}

/∗Cons t ruc tor save s the i n s t anc e o f s e r v e r and GUI which havec r ea t ed t h i s t h read to l a t e r ac c e s s methods ∗/pub l i c ThreadClass ( Socke t Sock , in t number , GUI gui , s e r v e r SIVE){

try {t h i s . Sock = Sock ;t h i s . number = number ; // c l i e n t indext h i s . gu i = gu i ;t h i s . SIVE = SIVE ; // s e r v e r i n s t an c ein = Sock . ge t InputS t ream () ;

out = Sock . getOutputStream () ;

} catch ( IOExcept ion i o e ) {gu i . Rec ieve ( ”\n” + ioe ) ;

}}

pub l i c void run ( ){

try {// g e t s t he c l i e n t s hostname . . .

Page 121: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

113Ine tAddres s c l i en tAdd = Sock . g e t In e tAdd r e s s ( ) ;

// Sends the Date as an Objec t over a ”new ObjectOutputStream”ObjectOutputStream ObStream = new ObjectOutputStream ( out ) ;Date da te = new Date ( ) ;ObStream . wr i t eOb j e c t ( da te ) ;

// Sends the c l i e n t index ”number” v i a a DataOutputStreamDataOutputStream dos = new DataOutputStream ( out ) ;dos . w r i t e I n t ( number ) ;

message = ”\ nC l i en t ” + number + ” wi th ho s t name ” + c l i en tAdd . getHostName ( ) + ” hasconnected a t ” + date . t o S t r i n g ( ) ;

/∗ Ca l l s t h e gu i ’ s method to append the t e x t Area ,i n d i c a t i n g to the user t h a t a new c l i e n t has a r r i v e d ∗/gu i . Rec ieve ( message ) ;

// l o op s over array , t e l l i n g everyone o f new c l i e n tfor ( in t i = 0 ; i < array . s i z e ( ) ; i++) {

i f ( i == (number − 1) ) {// doesn ’ t want to send to i t s e l f

}e l s e {

ThreadClass th read = ( ThreadClass ) array . g e t ( i ) ;

//Send method sends message to c l i e n t over ou tpu t streamthread . Send ( message ) ;

}

}

} catch ( IOExcept ion i o e ) {

}

try {

b u f f = new Buf feredReader (new InputStreamReader ( in ) ) ;

gu i . Rec ieve ( ”\nWelcome to Dans Poker Pro j e c t \n” ) ;

// j u s t to keep the l oop cons t an t

Page 122: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

114x = 5 ;whi le ( x == 5) {

// reads incoming t e x t from the c l i e n tmessage = b u f f . readLine ( ) ;

// on ly i f t h e user t y p e s q u i t or h i t s t he ”Quit ” bu t t oni f ( message . e q ua l s ( ” q u i t ” ) ) {

Date da te = new Date ( ) ;

temp = ” C l i e n t ” + number + ” has d i s connec t ed a t ” + date . t o S t r i n g ( ) ;

gu i . Rec ieve ( temp ) ;

// l o op s over everyone say ing c l i e n t x had l e f t and whenfor ( in t i = 0 ; i < array . s i z e ( ) ; i++) {

i f ( i == (number − 1) ) {//do no th ing

}e l s e {

ThreadClass th read = ( ThreadClass ) array . g e t ( i ) ;t h r ead . Send ( temp ) ;

}}out . f l u s h ( ) ;Sock . c l o s e ( ) ;// removes c l i e n t from ArrayLis tarray . remove ( number − 1) ;//Takes the count down in s e r v e rSIVE . Decrement ( ) ;//Breaks the l oopx = 6 ;

}

// f o r j u s t a r e g u l a r message . . .i f ( ! message . e q ua l s ( ” q u i t ” ) ) {

for ( in t i = 0 ; i < array . s i z e ( ) ; i++){

Page 123: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

115i f ( i == (number − 1) ) {

//do no th ing}e l s e {

ThreadClass th read = ( ThreadClass ) array . g e t ( i ) ;t h r ead . Send ( message ) ;

}

}

S t r i n g s = message . s u b s t r i n g (0 ,1 ) ;S t r i n g s2 = message . s u b s t r i n g (1 ,2 ) ;

i f ( s . e q u a l s ( ”0” ) | | s . e q u a l s ( ”1” ) | | s . e q ua l s ( ”2” ) | | s . e q ua l s ( ”3” ) | | s . e q ua l s ( ”4” ) | |s . e q ua l s ( ”5” ) | | s . e q u a l s ( ”6” ) | | s . e q u a l s ( ”7” ) | | s . e q ua l s ( ”8” ) | | s . e q ua l s ( ”9” ) ) {gu i . RecieveMsg ( message . s u b s t r i n g (2) , s , s2 ) ;

} e l s e {gu i . Rec ieve ( message ) ;

}// f l u s h e s b u f f e r . .out . f l u s h ( ) ;

}

}//end o f wh i l e l oop

} catch ( IOExcept ion e ) {gu i . Rec ieve ( ”Error : Could not g e t I /O Streams . ” ) ;

}

}//end o f run method

// Jus t uses p r in tWr i t e r to send a S t r i n g acc ro s s t he Output Streampub l i c void Send ( S t r i n g s t r i n g ){

p i n t e r = new Prin tWri ter ( out , true ) ;p i n t e r . p r i n t l n ( s t r i n g ) ;

}

Page 124: An Environment to Develop a 6-handed No Limit …mdv/courses/CM30082/projects.bho/2008-9/Harv… · An Environment to Develop a 6-handed No Limit Texas ... An Environment to Develop

CH

AP

TE

R10.

CO

DE

116

//end o f c l a s s}

10.13 File: User.java

import j a va . awt . ∗ ;import j a va . awt . e ven t . ∗ ;import j a va . i o . ∗ ;import j a va . l ang . ∗ ;import j a va . u t i l . ∗ ;

abs trac t c l a s s User {

pub l i c void Decide ( ) {

}

pub l i c void getData ( S t r i n g UserID , S t r i n g Decis ion , S t r i n g Amount) {

}

pub l i c void setNum( in t num) {

}

pub l i c void getHand ( S t r i n g to , S t r i n g v1 , S t r i n g s1 , S t r i n g v2 , S t r i n g s2 ) {

}}