SlideShare ist ein Scribd-Unternehmen logo
1 von 22
14-01-2016
Automated Poker Player
Automated Poker Player
C#
ENGR334
Wasim Akbar
Student name Student number Signature
Danish Bangash 34071407
Supervisor(s):
14-01-2016
Automated Poker Player
1
Table of Contents
1. INTRODUCTION................................................................................................................................. 2
1.1 SYSTEM DESCRIPTION...............................................................................................................2
2. REQUIREMENTS SPECIFICATION ............................................................................................... 2
3. DESIGN MODEL ................................................................................................................................. 3
3.1 SOLUTION CLASSES/INTERFACES .............................................................................................3
3.1.1 Cards.cs..............................................................................................................................3
3.1.2 DeckOfCards.cs.................................................................................................................4
3.1.3 DrawCards.cs ....................................................................................................................5
3.1.4 DealCards.cs......................................................................................................................6
3.1.5 HandEvaluator.cs..............................................................................................................8
3.1 FLOW CHART OF AUTOMATED POKER PLAYER....................................................................11
4. TESTING............................................................................................................................................. 12
5. CONCLUSION.................................................................................................................................... 13
6. APPENDICES ..................................................................................................................................... 14
6.1 SOURCE CODE C# .....................................................................................................................14
6.1.1 Cards.cs.............................................................................................................................14
6.1.2 DealCards.cs .....................................................................................................................14
6.1.3 DeckOfCards ....................................................................................................................16
6.1.4 DrawCards ........................................................................................................................17
6.1.5 HandEvaluator ..................................................................................................................18
6.1.6 Program.cs ........................................................................................................................20
14-01-2016
Automated Poker Player
2
1. Introduction
1.1 System description
The Automated Poker-Player System provides widely known single player poker
game with all requirements and rules of original game. This game has a deck of 52 cards
with 13 values each and 4 suits. The automated poker player system is implemented in the
‘C#’ programming environment platform which consist of six classes, Card,
DeckOfCards, DrawCards, DealCards, HandEvaluator, and the execution class
Program.cs.
Card class holds the value and suit of the card whereas the DeckOfCards inherits from the
Card class to access the suit and value of each card. Before the card is dealt the card needs
to be drawn in order to display them and cards are dealt. DealCards class is responsible for
dealing the cards, whereas the HandEvaluator class evaluates the hands by recognizing the
winning hands like Flush, Straight and StraightFlush. Program class executes the program.
After the program is executed it can be played through the console, following the
commands on the screen.
2. Requirements specification
Requirements
R1 The program implements automated poker player.
R2 The program recognises the winning hand.
R3 The program recognises the Flush hand.
R4 The Program recognises the Straight hand.
R5 The program recognises the StraightFlush hand.
R6 The Royal flush hand has not been implemented into the program.
R7 The program return nothing if no winning hand is shown.
14-01-2016
Automated Poker Player
3
3. Design model
We can divide this application into six classes each class will hold its own responsibility
it is defined to. We intended to have a simple and understandable design for the automated
poker player. We will need a class which can hold the cards suit and value and then we can
use that particular class which holds the value and suit of the card to create the deck of 52
cards and put them into array and shuffle the cards. We will also need a way to deal the
cards after we have shuffled them, one of the classes will hold the responsibility to deal the
cards, after the cards are dealt we will need a way to display the cards on the screen in our
case we will be using a console to execute the program. After dealing and display the cards
on the screen we will then evaluate the winning cards and find a way to recognise the
winning hands like Flush, Straight etc.
3.1 Solution classes/Interfaces
3.1.1 Cards.cs
 Out of first thing we need a class of cards so we created a class called Card.cs
 This class will simply have the suit for the card and the value of the card.
 The suits being HEARTS, SPADES, CLUBS and DIAMONDS.
 The values for the cards are TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, and
NINE, JACK, QUEEN, KING, and ACE.
 The best way to do this is by the enumeration for the suits and values, as shown in the
codes snip below:
14-01-2016
Automated Poker Player
4
 We can also do some properties to retrieve the values from the enumeration as we can
see in the codes below.
3.1.2 DeckOfCards.cs
 This class will inherit from Card class because we need the access to know the suit and
value of each card.
 First we create 52 cards in the deck, then we create an array of cards, as show in codes
below.
 We construct the deck of cards by the following:
 To have the ability to retrieve the current deck we need to do the following
 To create the deck of 52 cards with 13 values each and 4 suits, we set up the deck by the
following:
14-01-2016
Automated Poker Player
5
 In the above code snip what we are doing is, simply populating the array of deck with
suits and values.
 After setting up the deck we need to shuffle the card by the following method:
 Once the deck array is populated we will simply shuffle the deck randomly.
3.1.3 DrawCards.cs
 This is still a console application but the console has several properties and methods that
enables us to do some drawing on the screen.
 Also there an encoding that enables us to display hearts, diamonds, clubs , and spades,
 To draw the outline of the cards are done by the following method shown below:
14-01-2016
Automated Poker Player
6
 To show the suits and value of the card and also Red for HEARTS and DIAMONDS
and Black for CLUBS and SPADES is done by the following method:
 And finally we display the value and suit of the card
