예제 #1
0
 public void dealStateEnded(DealState state)
 {
     foreach (IGameObserver go in this.observers)
     {
         go.dealStateEnded(state);
     }
 }
예제 #2
0
        public void playGame()
        {
            //main game loop
            while (true)
            {
                this.currentDealState.dealCards();
                this.currentDealState.handleBettingSession();
                bool gameDone = this.currentDealState.gameIsDone();
                if (gameDone)
                {
                    break;
                }
                else
                {
                    this.currentDealState = this.currentDealState.getNextState();
                }
            }
            this.currentDealState.game.gameEnded();

            //Decide who won
            List <Player> winnerList = determineWinnerList();

            if (winnerList.Count == 1)                      //don't determine winner if the game ends in a fold
            {
                distributePot(winnerList[0], winnerList);   //in the event of a fold, distribute all money to the remaining player
            }
            else
            {
                chooseWinner(winnerList);             //determine who wins overall out of the list of potential winners
            }
        }
 public void dealStateEnded(DealState state)
 {
     MainGrid.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
     {
         if (state is PreFlopState)
         {
             addToTextDisplay("Preflop has ended.\n");
         }
         else if (state is FlopState)
         {
             addToTextDisplay("Flop has ended.\n");
         }
         else if (state is TurnState)
         {
             addToTextDisplay("Turn has ended.\n");
         }
         else if (state is RiverState)
         {
             addToTextDisplay("River has ended.\n");
         }
         else
         {
             addToTextDisplay("Showdown has ended.\n");
             startButton.Visibility = System.Windows.Visibility.Hidden;
         }
     }));
 }
예제 #4
0
        public void playGame()
        {
            //main game loop
            while (true)
            {
                this.currentDealState.dealCards();
                this.currentDealState.handleBettingSession();
                bool gameDone = this.currentDealState.gameIsDone();
                if (gameDone)
                {
                    break;
                }
                else
                {
                    this.currentDealState = this.currentDealState.getNextState();
                }
            }
            this.currentDealState.game.gameEnded();

            //Decide who won
            List<Player> winnerList = determineWinnerList();
            if (winnerList.Count == 1)                      //don't determine winner if the game ends in a fold
                distributePot(winnerList[0], winnerList);   //in the event of a fold, distribute all money to the remaining player
            else
            {
                chooseWinner(winnerList);             //determine who wins overall out of the list of potential winners
            }
        }
예제 #5
0
        public Move makeMove(DealState currentDealState)         //this method needs to be abstract, but is temporarily working for all players
        {
            Move myMove = this.moveChooser.getMove(currentDealState, currentDealState.game.legalMoveGenerator.generateLegalMoves(currentDealState, this), this.cards);

            this.currentStack = this.currentStack - myMove.amountPotRaised;
            this.betInRound   = this.betInRound + myMove.currentBetRaised;
            return(myMove);
        }
예제 #6
0
        public DealState currentDealState; //preflop (0 cards), flop (3 cards), turn (4 cards), river (5 cards), showdown (showing cards)

        #endregion Fields

        #region Constructors

        public GameState(Player[] players, GameController game)
        {
            List<Player> activePlayers = new List<Player>();
            foreach (Player p in players)
            {
                activePlayers.Add(p);
            }
            this.currentDealState = new PreFlopState(activePlayers, game);
        }
예제 #7
0
        public DealState currentDealState;                  //preflop (0 cards), flop (3 cards), turn (4 cards), river (5 cards), showdown (showing cards)

        public GameState(Player[] players, GameController game)
        {
            List <Player> activePlayers = new List <Player>();

            foreach (Player p in players)
            {
                activePlayers.Add(p);
            }
            this.currentDealState = new PreFlopState(activePlayers, game);
        }
