patterncsharpMinor
Poker game implementation
Viewed 0 times
pokerimplementationgame
Problem
I have included almost all features that real poker game contains, but even tho I tried to make it as clean as possible, I think it can be done much better. I used inheritance to somewhat distinct player seating, getting ready for hand to actually playing the game, but then again some things as moving the button depends on seated players. So I don't know what to do here. Some pointers would be great. Also getting state of hand, table seem as a problem, since not every detail about game is accessible from child class.
I want to say that I don't ask for specific implementation, but what should be designed differently to approach my goals much easily and of course improved code quality.
In my opinion there are 3 relevant classes:
I have also created a question some time ago about implementing a Poker Card Ranker.
```
namespace Poker.Game
{
public abstract class PokerTable {
/*
* Represents first bet size.
* It is a positive number.
*/
protected readonly Decimal SmallBlind;
/*
* Represents second bet size.
* Is atleast two times bigger than smallBlind.
* And it is positive number.
*/
protected readonly Decimal BigBlind;
/*
* Maximum amount of players at table.
*/
private readonly uint MaxPlayers;
/*
* Contains all players who are in current hand(not folded, not waiting).
* If player folds/leaves then he is removed from this list.
*/
protected CircularList playersInHand;
/*
* Contains all players who are sitting at table either waiting or playing a hand.
* key is seat at which player is seated,
* value is Player who is sitting there.
*/
private Dictionary playersAtTable = new Dictionary();
/*
* Creates basic game instance with setting blind and max player count.
*/
public PokerTable(Decimal smallBlind, Decimal bigBlind, uint maxPlayers)
{
if (bigBlind / 2 = M
I want to say that I don't ask for specific implementation, but what should be designed differently to approach my goals much easily and of course improved code quality.
In my opinion there are 3 relevant classes:
PokerTable, PokerGame and Player.I have also created a question some time ago about implementing a Poker Card Ranker.
PokerTable```
namespace Poker.Game
{
public abstract class PokerTable {
/*
* Represents first bet size.
* It is a positive number.
*/
protected readonly Decimal SmallBlind;
/*
* Represents second bet size.
* Is atleast two times bigger than smallBlind.
* And it is positive number.
*/
protected readonly Decimal BigBlind;
/*
* Maximum amount of players at table.
*/
private readonly uint MaxPlayers;
/*
* Contains all players who are in current hand(not folded, not waiting).
* If player folds/leaves then he is removed from this list.
*/
protected CircularList playersInHand;
/*
* Contains all players who are sitting at table either waiting or playing a hand.
* key is seat at which player is seated,
* value is Player who is sitting there.
*/
private Dictionary playersAtTable = new Dictionary();
/*
* Creates basic game instance with setting blind and max player count.
*/
public PokerTable(Decimal smallBlind, Decimal bigBlind, uint maxPlayers)
{
if (bigBlind / 2 = M
Solution
Methods/Properties headers in C# starts with
Also, you have too much comments. Usually, try to comment explaining why you did something, not how. That, people will figure it out quite easily. I can understand that you want method headers, but properties headers should rarely be longer than a few words and fields shouldn't be commented (not even headers) unless it it really important.
Watch your indentation, some of your code is hard to look at because there's not enough spacing. In C#, braces are on a line each, which means :
becomes
It is somehow easier to read and respects the coding standards.
Try to keep your constants at the top of your file and keep your order consistent. Let's say you have this template :
Try and keep it the same way everywhere. (This order is out of my hat, it doesn't exactly respect the C# coding standards if I'm not mistaken).
///. Try it in Visual Studio, you'll see that it's much better, plus it generates the header template for you!Also, you have too much comments. Usually, try to comment explaining why you did something, not how. That, people will figure it out quite easily. I can understand that you want method headers, but properties headers should rarely be longer than a few words and fields shouldn't be commented (not even headers) unless it it really important.
Watch your indentation, some of your code is hard to look at because there's not enough spacing. In C#, braces are on a line each, which means :
void methodA(){
}becomes
void methodA()
{
}It is somehow easier to read and respects the coding standards.
Try to keep your constants at the top of your file and keep your order consistent. Let's say you have this template :
- constants
- fields
- properties
- constructors
- methods
Try and keep it the same way everywhere. (This order is out of my hat, it doesn't exactly respect the C# coding standards if I'm not mistaken).
Code Snippets
void methodA(){
}void methodA()
{
}Context
StackExchange Code Review Q#104843, answer score: 3
Revisions (0)
No revisions yet.