예제 #1
0
        /// <summary>
        /// adds a sidepot to the pot
        /// </summary>
        /// <param name="player"></param>
        /// <param name="value"></param>
        private void addMySidePot(Player player, int value)
        {
            //if amountPerPlayer > potThisRound, dann nimm alles mit und potThisRound == value + player.inPot
            log.Debug("addMySidePot(Player " + player.name + ", int " + value + ") - Begin");
            List <Player> newPlayers = new List <Player>();

            newPlayers.Add(player);
            Pot p;

            if (amountPerPlayer > potThisRound && amountPerPlayer == value + player.inPot)
            {
                p               = new Pot(this.value + value, value + player.inPot, potThisRound + value, newPlayers, sidePot);
                potThisRound    = 0;
                this.value      = 0;
                amountPerPlayer = 0;
            }
            else
            {
                int times = 1 + (potThisRound / amountPerPlayer);

                int diff = (this.amountPerPlayer - (value + player.inPot)) * (times - 1);
                p                = new Pot(this.value - diff + value, value + player.inPot, this.value - diff + value - player.inPot, newPlayers, sidePot);
                potThisRound     = diff;
                this.value       = diff;
                amountPerPlayer -= p.amountPerPlayer;
            }
            sidePot = p;
            log.Debug("addMySidePot() - End");
        }
예제 #2
0
파일: Pot.cs 프로젝트: B3J4y/Poker
 public Pot(int value, int amountPerPlayer, int potThisRound, List<Player> player, Pot sidePot)
 {
     log.Debug("Pot(int " + value + ", int " + amountPerPlayer + ", int " + potThisRound + ", List<Player> player, Pot sidePot) - Begin");
     this.value = value;
     this.sidePot = sidePot;
     this.player = player;
     this.amountPerPlayer = amountPerPlayer;
     this.potThisRound = potThisRound;
     log.Debug("Pot() - End");
 }
예제 #3
0
파일: Game.cs 프로젝트: B3J4y/Poker
        public Game(List<Player> players, int bb, int sb, Boolean train)
	    {
            log.Debug("Game() - Begin");
            log.Debug("New Game - Player: " + players.Count + " Stakes: " + sb + "/" + bb);
            trainMode = train;
            boolCancel = false;
            blindLevel = 0;
            foreach (Player p in players)
            {
                log.Info("Name: " + p.name + "; Position: " + p.position + "; Stack: " + p.stack);
            }
            this.players = players;
            this.smallBlind = sb;
            this.bigBlind = bb;
            pot = new Pot();
            round = 0;
            players.Sort((x, y) => x.position.CompareTo(y.position));
            for (int i = 2; i < players.Count + 2; i++)
            {
                players.Find(x => (x.position > (i - 2)) && (x.ingamePosition == -1)).ingamePosition = i;
            }
            log.Debug("Game() - End");
	    }
예제 #4
0
 public Game(List <Player> players, int bb, int sb, Boolean train)
 {
     log.Debug("Game() - Begin");
     log.Debug("New Game - Player: " + players.Count + " Stakes: " + sb + "/" + bb);
     trainMode  = train;
     boolCancel = false;
     blindLevel = 0;
     foreach (Player p in players)
     {
         log.Info("Name: " + p.name + "; Position: " + p.position + "; Stack: " + p.stack);
     }
     this.players    = players;
     this.smallBlind = sb;
     this.bigBlind   = bb;
     pot             = new Pot();
     round           = 0;
     players.Sort((x, y) => x.position.CompareTo(y.position));
     for (int i = 2; i < players.Count + 2; i++)
     {
         players.Find(x => (x.position > (i - 2)) && (x.ingamePosition == -1)).ingamePosition = i;
     }
     log.Debug("Game() - End");
 }
예제 #5
0
 /// <summary>
 /// builds string for the side pots
 /// </summary>
 /// <param name="sidePot"></param>
 /// <param name="i"></param>
 /// <param name="s"></param>
 /// <returns></returns>
 private static string getSidePots(Pot sidePot, int i, string s)
 {
     log.Debug("getSidePots(Pot, i: " + i.ToString() + ", s: " + s.ToString() + ") - Begin");
     if (sidePot == null)
     {
         log.Debug("getSidePots() == null - End");
         return s;
     }
     else
     {
         log.Debug("getSidePots() - End");
         return getSidePots(sidePot.sidePot, i+1 ,s + "SidePot" + i + ": " + sidePot.value.ToString() + " ");
     }
 }
