Poker tournament app

Hi, I need help writing a program in C# to record winning hands and have it to deal out chips to player profiles after the final round. I also need help with creating a function to list the types of winning hands and how often they occurred. I’ve been stuck on these for a while now and this is my only option. Any help is grateful. Thank you!

this is my code

GAME.CS////////////////

using System;
using System.Collections.Generic;

namespace Poker_Tournament_App
{

class Game
{

   int Id{get; set;}
   string WinningHand{get; set;}
   bool FinalRoundGame{get; set;}

   List<Player> players = new List<Player>();

   public Game()
   {
     Id = 404;
     WinningHand = "";
     FinalRoundGame = false;
   }

   //Initialize without players
     public Game(int inId, string inWinningHand, bool inFinalRoundGame)
     {
       Id = inId;
       WinningHand = inWinningHand;
       FinalRoundGame = inFinalRoundGame;
     }

    //Initialize with player(s)
     public Game(int inId, string inWinningHand, bool inFinalRoundGame, List<Player> inPlayers)
     {
       Id = inId;
       WinningHand = inWinningHand;
       FinalRoundGame = inFinalRoundGame;
       addPlayers(inPlayers);
     }

     public void addPlayers(List<Player> inPlayers)
     {
       players.AddRange(inPlayers);
     }
   }
 }

END///////////

PLAYER.CS///////////////

using System;
using System.Collections.Generic;

namespace Poker_Tournament_App
{

class Player
{
     public string name {get; set;}
     public DateTime dateJoined {get; set;} //new DateTime(year, month, day)
     public DateTime birthday {get; set;} //new DateTime(year, month, day)
     public string hometown {get; set;}
     public int rankChips {get; set;} //new DateTime(year, month, day)

     Dictionary<string, int> winningHandCount = new Dictionary<string, int>();

     public Player()
     {
        name = "";
        dateJoined = new DateTime(1900, 01, 01);
        birthday = new DateTime(1900, 01, 01);
        hometown = "";
        rankChips = 0;
     }

     public Player(string inName, DateTime inDateJoined, DateTime inBirthday, string inHometown, int inRankChips)
     {
        name = inName;
        dateJoined = inDateJoined;
        birthday = inBirthday;
        hometown = inHometown;
        rankChips = inRankChips;
     }
     public void updateWinningHandCount(string inHandType)
     {
        if(winningHandCount.ContainsKey(inHandType))
        {
        winningHandCount[inHandType] = winningHandCount[inHandType] + 1;
        }
        else
        {
        winningHandCount.Add(inHandType, 1);
        }
     }
   }
}

END///////////////////////

PROGRAM.CS/////////////

using System;

namespace Poker_Tournament_App
{
class Program
{
public static void Main (string args) {
string selection;

           Console.WriteLine("Select an option:\n ");
           Console.WriteLine("1: Tournaments");
           Console.WriteLine("2: Players");
           Console.WriteLine("3: Overall Stats");
           Console.WriteLine("4: Save & Quit");
           selection = Console.ReadLine();

           if (selection == "1")
           {
              Console.WriteLine("Tournaments.");
           }
          else if(selection == "2")
          {
              Console.WriteLine("Players.");
          }
         else if(selection == "3")
         {
              Console.WriteLine("Overall Stats.");
         }
         else if(selection == "4")
        {
              Console.WriteLine("Byeeeeeeeeeeeeeee");
        }

    }
    }

}

END/////////////////

TOURNAMENT.CS/////////////

using System;

namespace Poker_Tournament_App
{
class Tournament
{
public string Name{get; set;}
public string Location{get; set;}
public int MaxPlayers{get; set;}

    DateTime _tournamentDate;

    public DateTime TournamentDate
    {
         get
         {
             return this._tournamentDate;
         }
         set
         {
             this._tournamentDate = value.Date;
         }
    }

    public Tournament()
    {
       Name = "";
       TournamentDate = new DateTime(1900, 01, 01);
       Location = "";
       MaxPlayers = 0;
    }
    public Tournament(string inName, DateTime inDate, string inLocation, int inMaxPlayers)
   {
       Name = inName;
       TournamentDate = inDate;
       Location = inLocation;
       MaxPlayers = inMaxPlayers;
   }

   public override string ToString()
   {
       string printString = "";
       printString += "\nName:\t\t" + Name;
       printString += "\nDate:\t\t" + TournamentDate.ToString("d");
       printString += "\nLocation:\t" + Location;
       printString += "\nMax Players:" + MaxPlayers;
       return printString;
   }

}

}

END///////////////////

Hi,

When you get a moment, please reformat your code as this is going to be hard for people to read: [How to] Format code in posts

it is fixed thank you :slight_smile:

1 Like

i still need help on the code though thank you

What’s actually wrong with the code? Are you getting errors, or is the output not what you expected?

nothing is wrong with the code, i need helping writing a program that will record the winning hand and have it to deal out chips to player profiles after the final round, and also a program that helps with creating a function to list the types of winning hand and how often they occurred. The existing code is what I’ve written to start my project. I’m creating a poker tournament app

I’ve tried many times but i cant get it to properly work so that’s why i’m reaching out to you guys to see if you could help me out

Hi,

Consider focusing your question a little further. Like if you have trouble getting one function to do something specific, that’s something you could ask about. If you have trouble with the concept layout, share a sketch of your layout for constructive criticism.

Define record the winning hand. Record it where? How long is it meant to live?

List winning hands and how often they occured is just a case of recording that information (presumably this would be part of recording the winning hand) and then retrieving it and displaying it however. Once you do recording retrieving will be not much more.

Overall, I would suggest you slow it down. Don’t worry about building end game stuff when you haven’t built the core.

Start but having a game start with just two players. Then control cards being delt. So now you will have a card dealing simulator basically. You don’t say what form of poker but then add logic like swapping cards or whatever.

Next you may want to add betting. Again, there won’t be any logic to pick a winner at this point, so you may want to add logic that randomly pick a winner when one should be decided.

Then add logic to evaluate the hands and decide the actual winner.

Then expand it so you can have more players.

While that probably isn’t the best order / way to break it down, I’m sure you get the point. The fact is, don’t try make the game from scratch there will be too many moving parts and you will jump around onto the next bit before what you was doing is finished. It might help you make a game where the different parts are decoupled, i.e. to make a game where you want to change how the winner is decided, you might make a ‘IHandEvaluator’ interface that has a method that returns a hand rank or some such that you can use to see who hold the better hand. This will then be injected to wherever it is needed, you can start will a class that implements it by returning a random rank but then swap it for a class that does the real work once written only having to change the IoC container. Again an oversimplified example but the core principle stands.