예제 #8
0
        public Move getMove(DealState currentDealState, List <Move> legalMoves, Card[] cards)
        {
            Playout p     = new Playout();
            int     score = 0;

            if (currentDealState.dealersHand == null)
            {
                score = p.playout(cards[0].getRawData(), cards[1].getRawData());
            }
            else if (currentDealState.dealersHand.Count == 3)
            {
                score = p.playout(cards[0].getRawData(), cards[1].getRawData(),
                                  currentDealState.dealersHand[0].getRawData(),
                                  currentDealState.dealersHand[1].getRawData(),
                                  currentDealState.dealersHand[2].getRawData());
            }
            else if (currentDealState.dealersHand.Count == 4)
            {
                score = p.playout(cards[0].getRawData(), cards[1].getRawData(),
                                  currentDealState.dealersHand[0].getRawData(),
                                  currentDealState.dealersHand[1].getRawData(),
                                  currentDealState.dealersHand[2].getRawData(),
                                  currentDealState.dealersHand[3].getRawData());
            }
            else
            {
                score = p.score(cards[0].getRawData(), cards[1].getRawData(),
                                currentDealState.dealersHand[0].getRawData(),
                                currentDealState.dealersHand[1].getRawData(),
                                currentDealState.dealersHand[2].getRawData(),
                                currentDealState.dealersHand[3].getRawData(),
                                currentDealState.dealersHand[4].getRawData()
                                );
            }

            // int division_size = (1169 - 500) / legalMoves.Count;
            int    count         = 0;
            double x             = (Math.Log(score, legalMoves.Count));
            double max           = (Math.Log(1169, legalMoves.Count));
            double min           = (Math.Log(370, legalMoves.Count));
            double division_size = (max - min) / legalMoves.Count;

            for (double base_pos = min; base_pos <= max; base_pos += division_size)
            {
                if (x <= base_pos)
                {
                    return(legalMoves[count - 1]);
                }
                count++;
            }
            return(legalMoves[0]);
        }
        public Move getMove(DealState currentDealState, List<Move> legalMoves, Card[] cards)
        {
            Playout p = new Playout();
            int score = 0;

            if (currentDealState.dealersHand == null)
            {
                score = p.playout(cards[0].getRawData(), cards[1].getRawData());
            }
            else if (currentDealState.dealersHand.Count == 3)
            {
                score = p.playout(cards[0].getRawData(), cards[1].getRawData(),
                    currentDealState.dealersHand[0].getRawData(),
                    currentDealState.dealersHand[1].getRawData(),
                    currentDealState.dealersHand[2].getRawData());
            }
            else if (currentDealState.dealersHand.Count == 4)
            {
                score = p.playout(cards[0].getRawData(), cards[1].getRawData(),
                    currentDealState.dealersHand[0].getRawData(),
                    currentDealState.dealersHand[1].getRawData(),
                    currentDealState.dealersHand[2].getRawData(),
                    currentDealState.dealersHand[3].getRawData());
            }
            else
            {
                score = p.score(cards[0].getRawData(), cards[1].getRawData(),
                    currentDealState.dealersHand[0].getRawData(),
                    currentDealState.dealersHand[1].getRawData(),
                    currentDealState.dealersHand[2].getRawData(),
                    currentDealState.dealersHand[3].getRawData(),
                    currentDealState.dealersHand[4].getRawData()
                    );
            }

               // int division_size = (1169 - 500) / legalMoves.Count;
            int count = 0;
            double x = (Math.Log(score, legalMoves.Count));
            double max = (Math.Log(1169, legalMoves.Count));
            double min = (Math.Log(370, legalMoves.Count));
            double division_size = (max-min) / legalMoves.Count;
            for (double base_pos = min; base_pos <= max; base_pos += division_size)
            {
                if (x <= base_pos)
                {
                    return legalMoves[count-1];
                }
                count++;
            }
            return legalMoves[0];
        }
예제 #10
0
 /*
  * IMoveChooser Methods
  */
 public Move getMove(DealState currentDealState, List <Move> legalMoves, Card[] cards)
 {
     return((Move)MainGrid.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new ReturnDelegate(delegate(List <Move> movesOptions)
     {
         Move myMove = null;
         MoveDialogBox moveChoiceBox = new MoveDialogBox(legalMoves);
         moveChoiceBox.Owner = this;
         moveChoiceBox.ShowDialog();
         if (moveChoiceBox.DialogResult == true)
         {
             myMove = moveChoiceBox.moveChoice;
         }
         else
         {
             new Exception("User did not select move.");
         }
         return myMove;
     }), legalMoves));
 }