3.1.4 DealCards.cs
 Firstly we need cards for the player.
 As we know from the deck of cards class, we created the deck and then we shuffled the
cards randomly. What we need is a way to sort the cards, which is going to help us
effectively when determining the hand of the player, if they are in order we will be able to
determine the highest card which will be the last one and determine the smallest card
which will be the first one, then we will be able to sort them in their proper order.
 We will create an array for the player and then construct the array, when we deal the
cards the player will have 5 cards in hand, then we will sort the player’s hand.
 The way we deal the cards is that, we set up the deck of 52 cards and shuffle them
randomly, for setting up the deck and shuffling the deck, we will inherit from the Card
Class,
14-01-2016
Automated Poker Player
7
 We will then get the hand for the player by calling getHand() method
 Cards are sorted by calling the sortCards() method, and display the sorted cards on the
console.
14-01-2016
Automated Poker Player
8
 After displaying the sorted hand we will evaluate the hand by calling the
evaluateHands() method:
3.1.5 HandEvaluator.cs
 In this class we will do some enumeration which in our case will be the hand to keep
track of what type of hand is possible, so if the hand is a bad hand then we have
‘Nothing’, or else ‘Straight’, ‘Flush’, ‘StraightFlsuh’.
 HandEvaluator class inherits from the Card Class, because we will use the suits and the
values.
 Then we evaluate the sorted hand, and do some properties for the cards and the hand
value, as we can see in the code snip below:
14-01-2016
Automated Poker Player
9
 To evaluate hand we will first get the number of suit, we will have to loop through the
cards. If the elements in suit is equal to ‘Hearts’, ‘Diamonds’, ‘Clubs’ or ‘Spades’ we
increment it by 1, as shown below:
 After doing all the programming above, we created the actual hands such as ‘Straight’,
‘Flush’, ‘StraightFlush’.
 For the ‘Flush’ hand, if all suits are the same
 For ‘Straight’, if 5 consecutive values:
14-01-2016
Automated Poker Player
10
 For ‘StraightFlush’, if all suits are the same as well as there are 5 consecutive values:
 To evaluate hand if we get the number of suits and according to that number of suits,
if we have a Flush we return hand of Flush, if it is a straight then the system return
hand of straight and if it is Straightflush system returns hand of Straightflush. If the
hand is bad system return Nothing:
14-01-2016
Automated Poker Player
11
3.1 Flow Chart of Automated Poker Player
14-01-2016
Automated Poker Player
12
4. Testing
 We test the system if it runs properly without any bugs and errors and we
did not encountered any errors so the program starts fine as expected.
 Then we tested the system for a bad hand, what will the system respond if we
have a bad hand, so the system returns ‘Nothing’ in indication to a bad cards
or no winning hand:
 After testing the bad hand, we test for the winning hands like ‘Flush’ and