예제 #6
0
 public Pot(int value, int amountPerPlayer, int potThisRound, List <Player> player, Pot sidePot)
 {
     log.Debug("Pot(int " + value + ", int " + amountPerPlayer + ", int " + potThisRound + ", List<Player> player, Pot sidePot) - Begin");
     this.value           = value;
     this.sidePot         = sidePot;
     this.player          = player;
     this.amountPerPlayer = amountPerPlayer;
     this.potThisRound    = potThisRound;
     log.Debug("Pot() - End");
 }
예제 #7
0
파일: Game.cs 프로젝트: B3J4y/Poker
        /// <summary>
        /// determines the winning players and shows how much they won
        /// </summary>
        /// <returns></returns>
        public List<Winner> whoIsWinner(Pot pot, List<Player> playersInGame)
        {
            log.Debug("whoIsWinner() - Begin");
            List<Winner> result = new List<Winner>();
            //List<Player> playersInGame = players.FindAll(x => x.isActive);
            playersInGame.AddRange(pot.player);
            List<KeyValuePair<Player, Hand>> playerHand = new List<KeyValuePair<Player, Hand>>();
            Console.WriteLine(boardToString());
            if (playersInGame.Count > 0)
            {

                //determines Hand Value
                foreach (Player player in playersInGame)
                {
                    playerHand.Add(new KeyValuePair<Player, Hand>(player, new Hand(player.getCardsToString(), boardToString())));
                    Console.WriteLine(player.name + " " + player.getCardsToString() + " " + new Hand(player.getCardsToString(), boardToString()).HandValue + " " + new Hand(player.getCardsToString(), boardToString()).HandTypeValue);
                }
                playerHand.Sort((x, y ) => x.Value.HandValue.CompareTo(y.Value.HandValue));
                //WinnerHands
                result.Add(new Winner(playerHand[playerHand.Count - 1].Key, playerHand[playerHand.Count - 1].Value.HandTypeValue.ToString()));
                for (int i = playerHand.Count - 2; i >= 0; i--)
                {
                    if (playerHand[playerHand.Count - 1].Value.HandValue == playerHand[i].Value.HandValue)
                    {
                        result.Add(new Winner(playerHand[i].Key, playerHand[i].Value.HandTypeValue.ToString()));

                    }
                    else
                    {
                        playerHand[i].Key.isActive = false;
                    }
                }
                if (result.Count == 1)
                {
                    result[0].value = pot.value;
                    result[0].player.stack += result[0].value;
                    result[0].player.isAllin = false;
                }
                else
                {
                    int mod = (pot.value / result.Count) % bigBlind;
                    Player first = new Player(activePlayer);
                    try
                    {
                        // nonActives = players.FindAll(x => (!x.isActive)).Count;
                        first = whoIsNext(players.Count - nonActives - 1, false);
                    }
                    catch (NoPlayerInGameException e)
                    {
                        first = activePlayer;
                    }

                    while (mod > 0)
                    {
                        Winner myPlayer = result.Find(x => x.player.name == first.name);
                        myPlayer.value += smallBlind;
                        pot.value -= smallBlind;
                        mod = (pot.value / result.Count) % bigBlind;
                    }

                    for (int j = 0; j < result.Count; j++)
                    {
                        result[j].value += (pot.value / result.Count);
                        result[j].player.stack += result[j].value;
                        if (result[j].player.stack > 0)
                        {

                            result[j].player.isAllin = false;
                        }
                    }
                }
            
                foreach(Winner w in result){
                    Logger.action(this, w.player, Action.playerAction.wins, w.value, board);
                }
            }
            if (pot.sidePot != null)
            {
                result.AddRange(whoIsWinner(pot.sidePot, playersInGame));
                pot.sidePot = null;
            }
            pot.value = 0;
            pot.potThisRound = 0;
            pot.player = new List<Player>();
            log.Debug("whoIsWinner() - End");
            return result;
        }