예제 #11
0
        public List <Move> generateLegalMoves(DealState currentDealState, Player player)
        {
            List <Move> legalMoves = new List <Move>();

            bool canRaise = (player.currentStack >= (currentDealState.currentBet - player.betInRound + currentDealState.game.setRaiseAmount));
            bool canCheck = (player.betInRound == currentDealState.currentBet);

            legalMoves.Add(new Fold());
            if (canCheck)
            {
                legalMoves.Add(new Check());
            }
            else
            {
                int callAmount = currentDealState.currentBet - player.betInRound;
                if (callAmount > player.currentStack)
                {
                    callAmount = player.currentStack;
                }
                legalMoves.Add(new Call(callAmount));
            }

            if (canRaise)
            {
                int increments          = (player.currentStack - (currentDealState.currentBet - player.betInRound)) / currentDealState.game.setRaiseAmount;
                int raiseAmount         = 0;
                int amountStackDeducted = 0;
                for (int i = 1; i < increments + 1; i++)
                {
                    raiseAmount         = i * currentDealState.game.setRaiseAmount;
                    amountStackDeducted = currentDealState.currentBet - player.betInRound + raiseAmount;
                    legalMoves.Add(new Raise(amountStackDeducted, raiseAmount));
                }
            }



            return(legalMoves);
        }
예제 #12
0
        public List<Move> generateLegalMoves(DealState currentDealState, Player player)
        {
            List<Move> legalMoves = new List<Move>();

            bool canRaise = (player.currentStack >= (currentDealState.currentBet - player.betInRound + currentDealState.game.setRaiseAmount));
            bool canCheck = (player.betInRound == currentDealState.currentBet);

            legalMoves.Add(new Fold());
            if (canCheck)
            {
                legalMoves.Add(new Check());
            }
            else
            {
                int callAmount = currentDealState.currentBet - player.betInRound;
                if (callAmount > player.currentStack)
                {
                    callAmount = player.currentStack;
                }
                legalMoves.Add(new Call(callAmount));
            }

            if (canRaise)
            {
                int increments = (player.currentStack - (currentDealState.currentBet - player.betInRound)) / currentDealState.game.setRaiseAmount;
                int raiseAmount = 0;
                int amountStackDeducted = 0;
                for (int i = 1; i < increments + 1; i++)
                {
                    raiseAmount = i * currentDealState.game.setRaiseAmount;
                    amountStackDeducted = currentDealState.currentBet - player.betInRound + raiseAmount;
                    legalMoves.Add(new Raise(amountStackDeducted, raiseAmount));
                }
            }

            return legalMoves;
        }
예제 #13
0
 /*
  * IMoveChooser Methods
  */
 public Move getMove(DealState currentDealState, List<Move> legalMoves, Card[] cards)
 {
     return (Move)MainGrid.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new ReturnDelegate(delegate(List<Move> movesOptions)
     {
         Move myMove = null;
         MoveDialogBox moveChoiceBox = new MoveDialogBox(legalMoves);
         moveChoiceBox.Owner = this;
         moveChoiceBox.ShowDialog();
         if (moveChoiceBox.DialogResult == true)
         {
             myMove = moveChoiceBox.moveChoice;
         }
         else
         {
             new Exception("User did not select move.");
         }
         return myMove;
     }), legalMoves);
 }
예제 #14
0
 public void dealStateEnded(DealState state)
 {
     MainGrid.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
     {
         if (state is PreFlopState)
         {
             addToTextDisplay("Preflop has ended.\n");
         }
         else if (state is FlopState)
         {
             addToTextDisplay("Flop has ended.\n");
         }
         else if (state is TurnState)
         {
             addToTextDisplay("Turn has ended.\n");
         }
         else if (state is RiverState)
         {
             addToTextDisplay("River has ended.\n");
         }
         else
         {
             addToTextDisplay("Showdown has ended.\n");
             startButton.Visibility = System.Windows.Visibility.Hidden;
         }
     }));
 }