示例#1
0
文件: Winner.cs 项目: B3J4y/Poker
 public Winner(Player player, String str)
 {
     log.Debug("Winner(Player " + player.name + ", String " + str +") - Begin");
     this.player = player;
     this.hand = str;
     log.Debug("Winner() - End");
 }
示例#2
0
文件: Player.cs 项目: B3J4y/Poker
 public Player(Player player)
 {
     log.Debug("Player(Player " + player.name + ")");
     this.isActive = player.isActive;
     this.stack = player.stack;
     this.cards = player.cards;
     this.position = player.position;
     this.ingamePosition = player.ingamePosition;
     this.inGame = player.inGame;
     this.inPot = player.inPot;
     this.name = player.name;
     this.hasChecked = player.hasChecked;
     this.isAllin = player.isAllin;
     log.Debug("Player() - End");
 }
示例#3
0
文件: Log.cs 项目: B3J4y/Poker
 public static void action(Game gl, Player player, SurfacePoker.Action.playerAction action, int amount, List<Card> board)
 {
     log.Debug("action(Game gl, Player "+ player.name + ", SurfacePoker.Action.playerAction "+ action+ ", int " + amount + ", List<Card> board) - Begin");
     String str = "";
     foreach(Card c in board){
         str += c.ToString();
     }
     if (player.cards.Count != 0)
     {
         log.Info(player.name+ ";" + player.stack + ";" + action.ToString() + ";" + amount + ";" + player.getCardsToString() + ";" + str + ";" + gl.pot.value + ";" + player.winChance);
     }
     else
     {
         log.Info(player.name + ";" + player.stack + ";" + action.ToString() + ";" + amount + "; ;" + str + ";"+ gl.pot.value + ";0");
     }
     log.Debug("action() - End");
 }
示例#4
0
文件: Game.cs 项目: B3J4y/Poker
        /// <summary>
        /// starts a new game and set back all relevant attributes
        /// </summary>
        public Player newGame()
        {
            
            log.Debug("new Game() - Begin");
            bigBlind = blindStructur[blindLevel];
            smallBlind = blindStructur[blindLevel] / 2;
            log.Debug("Blindlevel: " + smallBlind + "/" + bigBlind);
            deck = new Deck();
            round = 0;
            board = new List<Card>();
            pot.amountPerPlayer = bigBlind;
            nonActives = players.FindAll(x =>  (x.stack == 0)).Count;
            int j = 0;
            players.Sort((x, y) => x.ingamePosition.CompareTo(y.ingamePosition));
            bool firstplayer = !boolCancel;
            if (players.Count - nonActives == 1)
            {
                log.Debug("EndGameException");
                throw new EndGameException("End of Game - Only one player left");
            }
            Logger.action(this, dealer, Action.playerAction.newgame, 0, board);
            for (int k = 0; k < players.Count; k++)
            {
                if (players[k].stack > 0)
                {

                    players[k].isActive = true;
                    players[k].isAllin = false;
                    players[k].hasChecked = false;
                    Logger.action(this, players[k], Action.playerAction.ingame, 0, board);
                }
                else
                {
                    players[k].isActive = false;
                    players[k].isAllin = false;
                    
                }
                players[k].totalInPot = 0;
            }
            for (int i = 0; i < players.Count; i++)
            {
                players[i].inPot = 0;
                players[i].totalInPot = 0;
                if (players[i].stack > 0)
                {
                    if (firstplayer)
                    {
                        players[i].ingamePosition = players.Count - nonActives;
                        firstplayer = false;
                        Logger.action(this, players[i], Action.playerAction.bigblind, bigBlind, board);
                        if(players[i].stack >= bigBlind){
                            pot.raisePot(players[i], bigBlind);
                            players[i].action(bigBlind);
                        }
                        else
                        {
                            pot.raisePot(players[i], smallBlind);
                            players[i].action(smallBlind);
                        }
                    }
                    else
                    {
                        if (!boolCancel)
                        {
                            players[i].ingamePosition = i - j;
                            if (players[i].ingamePosition == players.Count - nonActives - 1)
                            {
                                Logger.action(this, players[i], Action.playerAction.smallblind, smallBlind, board);
                                pot.amountPerPlayer = smallBlind;
                                pot.raisePot(players[i], smallBlind);
                                players[i].action(smallBlind);
                            }
                        }
                        else
                        {
                            if (players[i].ingamePosition == players.Count - nonActives - 1)
                            {
                                Logger.action(this, players[i], Action.playerAction.smallblind, smallBlind, board);
                                pot.amountPerPlayer = smallBlind;
                                pot.raisePot(players[i], smallBlind);
                                players[i].action(smallBlind);
                            }
                            if (players[i].ingamePosition == players.Count - nonActives)
                            {
                                Logger.action(this, players[i], Action.playerAction.bigblind, bigBlind, board);
                                pot.amountPerPlayer = bigBlind;
                                pot.raisePot(players[i], bigBlind);
                                players[i].action(bigBlind);
                                boolCancel = false;
                            }
                        }

                    }
                    players[i].cards = new List<Card>();
                    players[i].setOneCard(deck.DealNext());
                    players[i].setOneCard(deck.DealNext());
                    
                }
                else
                {
                    players[i].cards = new List<Card>();
                    j++;
                    players[i].ingamePosition = 0;
                }
            }
            if (pot.sidePot != null)
            {
                if (pot.sidePot.amountPerPlayer < bigBlind)
                {
                    pot.amountPerPlayer = smallBlind;
                }
            }
            else
            {
                pot.amountPerPlayer = bigBlind;
            }
            pot.raiseSize = bigBlind;

            Logger.calculateWinChance(this);

            foreach (Player p in players)
            {
                Logger.action(this, p, Action.playerAction.nothing, 0, new List<Card>());
                log.Debug("Name: " + p.name + ", Position: " + p.ingamePosition + ", Stack: " + p.stack);
            }
            activePlayer = null;
            nextActivePlayer = null;
            if ((players.Count - nonActives) >= 3)
            {
                log.Debug("new Game() - End");
                return players.Find(x => x.ingamePosition == (players.Count - nonActives - 2));
            }
            else
            {
                log.Debug("new Game() - End");
                return players.Find(x => x.ingamePosition == (players.Count - nonActives));
            }
        }