‘Straight’, the probability for getting those two winning hands is very low, it
means the system takes a lot of time to get the winning hands, figures below
shows the system recognizes the winning hands the way it is expected:
14-01-2016
Automated Poker Player
13
5. Conclusion
The task given by the supervisor has been concluded by a successful program for the
automated poker player. The Program can determine three winning hands ‘Flush’,
‘Straight’, ‘StraightFlush’, the only thing the system cannot determine is the RoyalFlush.
Due to lack of knowledge the final hand requirement has not been implemented but in the
next iteration of the program more improvements are expected such as, RoyalFlush,
increasing the probability of getting each hand, implementing some other winning hands
such as OnePair, TwoPair and so on. The program has been tested properly through the
process for bugs and other errors and exceptions, we faced a lot of difficulties but as we
went through the process we finished the project with a good result.
14-01-2016
Automated Poker Player
14
6. Appendices
6.1 Source code C#
6.1.1 Cards.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomatedPokerPlayer
{
class Card
{
public enum SUIT
{
HEARTS,
SPADES,
DIAMONDS,
CLUBS
}
public enum VALUE
{
TWO = 2, THREE, FOUR, FIVE, SIX, SEVEN,
EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE
}
public SUIT MySuit { get; set; }
public VALUE MyValue { get; set; }
}
}
6.1.2 DealCards.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomatedPokerPlayer
{
class DealCards : DeckOfCards
{
private Card[] playerHand;
private Card[] sortedPlayerHand;
public DealCards()
{
playerHand = new Card[5];
14-01-2016
Automated Poker Player
15
sortedPlayerHand = new Card[5];
}
public void Deal()
{
setUpDeck();
getHand();
sortCards();
displayCards();
evaluateHands();
}
public void getHand()
{
for (int i = 0; i < 5; i++)
playerHand[i] = getDeck[i];
}
public void sortCards()
{
var queryPlayer = from hand in playerHand
orderby hand.MyValue
select hand;
var index = 0;
foreach (var element in queryPlayer.ToList())
{
sortedPlayerHand[index] = element;
index++;
}
}
public void displayCards()
{
Console.Clear();
int x = 0;
int y = 1;
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("PLAYER'S HAND");
for (int i = 0; i < 5; i++)
{
DrawCards.DrawCardOutline(x, y);
DrawCards.DrawCardSuitValue(sortedPlayerHand[i], x, y);
x++;
}
}
public void evaluateHands()
{
HandEvaluator playerHandEvaluator = new HandEvaluator(sortedPlayerHand);
Hand playerHand = playerHandEvaluator.EvaluateHand();
Console.WriteLine("nnnnnPlayer's Hand: " + playerHand);
}
}
}
14-01-2016
Automated Poker Player
16
6.1.3 DeckOfCards
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomatedPokerPlayer
{
class DeckOfCards : Card
{
const int NUM_OF_CARDS = 52;
private Card[] deck;
public DeckOfCards()
{
deck = new Card[NUM_OF_CARDS];
}
public Card[] getDeck { get { return deck; } }
public void setUpDeck()
{
int i = 0;
foreach (SUIT s in Enum.GetValues(typeof(SUIT)))
{
foreach (VALUE v in Enum.GetValues(typeof(VALUE)))
{
deck[i] = new Card { MySuit = s, MyValue = v };
i++;
}
}
ShuffleCards();
}
public void ShuffleCards()
{
Random rand = new Random();
Card temp;
for (int shuffleTimes = 0; shuffleTimes < 55; shuffleTimes++)
{
for (int i = 0; i < NUM_OF_CARDS; i++)
{
int secondCardIndex = rand.Next(13);
temp = deck[i];
deck[i] = deck[secondCardIndex];
deck[secondCardIndex] = temp;
}
}
}
}
}
14-01-2016
Automated Poker Player
17
6.1.4 DrawCards
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomatedPokerPlayer
{
class DrawCards
{
public static void DrawCardOutline(int xcoor, int ycoor)
{
Console.ForegroundColor = ConsoleColor.Black;
int x = xcoor * 12;
int y = ycoor;
Console.SetCursorPosition(x, y);
Console.Write(" __________n");
for (int i = 0; i < 10; i++)
{
Console.SetCursorPosition(x, y + 1 + i);
if (i != 9)
Console.WriteLine("| |");
else
Console.WriteLine("|__________|");
}
}
public static void DrawCardSuitValue(Card card, int xcoor, int ycoor)
{
int x = xcoor * 12;
int y = ycoor;
switch (card.MySuit)
{
case Card.SUIT.HEARTS:
Console.ForegroundColor = ConsoleColor.Red;
break;
case Card.SUIT.DIAMONDS:
Console.ForegroundColor = ConsoleColor.Red;
break;
case Card.SUIT.CLUBS:
Console.ForegroundColor = ConsoleColor.Black;
break;
case Card.SUIT.SPADES:
Console.ForegroundColor = ConsoleColor.Black;
break;
}
Console.SetCursorPosition(x + 2, y + 5);
Console.Write(card.MySuit);
Console.SetCursorPosition(x + 3, y + 7);
Console.Write(card.MyValue);
14-01-2016
Automated Poker Player
18
}
}
}
6.1.5 HandEvaluator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomatedPokerPlayer
{
public enum Hand
{
Nothing,
Straightflush,
Straight,
Flush,
}
class HandEvaluator : Card
{
private int heartsSum;
private int diamondSum;
private int clubSum;
private int spadesSum;
private Card[] cards;
public HandEvaluator(Card[] sortedHand)
{
heartsSum = 0;
diamondSum = 0;
clubSum = 0;
spadesSum = 0;
cards = new Card[5];
Cards = sortedHand;
}
public Card[] Cards
{
get { return cards; }
set
{
cards[0] = value[0];
cards[1] = value[1];
cards[2] = value[2];
cards[3] = value[3];
cards[4] = value[4];
}
}
private void getNumberOfSuit()
14-01-2016
Automated Poker Player
19
{
foreach (var element in Cards)
{
if (element.MySuit == Card.SUIT.HEARTS)
heartsSum++;
else if (element.MySuit == Card.SUIT.DIAMONDS)
diamondSum++;
else if (element.MySuit == Card.SUIT.CLUBS)
clubSum++;
else if (element.MySuit == Card.SUIT.SPADES)
spadesSum++;
}
}
public Hand EvaluateHand()
{
getNumberOfSuit();
if (Flush())
return Hand.Flush;
else if (Straight())
return Hand.Straight;
else if (Straightflush())
return Hand.Straightflush;
return Hand.Nothing;
}
private bool Flush()
{
if (heartsSum == 5 || diamondSum == 5 || clubSum == 5 || spadesSum == 5)
{
return true;
}
return false;
}
private bool Straight()
{
if (cards[0].MyValue + 1 == cards[1].MyValue &&
cards[1].MyValue + 1 == cards[2].MyValue &&
cards[2].MyValue + 1 == cards[3].MyValue &&
cards[3].MyValue + 1 == cards[4].MyValue)
{
return true;
}
return false;
}
private bool Straightflush()
{
if (
heartsSum == 5 ||
diamondSum == 5 ||
clubSum == 5 ||
spadesSum == 5 &&
cards[0].MyValue + 1 == cards[1].MyValue &&
cards[1].MyValue + 1 == cards[2].MyValue &&
cards[2].MyValue + 1 == cards[3].MyValue &&
14-01-2016
Automated Poker Player
20
cards[3].MyValue + 1 == cards[4].MyValue
)
{
return true;
}
return false;
}
}
}
6.1.6 Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomatedPokerPlayer
{
class Program
{
static void Main(string[] args)
{
Console.SetWindowSize(65, 40);
Console.BufferWidth = 65;
Console.BufferHeight = 40;
Console.Title = "Automated Poker Player";
DealCards dc = new DealCards();
bool quit = false;
while (!quit)
{
dc.Deal();
char selection = ' ';
while (!selection.Equals('Y') && !selection.Equals('N'))
{
Console.WriteLine("Play again? Y-N");
selection = Convert.ToChar(Console.ReadLine().ToUpper());
if (selection.Equals('Y'))
quit = false;
else if (selection.Equals('N'))
quit = true;
else
Console.WriteLine("Invalid Selection. Try again");
}
}
Console.ReadKey();
}
}
}
14-01-2016
Automated Poker Player
21

