Exemple #1
0
    //初始化当前步骤
    public void InitStep()
    {
        RoundStep step = levelData.rounds[CurrentRound].steps[CurrentStep];

        UIRoundData[2] = step.stepType;
        UIRoundData[1] = (object)RemainRound;
        MaxStep        = levelData.rounds[CurrentRound].steps.Length;
        UIGameRound roundUI = (UIGameRound)UIManager.Instance.GetPageInstatnce <UIGameRound>();

        //特殊步骤的特殊配置数据
        if (step.stepType == StepType.Think)
        {
            roundUI.SetFriend("判定你的名誉值为" + Hornor, (int)FinalNPCRate * 100);
        }
        roundUI.UpdateDataShow();
        if (step.stepType == StepType.UseCard)
        {
            NextActions = 2;
            card1       = step.CardList[0];
            card2       = step.CardList[1];
            card3       = step.CardList[2];
        }
        else
        {
            NextActions = 1;
        }
    }
Exemple #2
0
    public object Clone()
    {
        RoundStep outdata = new RoundStep
        {
            stepType = stepType,
            CardList = (int[])CardList.Clone(),
        };

        return(outdata);
    }
Exemple #3
0
        void UpdateRound()
        {
            switch (CurrentRoundStep)
            {
            case RoundStep.PowerGeneration:
                // TODO: Show animation for player ship generating power?
                if (PlayerShip != null)
                {
                    PlayerShip.GeneratePower();
                }

                foreach (var ship in NPCShips)
                {
                    ship.GeneratePower();
                }

                CurrentPhaseStep = PhaseStep.ShipMovement;
                CurrentRoundStep = RoundStep.PhaseOne;
                break;

            case RoundStep.PhaseOne:
            case RoundStep.PhaseTwo:
            case RoundStep.PhaseThree:
            case RoundStep.PhaseFour:
            case RoundStep.PhaseFive:
            case RoundStep.PhaseSix:
                UpdatePhase();
                break;

            case RoundStep.Bookkeeping:
                if (PlayerShip != null)
                {
                    PlayerShip.EndRound();
                }

                foreach (var ship in NPCShips)
                {
                    ship.EndRound();
                }

                EndMissionState ended = CheckEndOfMission();
                if (ended != EndMissionState.MissionInProgress)
                {
                    // TODO: mission is complete, so resolve mission
                    CurrentMissionState = MissionState.EndOfMission;
                }
                else
                {
                    CurrentRound++;
                    CurrentRoundStep = RoundStep.PowerGeneration;
                }

                break;
            }
        }
Exemple #4
0
 /// <summary>
 /// Create an instance of the TableState
 /// </summary>
 /// <param name="roundStep">The current step the table is on</param>
 /// <param name="actingPlayer">Index of the current acting player</param>
 /// <param name="players">List of the players</param>
 /// <param name="communityCards">The community cards on the table</param>
 /// <param name="roundHistory">The list of previous rounds</param>
 /// <param name="curBet">The current bet</param>
 /// <param name="minBet">The minimum bet</param>
 /// <param name="pot">The current pot</param>
 internal TableState(RoundStep roundStep, int actingPlayer, List <PlayerState> players, List <Card> communityCards, List <RoundState> roundHistory, int curBet, int minBet, int pot)
 {
     this.Step           = roundStep;
     this.PlayerCount    = players.Count;
     this.Players        = new TableStatePlayers(actingPlayer, players);
     this.CommunityCards = communityCards;
     this.RoundHistory   = roundHistory;
     this.CurrentBet     = curBet;
     this.MinimumBet     = minBet;
     this.Pot            = pot;
 }