示例#5
0
文件: Game.cs 项目: B3J4y/Poker
 private void NewPlayRound()
 {
     players = new List<Player>();
     for (int i = 0; i < PLAYERCOUNT; i++)
     {
         Player player = new Player("Player" + i, 1000, i+1);
         players.Add(player);
     }
     gl = new Game(players, bb, sb, true);
 }
示例#6
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;
        }
示例#7
0
文件: Game.cs 项目: B3J4y/Poker
 /// <summary>
 /// initialize the next round
 /// </summary>
 public KeyValuePair<Player, List<Action>> nextRound()
 {
     log.Debug("nextRound() - Begin");
     round++;
     switch (round) {
         case 1:
             board.Add(deck.DealNext());
             board.Add(deck.DealNext());
             board.Add(deck.DealNext());
             break;
         case 2:
             board.Add(deck.DealNext());
             break;
         case 3:
             board.Add(deck.DealNext());
             break;
         case 4:
             break;
     }
     Logger.action(this, dealer, Action.playerAction.nothing, 0, board);
     Logger.calculateWinChance(this);
     foreach (Player player in players)
     {
         player.hasChecked = false;
         player.totalInPot += player.inPot;
         player.inPot = 0;
     }
     pot.amountPerPlayer = 0;
     pot.raiseSize = 0;
     //active Player after DealerButton
     //int nonActives = players.FindAll(x => (x.isAllin) | (!x.isActive)).Count;
     activePlayer = whoIsNext(players.Count - nonActives - 1, true);
     nextActivePlayer = whoIsNext(activePlayer.ingamePosition + 1, true);
     pot.endOfRound();
     log.Debug("nextRound() - End");
     return getActions();
 }