Weitere ähnliche Inhalte

Ähnlich wie Automated Poker Player System Evaluates Hands

project 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docxproject 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docxbriancrawford30935
 
Poker Texas Holdem English
Poker Texas Holdem   EnglishPoker Texas Holdem   English
Poker Texas Holdem EnglishMárcio Guerra
 
Corona Poker Player Guide
Corona Poker Player GuideCorona Poker Player Guide
Corona Poker Player GuideCoronapoker
 
COMP 220 HELP Lessons in Excellence--comp220help.com
COMP 220 HELP Lessons in Excellence--comp220help.comCOMP 220 HELP Lessons in Excellence--comp220help.com
COMP 220 HELP Lessons in Excellence--comp220help.comthomashard85
 
Ch11 Search & Sort
Ch11 Search & SortCh11 Search & Sort
Ch11 Search & Sortleminhvuong
 
I have another assignment due for an advance java programming class .pdf
I have another assignment due for an advance java programming class .pdfI have another assignment due for an advance java programming class .pdf
I have another assignment due for an advance java programming class .pdfFORTUNE2505
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number TutorialOXUS 20
 
COMP 220 Entire Course NEW
COMP 220 Entire Course NEWCOMP 220 Entire Course NEW
COMP 220 Entire Course NEWshyamuopeight
 
Comp 220 i lab 1 two dimensional arrays lab report and source code
Comp 220 i lab 1 two dimensional arrays lab report and source codeComp 220 i lab 1 two dimensional arrays lab report and source code
Comp 220 i lab 1 two dimensional arrays lab report and source codepradesigali1
 
Social Media Game Concept - Hearts ( as visible in Windows games arena)
Social Media Game Concept - Hearts ( as visible in Windows games arena)Social Media Game Concept - Hearts ( as visible in Windows games arena)
Social Media Game Concept - Hearts ( as visible in Windows games arena)Ankit Gupta
 
Yu-gi-oh 5Ds Official Rulebook
Yu-gi-oh 5Ds Official RulebookYu-gi-oh 5Ds Official Rulebook
Yu-gi-oh 5Ds Official RulebookHaris Setiawan
 
FaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdfFaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdfabifancystore
 
Game design document - BadBug Studio - Xbox Game
Game design document - BadBug Studio - Xbox GameGame design document - BadBug Studio - Xbox Game
Game design document - BadBug Studio - Xbox GameUTC Fire & Security
 
Taking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain ModelingTaking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain ModelingCameron Presley
 
Teaching a Computer To Play Blackjack.doc
Teaching a Computer To Play Blackjack.docTeaching a Computer To Play Blackjack.doc
Teaching a Computer To Play Blackjack.docbutest
 
Turtle strategyforbj
Turtle strategyforbjTurtle strategyforbj
Turtle strategyforbjhumbertobe
 

Ähnlich wie Automated Poker Player System Evaluates Hands (20)

Yu-gi-oh GX Rulebook
Yu-gi-oh GX RulebookYu-gi-oh GX Rulebook
Yu-gi-oh GX Rulebook
 
project 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docxproject 6cards.pyimport randomclass Card( object ).docx
project 6cards.pyimport randomclass Card( object ).docx
 
Game Theory
Game TheoryGame Theory
Game Theory
 
Poker Texas Holdem English
Poker Texas Holdem   EnglishPoker Texas Holdem   English
Poker Texas Holdem English
 
Corona Poker Player Guide
Corona Poker Player GuideCorona Poker Player Guide
Corona Poker Player Guide
 
COMP 220 HELP Lessons in Excellence--comp220help.com
COMP 220 HELP Lessons in Excellence--comp220help.comCOMP 220 HELP Lessons in Excellence--comp220help.com
COMP 220 HELP Lessons in Excellence--comp220help.com
 
Ch11 Search & Sort
Ch11 Search & SortCh11 Search & Sort
Ch11 Search & Sort
 
I have another assignment due for an advance java programming class .pdf
I have another assignment due for an advance java programming class .pdfI have another assignment due for an advance java programming class .pdf
I have another assignment due for an advance java programming class .pdf
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
 
Game Rules
Game RulesGame Rules
Game Rules
 
COMP 220 Entire Course NEW
COMP 220 Entire Course NEWCOMP 220 Entire Course NEW
COMP 220 Entire Course NEW
 