예제 #8
0
        /// <summary>
        /// determines the winning players and shows how much they won
        /// </summary>
        /// <returns></returns>
        public List <Winner> whoIsWinner(Pot pot, List <Player> playersInGame)
        {
            log.Debug("whoIsWinner() - Begin");
            List <Winner> result = new List <Winner>();

            //List<Player> playersInGame = players.FindAll(x => x.isActive);
            playersInGame.AddRange(pot.player);
            List <KeyValuePair <Player, Hand> > playerHand = new List <KeyValuePair <Player, Hand> >();

            Console.WriteLine(boardToString());
            if (playersInGame.Count > 0)
            {
                //determines Hand Value
                foreach (Player player in playersInGame)
                {
                    playerHand.Add(new KeyValuePair <Player, Hand>(player, new Hand(player.getCardsToString(), boardToString())));
                    Console.WriteLine(player.name + " " + player.getCardsToString() + " " + new Hand(player.getCardsToString(), boardToString()).HandValue + " " + new Hand(player.getCardsToString(), boardToString()).HandTypeValue);
                }
                playerHand.Sort((x, y) => x.Value.HandValue.CompareTo(y.Value.HandValue));
                //WinnerHands
                result.Add(new Winner(playerHand[playerHand.Count - 1].Key, playerHand[playerHand.Count - 1].Value.HandTypeValue.ToString()));
                for (int i = playerHand.Count - 2; i >= 0; i--)
                {
                    if (playerHand[playerHand.Count - 1].Value.HandValue == playerHand[i].Value.HandValue)
                    {
                        result.Add(new Winner(playerHand[i].Key, playerHand[i].Value.HandTypeValue.ToString()));
                    }
                    else
                    {
                        playerHand[i].Key.isActive = false;
                    }
                }
                if (result.Count == 1)
                {
                    result[0].value          = pot.value;
                    result[0].player.stack  += result[0].value;
                    result[0].player.isAllin = false;
                }
                else
                {
                    int    mod   = (pot.value / result.Count) % bigBlind;
                    Player first = new Player(activePlayer);
                    try
                    {
                        // nonActives = players.FindAll(x => (!x.isActive)).Count;
                        first = whoIsNext(players.Count - nonActives - 1, false);
                    }
                    catch (NoPlayerInGameException e)
                    {
                        first = activePlayer;
                    }

                    while (mod > 0)
                    {
                        Winner myPlayer = result.Find(x => x.player.name == first.name);
                        myPlayer.value += smallBlind;
                        pot.value      -= smallBlind;
                        mod             = (pot.value / result.Count) % bigBlind;
                    }

                    for (int j = 0; j < result.Count; j++)
                    {
                        result[j].value        += (pot.value / result.Count);
                        result[j].player.stack += result[j].value;
                        if (result[j].player.stack > 0)
                        {
                            result[j].player.isAllin = false;
                        }
                    }
                }

                foreach (Winner w in result)
                {
                    Logger.action(this, w.player, Action.playerAction.wins, w.value, board);
                }
            }
            if (pot.sidePot != null)
            {
                result.AddRange(whoIsWinner(pot.sidePot, playersInGame));
                pot.sidePot = null;
            }
            pot.value        = 0;
            pot.potThisRound = 0;
            pot.player       = new List <Player>();
            log.Debug("whoIsWinner() - End");
            return(result);
        }
예제 #9
0
파일: Pot.cs 프로젝트: B3J4y/Poker
        /// <summary>
        /// adds a sidepot to the pot
        /// </summary>
        /// <param name="player"></param>
        /// <param name="value"></param>
        private void addMySidePot(Player player, int value)
        {
            //if amountPerPlayer > potThisRound, dann nimm alles mit und potThisRound == value + player.inPot
            log.Debug("addMySidePot(Player "  +player.name + ", int " + value + ") - Begin");
            List<Player> newPlayers = new List<Player>();
            newPlayers.Add(player);
            Pot p;
            if (amountPerPlayer > potThisRound && amountPerPlayer == value + player.inPot)
            {
                p = new Pot(this.value + value, value + player.inPot, potThisRound + value, newPlayers, sidePot);
                potThisRound = 0;
                this.value = 0;
                amountPerPlayer = 0;
            }
            else
            {
                int times = 1 + (potThisRound / amountPerPlayer);

                int diff = (this.amountPerPlayer - (value + player.inPot)) * (times - 1);
                p = new Pot(this.value - diff + value, value + player.inPot, this.value - diff + value - player.inPot, newPlayers, sidePot);
                potThisRound = diff;
                this.value = diff;
                amountPerPlayer -= p.amountPerPlayer;

            }
            sidePot = p;
            log.Debug("addMySidePot() - End");
        }