Ejemplo n.º 1
0
        /// <summary>
        /// 处理结果,并分发赌注
        /// </summary>
        /// <param name="playerSeat">玩家座位</param>
        /// <param name="result">结果种类</param>
        public int HandleBets(PlayerSeat playerSeat, CompeteResultEnum result)
        {
            int bet = 0;

            switch (result)
            {
            case CompeteResultEnum.BankerWin:
                bet = playerSeat.Bet;
                bankerSeat.BankerReceive(playerSeat.TakeBet());
                break;

            case CompeteResultEnum.Draw:
                break;

            case CompeteResultEnum.PlayerBlackJackWin:
                bet = playerSeat.Bet * 3 / 2;
                playerSeat.ReceiveBet(bankerSeat.BankerPay(bet));
                break;

            case CompeteResultEnum.PlayerPlainWin:
                bet = playerSeat.Bet;
                playerSeat.ReceiveBet(bankerSeat.BankerPay(bet));
                break;

            default:
                break;
            }
            playerSeat.GiveBetToUser();
            return(bet);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 结算一个位置上的牌
        /// </summary>
        /// <param name="seatID">座位编号</param>
        /// <returns>计算结果</returns>
        public CompeteResultEnum Evaluate(int seatID, out int bet)
        {
            PlayerSeat playerSeat = GetSeatByID(seatID) as PlayerSeat;

            if (playerSeat.Player == null || bankerSeat.Player == null)
            {
                throw new Exception("Player or Banker is not in seat");
            }
            else
            {
                CompeteResultEnum competeResult = Compete(playerSeat, bankerSeat);
                bet = HandleBets(playerSeat, competeResult);
                return(competeResult);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 主要的比较牌型大小逻辑
        /// </summary>
        /// <param name="playerSeat">玩家座位</param>
        /// <param name="bankerSeat">庄家座位</param>
        /// <returns>比较结果</returns>
        private CompeteResultEnum Compete(PlayerSeat playerSeat, BankerSeat bankerSeat)
        {
            IList <Card> playerCards = playerSeat.Cards, bankerCards = bankerSeat.Cards;

            FlipCards(playerCards);
            FlipCards(bankerCards);
            int bet = playerSeat.Bet;

            if (IsBlackJack(playerCards) && !IsBlackJack(bankerCards))
            {
                bet = bet * 3 / 2;
                return(CompeteResultEnum.PlayerBlackJackWin);
            }
            int playerSum = BestSum(playerCards), bankerSum = BestSum(bankerCards);

            if (playerSum > 21)
            {
                return(CompeteResultEnum.BankerWin);
            }
            else if (bankerSum > 21 && playerSum <= 21)
            {
                return(CompeteResultEnum.PlayerPlainWin);
            }
            else
            {
                if (playerSum < bankerSum || (playerSum == bankerSum && bankerSum < 17))
                {
                    return(CompeteResultEnum.BankerWin);
                }
                else if (playerSum == bankerSum)
                {
                    return(CompeteResultEnum.Draw);
                }
                else
                {
                    return(CompeteResultEnum.PlayerPlainWin);
                }
            }
        }