Comp 220 i lab 1 two dimensional arrays lab report and source code
Comp 220 i lab 1 two dimensional arrays lab report and source codeComp 220 i lab 1 two dimensional arrays lab report and source code
Comp 220 i lab 1 two dimensional arrays lab report and source code
 
Social Media Game Concept - Hearts ( as visible in Windows games arena)
Social Media Game Concept - Hearts ( as visible in Windows games arena)Social Media Game Concept - Hearts ( as visible in Windows games arena)
Social Media Game Concept - Hearts ( as visible in Windows games arena)
 
Yu-gi-oh 5Ds Official Rulebook
Yu-gi-oh 5Ds Official RulebookYu-gi-oh 5Ds Official Rulebook
Yu-gi-oh 5Ds Official Rulebook
 
Yugioh rlbk
Yugioh rlbkYugioh rlbk
Yugioh rlbk
 
FaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdfFaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdf
 
Game design document - BadBug Studio - Xbox Game
Game design document - BadBug Studio - Xbox GameGame design document - BadBug Studio - Xbox Game
Game design document - BadBug Studio - Xbox Game
 
Taking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain ModelingTaking a Gamble with Functional Domain Modeling
Taking a Gamble with Functional Domain Modeling
 
Teaching a Computer To Play Blackjack.doc
Teaching a Computer To Play Blackjack.docTeaching a Computer To Play Blackjack.doc
Teaching a Computer To Play Blackjack.doc
 
Turtle strategyforbj
Turtle strategyforbjTurtle strategyforbj
Turtle strategyforbj
 

Mehr von Danish Bangash

Metal detector project presentation
Metal detector project presentationMetal detector project presentation
Metal detector project presentationDanish Bangash
 
Metal Detector Project
Metal Detector ProjectMetal Detector Project
Metal Detector ProjectDanish Bangash
 
Project 3 “Satellite Link Budgets and PE”
Project 3 “Satellite Link Budgets and PE”Project 3 “Satellite Link Budgets and PE”
Project 3 “Satellite Link Budgets and PE”Danish Bangash
 
Project 2: Baseband Data Communication
Project 2: Baseband Data CommunicationProject 2: Baseband Data Communication
Project 2: Baseband Data CommunicationDanish Bangash
 
Project 1 “Signal Power, Noise, SNR and Auto- and Cross Correlation”
Project 1 “Signal Power, Noise, SNR and Auto- and Cross Correlation”Project 1 “Signal Power, Noise, SNR and Auto- and Cross Correlation”
Project 1 “Signal Power, Noise, SNR and Auto- and Cross Correlation”Danish Bangash
 
Finite Element Method Magnetics (FEMM) simulation
Finite Element Method Magnetics (FEMM) simulationFinite Element Method Magnetics (FEMM) simulation
Finite Element Method Magnetics (FEMM) simulationDanish Bangash
 
Design For Manufacturing_ Report
Design For Manufacturing_ ReportDesign For Manufacturing_ Report
Design For Manufacturing_ ReportDanish Bangash
 
Bachelor- thesis, optimization of wireless power transfer coils using finite ...
Bachelor- thesis, optimization of wireless power transfer coils using finite ...Bachelor- thesis, optimization of wireless power transfer coils using finite ...
Bachelor- thesis, optimization of wireless power transfer coils using finite ...Danish Bangash
 

Mehr von Danish Bangash (8)

Metal detector project presentation
Metal detector project presentationMetal detector project presentation
Metal detector project presentation
 
Metal Detector Project
Metal Detector ProjectMetal Detector Project
Metal Detector Project
 
Project 3 “Satellite Link Budgets and PE”
Project 3 “Satellite Link Budgets and PE”Project 3 “Satellite Link Budgets and PE”
Project 3 “Satellite Link Budgets and PE”
 
Project 2: Baseband Data Communication
Project 2: Baseband Data CommunicationProject 2: Baseband Data Communication
Project 2: Baseband Data Communication
 
Project 1 “Signal Power, Noise, SNR and Auto- and Cross Correlation”
Project 1 “Signal Power, Noise, SNR and Auto- and Cross Correlation”Project 1 “Signal Power, Noise, SNR and Auto- and Cross Correlation”
Project 1 “Signal Power, Noise, SNR and Auto- and Cross Correlation”
 
Finite Element Method Magnetics (FEMM) simulation
Finite Element Method Magnetics (FEMM) simulationFinite Element Method Magnetics (FEMM) simulation
Finite Element Method Magnetics (FEMM) simulation
 
Design For Manufacturing_ Report
Design For Manufacturing_ ReportDesign For Manufacturing_ Report
Design For Manufacturing_ Report
 
Bachelor- thesis, optimization of wireless power transfer coils using finite ...
Bachelor- thesis, optimization of wireless power transfer coils using finite ...Bachelor- thesis, optimization of wireless power transfer coils using finite ...
Bachelor- thesis, optimization of wireless power transfer coils using finite ...
 

Kürzlich hochgeladen

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 

