Ejemplo n.º 1
0
        public override void play(GameState state)
        {
            bool canCheck = this.canCheck(state);
             Random random = new Random();
            int choice;
            if (canCheck)
                choice = random.Next(1, 3);
            else
                choice = random.Next(0, 3);

            if (canCheck)
            {
                if (choice == 1)
                    check();
                else if (choice == 2)
                    bet(state.bb * 2, state);
            }
            else
            {
                if (choice == 0)
                    fold();
                else if (choice == 1)
                    call(state);
                else if (choice == 2)
                    raise(state.bb * 2, state);
            }
        }
Ejemplo n.º 2
0
        public override void play(GameState state)
        {
            bool canCheck = this.canCheck(state);

            int amount = 0;
            Random random = new Random();
             int choice = random.Next(0, 2); //  decision(fold==0, check/call==1/2, bet/raise==3/4)

            if(choice == 3 || choice == 4)
                amount = random.Next(1, chipCount); // ammount to bet or raise (on top of amount to call) for bet/raise option

            if (choice == 0) // if fold
                fold();
            else  if (canCheck)
            {
                if (choice == 1 || choice == 2) // check/call
                    check();
                else //bet/raise
                    bet(amount, state);
            }
            else
            {
                if (choice == 1 || choice == 2) //check/call
                    call(state.maxCommitted - chipsCommitted); // calls amount listed or all chips (goes all in)
                else //bet/raise
                    raise(amount, state.maxCommitted - chipsCommitted, state); // raise amount on top + the amount to call(amount) + amount to call (seperated to check if is able to raise)

            }
        }
Ejemplo n.º 3
0
        public void update(GameForm gameForm, GameState state)
        {
            // list GameState info
            playersInfo = new List<Label>();
            foreach (Player player in state.players)
               playersInfo.Add( displayPlayerInfo(player, false));

            //show options
        }
Ejemplo n.º 4
0
        public void endHand(GameState state)
        {
            MessageBox.Show("Hand over.");

            List<Player> playersLeftInGame = new List<Player>();
             List<Player> playersLeftInHand = new List<Player>();
             foreach (Player player in state.players)
                if (player.inHand && player.chipsCommitted > 0 )  // player.chipsCommitted to exclude people who went allin earlier
                    playersLeftInHand.Add(player);

             state.endTurn();
             decideWinnersAndPayChips(new Tuple<int, List<Player>>(state.potCount, playersLeftInHand));

             foreach (Tuple<int, List<Player>> sidePot in state.sidePots)
                 decideWinnersAndPayChips(sidePot);

            foreach (Player player in state.players)
            if (player.chipCount != 0)
                playersLeftInGame.Add(player);
            else
            {
                RulesAndMethods.AddToLog("Player " + player.name + " was eliminated.");
                player.inHand = false;
                player.clearCards(); // gets rid of cards for people who are eliminated
            }
            state.players = playersLeftInGame;

            foreach (Player player in state.players)
                player.clearCards(); // gets rid of cards of players still alive

            if (state.players.Count > 1 && state.humanIsAlive())
            {
                // sets next buttonPos

                state.buttonPos++;
                state.buttonPos = state.buttonPos % state.players.Count;

                state.clearPublicCards();
                newHand(state);
            }
            else
            {
                state.gameOver = true;
                if(!currentHumanPlayer.outOfMoney())
                state.players[0].inHand = false; // so if human wins doesn't try to display cards
                MessageBox.Show("GAME OVER.");
            }
        }