示例#8
0
文件: Game.cs 项目: B3J4y/Poker
        /// <summary>
        /// determines which possibilities the active player has
        /// </summary>
        /// <returns>KeyValuePair: key - active Player; value - List of possibile actions</returns>
        public KeyValuePair<Player, List<Action>> nextPlayer()
        {
            log.Debug("nextPlayer() - Begin");
            if ((activePlayer == null) && (nextActivePlayer == null))
            {
                activePlayer = players.Find(x => x.ingamePosition == 1);
                nextActivePlayer = players.Find(x => x.ingamePosition == 2);
            }
            else
            {
                activePlayer = nextActivePlayer;
                try
                {

                    nextActivePlayer = whoIsNext();
                }
                catch (NoPlayerInGameException exp)
                {
                    log.Debug("NoPlayerInGameException");
                    throw exp;
                }
                catch (EndRoundException exp)
                {
                    log.Debug("EndRoundException");
                    throw exp;
                }

            }
            log.Debug("nextPlayer() - End");
            return getActions();
        }
示例#9
0
文件: Pot.cs 项目: B3J4y/Poker
        /// <summary>
        /// creates a sidepot
        /// takes the other sidepots into consideration
        /// </summary>
        /// <param name="player">player who goes allin</param>
        /// <param name="value"></param>
        public void createSidePot(Player player, int value)
        {
            log.Debug("createSidePot(Player " + player.name + ", int " + value + ") - Begin");
            if (this.sidePot == null)
            {
                addMySidePot(player, value);
            }
            else
            {

                if (this.sidePot.amountPerPlayer == value + player.inPot)
                {
                    this.sidePot.potThisRound += value;
                    this.sidePot.value += value;
                    this.player.Add(player);

                }
                else
                {
                    if (this.sidePot.amountPerPlayer > value + player.inPot)
                    {
                        this.sidePot.createSidePot(player, value);
                    }
                    else
                    {
                        List<Player> newPlayers = new List<Player>();
                        newPlayers.Add(player);
                        int times = potThisRound / this.AmountPerPlayer;
                        int diff = this.amountPerPlayer - (value + player.inPot);
                        int valuediff = this.value - diff * times;
                        this.AmountPerPlayer = diff;
                        this.value = times * diff;
                        this.potThisRound -= times * diff;
                        this.sidePot.value += sidePot.amountPerPlayer - player.inPot;
                        this.potThisRound += sidePot.amountPerPlayer - player.inPot;
                        this.sidePot = new Pot(value + player.inPot-sidePot.amountPerPlayer + valuediff,
                            value + player.inPot - sidePot.amountPerPlayer,
                            value + player.inPot - sidePot.amountPerPlayer + valuediff,
                            newPlayers,
                            this.sidePot);

                    }
                }
            }
            log.Debug("createSidePot() - End");
        }
示例#10
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");
        }
示例#11
0
文件: Pot.cs 项目: B3J4y/Poker
 /// <summary>
 /// a player who want to raise the pot
 /// </summary>
 /// <param name="player"></param>
 /// <param name="value"></param>
 public void raisePot(Player player,int value)
 {
     log.Debug("raisePot(Player" +player.name + ",int " + value + ") - Begin");
     if ((player.inPot + value < amountPerPlayer) || (player.isAllin) || (player.stack == value))
     {
         if (sidePot != null)
         {
             if (sidePot.amountPerPlayer > 0)
             {
                 createSidePot(player, value);
             }
             else
             {
                 addMySidePot(player, value);
             }
         }
         else
         {
             addMySidePot(player, value);
         }
     }
     else
     {
         if (this.sidePot == null)
         {
             this.value += value;
             this.potThisRound += value;
         }
         else
         {
             int valuePerRound = value + player.inPot - this.sidePot.amountPerPlayer;
             this.value += valuePerRound;
             this.potThisRound += valuePerRound;
             if ((sidePot.amountPerPlayer > 0) && player.inPot < sidePot.amountPerPlayer)
             {
                 sidePot.raisePot(player, value - valuePerRound);
             }
         }
     }
     log.Debug("raisePot() - End");
 }