Kürzlich hochgeladen (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 

Automated Poker Player System Evaluates Hands

  • 1. 14-01-2016 Automated Poker Player Automated Poker Player C# ENGR334 Wasim Akbar Student name Student number Signature Danish Bangash 34071407 Supervisor(s):
  • 2. 14-01-2016 Automated Poker Player 1 Table of Contents 1. INTRODUCTION................................................................................................................................. 2 1.1 SYSTEM DESCRIPTION...............................................................................................................2 2. REQUIREMENTS SPECIFICATION ............................................................................................... 2 3. DESIGN MODEL ................................................................................................................................. 3 3.1 SOLUTION CLASSES/INTERFACES .............................................................................................3 3.1.1 Cards.cs..............................................................................................................................3 3.1.2 DeckOfCards.cs.................................................................................................................4 3.1.3 DrawCards.cs ....................................................................................................................5 3.1.4 DealCards.cs......................................................................................................................6 3.1.5 HandEvaluator.cs..............................................................................................................8 3.1 FLOW CHART OF AUTOMATED POKER PLAYER....................................................................11 4. TESTING............................................................................................................................................. 12 5. CONCLUSION.................................................................................................................................... 13 6. APPENDICES ..................................................................................................................................... 14 6.1 SOURCE CODE C# .....................................................................................................................14 6.1.1 Cards.cs.............................................................................................................................14 6.1.2 DealCards.cs .....................................................................................................................14 6.1.3 DeckOfCards ....................................................................................................................16 6.1.4 DrawCards ........................................................................................................................17 6.1.5 HandEvaluator ..................................................................................................................18 6.1.6 Program.cs ........................................................................................................................20
  • 3. 14-01-2016 Automated Poker Player 2 1. Introduction 1.1 System description The Automated Poker-Player System provides widely known single player poker game with all requirements and rules of original game. This game has a deck of 52 cards with 13 values each and 4 suits. The automated poker player system is implemented in the ‘C#’ programming environment platform which consist of six classes, Card, DeckOfCards, DrawCards, DealCards, HandEvaluator, and the execution class Program.cs. Card class holds the value and suit of the card whereas the DeckOfCards inherits from the Card class to access the suit and value of each card. Before the card is dealt the card needs to be drawn in order to display them and cards are dealt. DealCards class is responsible for dealing the cards, whereas the HandEvaluator class evaluates the hands by recognizing the winning hands like Flush, Straight and StraightFlush. Program class executes the program. After the program is executed it can be played through the console, following the commands on the screen. 2. Requirements specification Requirements R1 The program implements automated poker player. R2 The program recognises the winning hand. R3 The program recognises the Flush hand. R4 The Program recognises the Straight hand. R5 The program recognises the StraightFlush hand. R6 The Royal flush hand has not been implemented into the program. R7 The program return nothing if no winning hand is shown.
  • 4. 14-01-2016 Automated Poker Player 3 3. Design model We can divide this application into six classes each class will hold its own responsibility it is defined to. We intended to have a simple and understandable design for the automated poker player. We will need a class which can hold the cards suit and value and then we can use that particular class which holds the value and suit of the card to create the deck of 52 cards and put them into array and shuffle the cards. We will also need a way to deal the cards after we have shuffled them, one of the classes will hold the responsibility to deal the cards, after the cards are dealt we will need a way to display the cards on the screen in our case we will be using a console to execute the program. After dealing and display the cards on the screen we will then evaluate the winning cards and find a way to recognise the winning hands like Flush, Straight etc. 3.1 Solution classes/Interfaces 3.1.1 Cards.cs  Out of first thing we need a class of cards so we created a class called Card.cs  This class will simply have the suit for the card and the value of the card.  The suits being HEARTS, SPADES, CLUBS and DIAMONDS.  The values for the cards are TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, and NINE, JACK, QUEEN, KING, and ACE.  The best way to do this is by the enumeration for the suits and values, as shown in the codes snip below:
  • 5. 14-01-2016 Automated Poker Player 4  We can also do some properties to retrieve the values from the enumeration as we can see in the codes below. 3.1.2 DeckOfCards.cs  This class will inherit from Card class because we need the access to know the suit and value of each card.  First we create 52 cards in the deck, then we create an array of cards, as show in codes below.  We construct the deck of cards by the following:  To have the ability to retrieve the current deck we need to do the following  To create the deck of 52 cards with 13 values each and 4 suits, we set up the deck by the following:
  • 6. 14-01-2016 Automated Poker Player 5  In the above code snip what we are doing is, simply populating the array of deck with suits and values.  After setting up the deck we need to shuffle the card by the following method:  Once the deck array is populated we will simply shuffle the deck randomly. 3.1.3 DrawCards.cs  This is still a console application but the console has several properties and methods that enables us to do some drawing on the screen.  Also there an encoding that enables us to display hearts, diamonds, clubs , and spades,  To draw the outline of the cards are done by the following method shown below:
  • 7. 14-01-2016 Automated Poker Player 6  To show the suits and value of the card and also Red for HEARTS and DIAMONDS and Black for CLUBS and SPADES is done by the following method:  And finally we display the value and suit of the card 3.1.4 DealCards.cs  Firstly we need cards for the player.  As we know from the deck of cards class, we created the deck and then we shuffled the cards randomly. What we need is a way to sort the cards, which is going to help us effectively when determining the hand of the player, if they are in order we will be able to determine the highest card which will be the last one and determine the smallest card which will be the first one, then we will be able to sort them in their proper order.  We will create an array for the player and then construct the array, when we deal the cards the player will have 5 cards in hand, then we will sort the player’s hand.  The way we deal the cards is that, we set up the deck of 52 cards and shuffle them randomly, for setting up the deck and shuffling the deck, we will inherit from the Card Class,
  • 8. 14-01-2016 Automated Poker Player 7  We will then get the hand for the player by calling getHand() method  Cards are sorted by calling the sortCards() method, and display the sorted cards on the console.
  • 9. 14-01-2016 Automated Poker Player 8  After displaying the sorted hand we will evaluate the hand by calling the evaluateHands() method: 3.1.5 HandEvaluator.cs  In this class we will do some enumeration which in our case will be the hand to keep track of what type of hand is possible, so if the hand is a bad hand then we have ‘Nothing’, or else ‘Straight’, ‘Flush’, ‘StraightFlsuh’.  HandEvaluator class inherits from the Card Class, because we will use the suits and the values.  Then we evaluate the sorted hand, and do some properties for the cards and the hand value, as we can see in the code snip below:
  • 10. 14-01-2016 Automated Poker Player 9  To evaluate hand we will first get the number of suit, we will have to loop through the cards. If the elements in suit is equal to ‘Hearts’, ‘Diamonds’, ‘Clubs’ or ‘Spades’ we increment it by 1, as shown below:  After doing all the programming above, we created the actual hands such as ‘Straight’, ‘Flush’, ‘StraightFlush’.  For the ‘Flush’ hand, if all suits are the same  For ‘Straight’, if 5 consecutive values:
  • 11. 14-01-2016 Automated Poker Player 10  For ‘StraightFlush’, if all suits are the same as well as there are 5 consecutive values:  To evaluate hand if we get the number of suits and according to that number of suits, if we have a Flush we return hand of Flush, if it is a straight then the system return hand of straight and if it is Straightflush system returns hand of Straightflush. If the hand is bad system return Nothing:
  • 12. 14-01-2016 Automated Poker Player 11 3.1 Flow Chart of Automated Poker Player
  • 13. 14-01-2016 Automated Poker Player 12 4. Testing  We test the system if it runs properly without any bugs and errors and we did not encountered any errors so the program starts fine as expected.  Then we tested the system for a bad hand, what will the system respond if we have a bad hand, so the system returns ‘Nothing’ in indication to a bad cards or no winning hand:  After testing the bad hand, we test for the winning hands like ‘Flush’ and ‘Straight’, the probability for getting those two winning hands is very low, it means the system takes a lot of time to get the winning hands, figures below shows the system recognizes the winning hands the way it is expected:
  • 14. 14-01-2016 Automated Poker Player 13 5. Conclusion The task given by the supervisor has been concluded by a successful program for the automated poker player. The Program can determine three winning hands ‘Flush’, ‘Straight’, ‘StraightFlush’, the only thing the system cannot determine is the RoyalFlush. Due to lack of knowledge the final hand requirement has not been implemented but in the next iteration of the program more improvements are expected such as, RoyalFlush, increasing the probability of getting each hand, implementing some other winning hands such as OnePair, TwoPair and so on. The program has been tested properly through the process for bugs and other errors and exceptions, we faced a lot of difficulties but as we went through the process we finished the project with a good result.
  • 15. 14-01-2016 Automated Poker Player 14 6. Appendices 6.1 Source code C# 6.1.1 Cards.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutomatedPokerPlayer { class Card { public enum SUIT { HEARTS, SPADES, DIAMONDS, CLUBS } public enum VALUE { TWO = 2, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE } public SUIT MySuit { get; set; } public VALUE MyValue { get; set; } } } 6.1.2 DealCards.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutomatedPokerPlayer { class DealCards : DeckOfCards { private Card[] playerHand; private Card[] sortedPlayerHand; public DealCards() { playerHand = new Card[5];
  • 16. 14-01-2016 Automated Poker Player 15 sortedPlayerHand = new Card[5]; } public void Deal() { setUpDeck(); getHand(); sortCards(); displayCards(); evaluateHands(); } public void getHand() { for (int i = 0; i < 5; i++) playerHand[i] = getDeck[i]; } public void sortCards() { var queryPlayer = from hand in playerHand orderby hand.MyValue select hand; var index = 0; foreach (var element in queryPlayer.ToList()) { sortedPlayerHand[index] = element; index++; } } public void displayCards() { Console.Clear(); int x = 0; int y = 1; Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("PLAYER'S HAND"); for (int i = 0; i < 5; i++) { DrawCards.DrawCardOutline(x, y); DrawCards.DrawCardSuitValue(sortedPlayerHand[i], x, y); x++; } } public void evaluateHands() { HandEvaluator playerHandEvaluator = new HandEvaluator(sortedPlayerHand); Hand playerHand = playerHandEvaluator.EvaluateHand(); Console.WriteLine("nnnnnPlayer's Hand: " + playerHand); } } }
  • 17. 14-01-2016 Automated Poker Player 16 6.1.3 DeckOfCards using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutomatedPokerPlayer { class DeckOfCards : Card { const int NUM_OF_CARDS = 52; private Card[] deck; public DeckOfCards() { deck = new Card[NUM_OF_CARDS]; } public Card[] getDeck { get { return deck; } } public void setUpDeck() { int i = 0; foreach (SUIT s in Enum.GetValues(typeof(SUIT))) { foreach (VALUE v in Enum.GetValues(typeof(VALUE))) { deck[i] = new Card { MySuit = s, MyValue = v }; i++; } } ShuffleCards(); } public void ShuffleCards() { Random rand = new Random(); Card temp; for (int shuffleTimes = 0; shuffleTimes < 55; shuffleTimes++) { for (int i = 0; i < NUM_OF_CARDS; i++) { int secondCardIndex = rand.Next(13); temp = deck[i]; deck[i] = deck[secondCardIndex]; deck[secondCardIndex] = temp; } } } } }
  • 18. 14-01-2016 Automated Poker Player 17 6.1.4 DrawCards using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutomatedPokerPlayer { class DrawCards { public static void DrawCardOutline(int xcoor, int ycoor) { Console.ForegroundColor = ConsoleColor.Black; int x = xcoor * 12; int y = ycoor; Console.SetCursorPosition(x, y); Console.Write(" __________n"); for (int i = 0; i < 10; i++) { Console.SetCursorPosition(x, y + 1 + i); if (i != 9) Console.WriteLine("| |"); else Console.WriteLine("|__________|"); } } public static void DrawCardSuitValue(Card card, int xcoor, int ycoor) { int x = xcoor * 12; int y = ycoor; switch (card.MySuit) { case Card.SUIT.HEARTS: Console.ForegroundColor = ConsoleColor.Red; break; case Card.SUIT.DIAMONDS: Console.ForegroundColor = ConsoleColor.Red; break; case Card.SUIT.CLUBS: Console.ForegroundColor = ConsoleColor.Black; break; case Card.SUIT.SPADES: Console.ForegroundColor = ConsoleColor.Black; break; } Console.SetCursorPosition(x + 2, y + 5); Console.Write(card.MySuit); Console.SetCursorPosition(x + 3, y + 7); Console.Write(card.MyValue);
  • 19. 14-01-2016 Automated Poker Player 18 } } } 6.1.5 HandEvaluator using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutomatedPokerPlayer { public enum Hand { Nothing, Straightflush, Straight, Flush, } class HandEvaluator : Card { private int heartsSum; private int diamondSum; private int clubSum; private int spadesSum; private Card[] cards; public HandEvaluator(Card[] sortedHand) { heartsSum = 0; diamondSum = 0; clubSum = 0; spadesSum = 0; cards = new Card[5]; Cards = sortedHand; } public Card[] Cards { get { return cards; } set { cards[0] = value[0]; cards[1] = value[1]; cards[2] = value[2]; cards[3] = value[3]; cards[4] = value[4]; } } private void getNumberOfSuit()
  • 20. 14-01-2016 Automated Poker Player 19 { foreach (var element in Cards) { if (element.MySuit == Card.SUIT.HEARTS) heartsSum++; else if (element.MySuit == Card.SUIT.DIAMONDS) diamondSum++; else if (element.MySuit == Card.SUIT.CLUBS) clubSum++; else if (element.MySuit == Card.SUIT.SPADES) spadesSum++; } } public Hand EvaluateHand() { getNumberOfSuit(); if (Flush()) return Hand.Flush; else if (Straight()) return Hand.Straight; else if (Straightflush()) return Hand.Straightflush; return Hand.Nothing; } private bool Flush() { if (heartsSum == 5 || diamondSum == 5 || clubSum == 5 || spadesSum == 5) { return true; } return false; } private bool Straight() { if (cards[0].MyValue + 1 == cards[1].MyValue && cards[1].MyValue + 1 == cards[2].MyValue && cards[2].MyValue + 1 == cards[3].MyValue && cards[3].MyValue + 1 == cards[4].MyValue) { return true; } return false; } private bool Straightflush() { if ( heartsSum == 5 || diamondSum == 5 || clubSum == 5 || spadesSum == 5 && cards[0].MyValue + 1 == cards[1].MyValue && cards[1].MyValue + 1 == cards[2].MyValue && cards[2].MyValue + 1 == cards[3].MyValue &&
  • 21. 14-01-2016 Automated Poker Player 20 cards[3].MyValue + 1 == cards[4].MyValue ) { return true; } return false; } } } 6.1.6 Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutomatedPokerPlayer { class Program { static void Main(string[] args) { Console.SetWindowSize(65, 40); Console.BufferWidth = 65; Console.BufferHeight = 40; Console.Title = "Automated Poker Player"; DealCards dc = new DealCards(); bool quit = false; while (!quit) { dc.Deal(); char selection = ' '; while (!selection.Equals('Y') && !selection.Equals('N')) { Console.WriteLine("Play again? Y-N"); selection = Convert.ToChar(Console.ReadLine().ToUpper()); if (selection.Equals('Y')) quit = false; else if (selection.Equals('N')) quit = true; else Console.WriteLine("Invalid Selection. Try again"); } } Console.ReadKey(); } } }