Ejemplo n.º 5
0
        public GameForm(int numPlayers, int numChips)
        {
            InitializeComponent();

            // gives labels to the seats, groups list of seats into a table
            table = new List<Seat>()
            {
                new Seat(playerOneName, playerOneChipCount, playerOneChipsCommitted, playerOneLastAction, playerOneCards, playerOneButton, playerOneAction),
                new Seat(playerTwoName, playerTwoChipCount, playerTwoChipsCommitted, playerTwoLastAction, playerTwoCards, playerTwoButton, playerTwoAction),
                new Seat(playerThreeName, playerThreeChipCount, playerThreeChipsCommitted, playerThreeLastAction, playerThreeCards, playerThreeButton, playerThreeAction),
                new Seat(playerFourName, playerFourChipCount, playerFourChipsCommitted, playerFourLastAction, playerFourCards, playerFourButton, playerFourAction),
                new Seat(playerFiveName, playerFiveChipCount, playerFiveChipsCommitted, playerFiveLastAction, playerFiveCards, playerFiveButton, playerFiveAction),
                new Seat(playerSixName, playerSixChipCount, playerSixChipsCommitted, playerSixLastAction, playerSixCards, playerSixButton, playerSixAction),
                new Seat(playerSevenName, playerSevenChipCount, playerSevenChipsCommitted, playerSevenLastAction, playerSevenCards, playerSevenButton, playerSevenAction),
                new Seat(playerEightName, playerEightChipCount, playerEightChipsCommitted, playerEightLastAction, playerEightCards, playerEightButton, playerEightAction),
                new Seat(playerNineName, playerNineChipCount, playerNineChipsCommitted, playerNineLastAction, playerNineCards, playerNineButton, playerNineAction)

            };
            game = new Game(numPlayers, numChips);
            state = game.state;

            // moves just created players into the seats
            int seatNumber;
            int lastSeatFilled = 0;
            for (int i = 0; i < state.players.Count; i++)
            {
                if (state.players[i].human)
                { // there should only be one human player
                    table[0].refreshPlayer(state.players[i], state); // used to update info or seat the player the first time
                    lastSeatFilled = 0;
                }
                else
                {
                    Random random = new Random();
                    seatNumber = random.Next(lastSeatFilled + 1, 9 - (state.players.Count - (i+1))); // this fills in order, semirandomly
                    lastSeatFilled = seatNumber;
                    if (table[seatNumber].player == null)
                        table[seatNumber].refreshPlayer(state.players[i], state);

                }

            }
            var timer = new Timer();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 250;
            timer.Start();
        }
Ejemplo n.º 6
0
        public Game(int numPlayers, int startingChips)
        {
            RulesAndMethods.ResetLog();
            int bb = startingChips / 100;
               players  = new List<Player>(numPlayers);

            //all but one are computer players
            for (int i = 0; i < numPlayers-1; i++)
                players.Add( new SimpleComputerPlayer("Computer Player " + (i+1), startingChips, i));
            players.Add(new HumanPlayer("Human", startingChips, numPlayers-1));

            Random random = new Random();
            int buttonPos = random.Next(1, players.Count);

            state = new GameState(players, buttonPos);
            state.bb = bb;

                handsOfPoker = new HandOfPoker(state);
               if (players.Count == 1)
                   gameEnds();
        }
Ejemplo n.º 7
0
        public void refreshPlayer(Player player, GameState state)
        {
            if (player != null && !(player.outOfMoney() && !player.inHand))
            {
                this.player = player;
                playerName.Text = player.name;
                this.chipCount.Text = player.chipCount.ToString();
                this.chipsCommitted.Text = player.chipsCommitted.ToString();
                this.lastAction.Text = player.lastAction;
                if (player.human)
                    revealCards();
                else if (player.inHand)
                    this.playerCards.Text = "HAS CARDS.";
                else
                    this.playerCards.Text = "NO CARDS.";

                if (state.players[state.buttonPos] == player)
                {
                    playerButton.Image = button;
                    playerButton.Show();
                }
                else
                    playerButton.Hide();

                if (state.nextToPlay() == player)
                {
                    playerAction.Image = action;
                    playerAction.Show();
                }
                else
                    playerAction.Hide();
            }
            else
                makeEverythingEmpty();
        }
Ejemplo n.º 8
0
 public void startGame(GameState state)
 {
     GameForm gameForm = new GameForm();
     update(gameForm, state);
 }