Exemple #5
0
        /// <summary>
        /// Run a round of poker
        /// </summary>
        /// <param name="dealerIndex">The index of the dealer</param>
        /// <param name="bigBlind">The big blind for this round</param>
        /// <param name="output">StreamWriter to write the summary output</param>
        /// <returns>A round state object summary of the round.</returns>
        internal RoundState RunRound(int dealerIndex, int bigBlind)
        {
            // Shuffle the deck first thing
            // Don't forget to do this!
            this.deck.Shuffle();

            // The total amount in the pot
            int pot = 0;

            // Current bet
            int bet = bigBlind;

            // Index of the person with the current bet
            int betIndex;

            // Number of players who have called current bet
            int called = 1;

            // Number of players who have folded
            int folded = 0;

            // The step of the round
            RoundStep step = RoundStep.PreFlop;

            // Cards on the table
            List <Card> communityCards = new List <Card>();

            // Values to report back to the RoundState
            // Will be populated as the game goes forward
            string[] winners = null;
            Dictionary <string, Card[]> revealedCards = new Dictionary <string, Card[]>();
            List <RoundAction>          actions       = new List <RoundAction>();

            // See which players are still in, and drop those with less money than the big blind
            // Deal cards out to the players who are still in
            int playersIn = 0;

            foreach (var player in this.players)
            {
                if (!player.Dropped)
                {
                    ++playersIn;
                    // The cards are draw terribly out of order. I would be dead in the Wild West.
                    player.StartRound(new[] { this.deck.Draw(), this.deck.Draw() });
                }
            }

            // When the game is over, return null
            if (playersIn == 1)
            {
                return(null);
            }

            // Select little blind
            int littleBlind = bigBlind / 2; // I round down because I am a lazy programmer
            int littleBlindIndex;

            if (playersIn == 2)
            {
                // In head-to-head, the dealer is little blind
                littleBlindIndex = dealerIndex;
            }
            else
            {
                littleBlindIndex = this.NextPlayer(dealerIndex);
            }

            // Select big blind
            int bigBlindIndex = betIndex = this.NextPlayer(littleBlindIndex);

            // Initial bids
            this.players[littleBlindIndex].PostBlind(littleBlind);
            Logger.Log(LogLevel.Info, "Little Blind {0} puts in ${1}", this.players[littleBlindIndex].Name, littleBlind);

            this.players[bigBlindIndex].PostBlind(bigBlind);
            Logger.Log(LogLevel.Info, "Big Blind {0} puts in ${1}", this.players[bigBlindIndex].Name, bigBlind);

            // Take turns until betting is complete
            int actionIndex;

            actionIndex = this.NextPlayer(bigBlindIndex);

            while (step != RoundStep.Complete && playersIn - folded > 1)
            {
                Logger.Log(LogLevel.Info, string.Empty);
                Logger.Log(LogLevel.Info, "At {0} step", step.ToString());

                switch (step)
                {
                case RoundStep.Flop:
                    this.deck.Draw();     // Why do I burn a card? Because tradition.
                    communityCards.Add(this.deck.Draw());
                    communityCards.Add(this.deck.Draw());
                    communityCards.Add(this.deck.Draw());
                    Logger.Log(LogLevel.Info, "Flop: {0} / {1} / {2}", PokerUtils.PrintCard(communityCards[0]), PokerUtils.PrintCard(communityCards[1]), PokerUtils.PrintCard(communityCards[2]));
                    break;

                case RoundStep.Turn:
                case RoundStep.River:
                    this.deck.Draw();
                    communityCards.Add(this.deck.Draw());
                    Logger.Log(LogLevel.Info, "{0}: {1}", step.ToString(), PokerUtils.PrintCard(communityCards[communityCards.Count - 1]));
                    break;
                }

                // In head-to-head the dealer goes first only in pre-flop, and goes last in all other rounds
                if (playersIn == 2)
                {
                    if (step == RoundStep.PreFlop)
                    {
                        actionIndex = dealerIndex;
                    }
                    else
                    {
                        actionIndex = this.NextPlayer(bigBlindIndex);
                    }
                }

                called = 0;
                while (called < playersIn - folded)
                {
                    // Create the Table State for this player's action
                    var playerState = new List <PlayerState>();
                    foreach (var p in this.players)
                    {
                        playerState.Add(p.State);
                    }
                    var tableState = new TableState(step, actionIndex, playerState, communityCards, rounds, bet, bigBlind, pot);

                    var        player = this.players[actionIndex];
                    TurnAction action;
                    try
                    {
                        // Player takes their action
                        action = player.Implementation.DoAction(player.Cards, tableState);
                    }
                    catch (Exception e)
                    {
                        Logger.Log(LogLevel.Error, "Exception during {0}'s turn. Exception: {1}", player.Name, e);
                        action = TurnAction.Fold;
                    }

                    player.ResolveAction(action, ref called, ref folded, ref bet, ref pot);

                    actions.Add(new RoundAction(player.Name, action));
                    actionIndex = this.NextPlayer(actionIndex);
                }

                step++;
            }

            // Check out the result

            return(new RoundState(pot, winners, revealedCards, actions));
        }