示例#12
0
        // Methode um zu berechnen des raiseValue
        public void setRaiseValue(Player player, int round)
        {
            if (round == -1) {
                raiseValue = 0;
            }
            else if (player.PlayerBlindDealState == Player.BlindDealState.big && (player.Gesetzt > raiseValue))
            {
                if(round==0)
                    raiseValue = player.Gesetzt-bigBlind;
                if (round > 0)
                    raiseValue = player.Gesetzt;
            }
            else if (player.PlayerBlindDealState == Player.BlindDealState.small && (player.Gesetzt > raiseValue))
            {
                if (round == 0)
                    raiseValue = player.Gesetzt - smallBlind;
                if (round == 1)
                    raiseValue = player.Gesetzt-smallBlind;
                if (round > 1)
                    raiseValue = player.Gesetzt;

            }
            else if (player.PlayerBlindDealState == Player.BlindDealState.unknow || player.PlayerBlindDealState == Player.BlindDealState.dealer)
            {
                if (player.Gesetzt > raiseValue)
                    raiseValue = player.Gesetzt - bigBlind;
            }

            //Console.WriteLine("RaiseValue:   " + raiseValue);
        }
示例#13
0
        //Methode zum berechnen des minBetValue
        public int minBetValue(Player player, int round)
        {
            int minBet = 0;

            if (player.PlayerBlindDealState == Player.BlindDealState.small)
            {
                if (round == 1) {
                    if (raiseValue > 0)
                        minBet += raiseValue+smallBlind;
                }
                if (round == 0)
                    minBet += smallBlind;

                if (round > 1)
                    minBet += raiseValue;
            }
            else if (player.PlayerBlindDealState == Player.BlindDealState.big)
            {
                if (round > 0)
                {
                    if (raiseValue > 0)
                        minBet += raiseValue;
                }
                if (round == 0)
                    minBet += bigBlind;

            }
            else
            {
                if (round > 0)
                {
                    if (raiseValue > 0)
                        minBet += raiseValue;
                }
                else
                    minBet += bigBlind;
            }

               // Console.WriteLine("RV"+raiseValue);
               // Console.WriteLine("minbet" + minBet);

            return minBet;
        }
示例#14
0
文件: SidePot.cs 项目: B3J4y/Poker
 public SidePot(int value, Player player)
 {
     this.potValue = value;
     this.owner = player;
 }
示例#15
0
 public void action(Player player, string action, double amount)
 {
     KeyValuePair<string, LogPlayer> current = this.players.Find(x => x.Key.Equals(player.getPlayername()));
     current.Value.addAction(action, amount);
 }
        /// <summary>
        /// Initalisierung der Variablen
        /// </summary>
        public void init()
        {
            //Deck initalisieren
            deck = new Deck();

            //Die 6 möglichen Hände initalisieren
            hand1 = new Hand();
            hand2 = new Hand();
            hand3 = new Hand();
            hand4 = new Hand();
            hand5 = new Hand();
            hand6 = new Hand();

            //Spieler initalisieren
            player1 = new Player("", 10000, false, 1);
            player2 = new Player("", 10000, false, 2);
            player3 = new Player("", 10000, false, 3);
            player4 = new Player("", 10000, false, 1);
            player5 = new Player("", 10000, false, 2);
            player6 = new Player("", 10000, false, 4);

            player1.PlayerID = 0;
            player2.PlayerID = 1;
            player3.PlayerID = 2;
            player4.PlayerID = 3;
            player5.PlayerID = 4;
            player6.PlayerID = 5;

            player1.setTagID(1);
            player2.setTagID(2);
            player3.setTagID(3);

            activePlayers = new List<Player>();         //Aktive Spieler am Tisch
            activeHands = new List<Hand>();             //Händer der Aktiven Spieler am Tisch
            activeRoundPlayers = new List<Player>();    //Aktive Spieler einer Runde
            chipsOnTable = new List<Canvas>();          //Alle Chips die sich auf dem Tisch befinden

            table = new Table();                        //Tisch init
            blind = new Blind();                        //Blind init
        }
示例#17
0
文件: Winner.cs 项目: B3J4y/Poker
 public Winner(Player player)
 {
     log.Debug("Winner(Player " + player.name + ") - Begin");
     this.player = player;
     log.Debug("Winner() - End");
 }