Ejemplo n.º 9
0
 public override void play(GameState state)
 {
     Console.WriteLine("Something went wrong, human players play through the interface.");
 }
Ejemplo n.º 10
0
 public HandOfPoker(GameState state)
 {
     //            newHand(state);
 }
Ejemplo n.º 11
0
        public bool progressHand(GameState.HandStep previousStep)
        {
            List<Player> playersWhoWentAllIn = new List<Player>();
            foreach (Player player in state.players)
                if (player.isAllIn() && player.chipsCommitted > 0)
                    playersWhoWentAllIn.Add(player);

            while (playersWhoWentAllIn.Count > 0)
            {
                int minAllIn = 10000000;
                Player minAllInPlayer = playersWhoWentAllIn[0];

                foreach (Player player in playersWhoWentAllIn) // find player who has the smallest all in
                {
                    if (player.chipsCommitted < minAllIn)
                    {
                        minAllInPlayer = player;
                        minAllIn = player.chipsCommitted;
                    }
                }
                if (minAllInPlayer != null)
                {
                    state.newSplitPot(minAllInPlayer);
                    playersWhoWentAllIn.Remove(minAllInPlayer);
                }

            }
            // moves chips to center, rests actionPos, maxCommitted = 0, resets last actions, resets last raise

            if (state.playersInHand() < 2)
                return true;

            switch (previousStep)
            {
                case GameState.HandStep.PreFlop:
                    for (int i = 0; i <= 2; i++)
                        state.addNewPublicCard();
                    break;
                case GameState.HandStep.Flop:
                    state.addNewPublicCard();
                    break;
                case GameState.HandStep.Turn:
                    state.addNewPublicCard();
                    break;
                case GameState.HandStep.River:
                    return true;

                default:
                    break;
            }

            int numNextStep = (int)previousStep + 1;
            state.handStep = (GameState.HandStep)numNextStep;

            if (state.playersInHand() - state.playersAllIn() < 2)
            {
                progressHand(state.handStep); // recursive, runs until you hit the river, which will immediately return true
                    return true;
            }
            else
                state.endTurn(); // need to be able to tell who went all in during a particular phase, so do this later in this case

            return false;
        }
Ejemplo n.º 12
0
        public void play(GameState state)
        {
            while (!state.nextToPlay().human && !state.allDoneWithTurn())
            {
                state.nextToPlay().play(state);

                state.updateGameState();
            }

            if (state.allDoneWithTurn() || state.playersInHand() < 2)
                if (progressHand(state.handStep))
                { // progresses hand and returns whether hand is over (the last handStep was river)
                    endHand(state);
                    return;
                }
                else
                    play(state);
            if(!state.gameOver)
            if(state.nextToPlay().human)
                currentHumanPlayer = (HumanPlayer)state.nextToPlay();
        }
Ejemplo n.º 13
0
        public void newHand(GameState state)
        {
            this.state = state;
            state.handStep = GameState.HandStep.PreFlop;
            Deck deck = new Deck();
            state.deck = deck;
            state.players = state.players;
            this.buttonPos = state.buttonPos;

            if (state.players.Count > 2)
            {
                state.actionPos = (state.buttonPos + 3) % state.players.Count;
                // small blind
                state.players[(buttonPos + 1) % state.players.Count].commitChips(state.bb / 2);
                // big blind
                state.players[(buttonPos + 2) % state.players.Count].commitChips(state.bb);
            }
            else
            {
                state.actionPos = (state.buttonPos) % state.players.Count;
                // small blind
                state.players[(state.buttonPos) % state.players.Count].commitChips(state.bb / 2);
                // big blind
                state.players[(state.buttonPos + 1) % state.players.Count].commitChips(state.bb);
            }

            foreach (Player player in state.players)
            {
                player.inHand = true;
                player.addHoleCards(deck.giveCard(), deck.giveCard());
            }
            state.updateMaxCommitted();

            play(state);
        }