Пример #1
0
        protected virtual void HandleChannelMessage(object sender, IChannelMessageEventArgs args, MessageFlags flags)
        {
            if (flags.HasFlag(MessageFlags.UserBanned))
            {
                return;
            }

            if (args.Channel != Config.CasinoChannel)
            {
                return;
            }

            bool botJoin = false;

            if (args.Message.Trim() == "?join")
            {
                // "?join"
                botJoin = true;
            }
            else
            {
                string[] bits = args.Message.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (
                    bits.Length >= 2 &&
                    bits[0] == "?join" &&
                    bits.Skip(1).Any(b => b.Equals(ConnectionManager.MyNickname, StringComparison.OrdinalIgnoreCase))
                    )
                {
                    // "?join MyBot" or "?join ThisBot ThatBot MyBot"
                    botJoin = true;
                }
            }

            if (botJoin)
            {
                ConnectionManager.SendChannelMessage(args.Channel, ".botjoin");
                ConnectionManager.SendChannelMessage(args.Channel, ".grules");
            }

            // FIXME: these should be JSON events
            if (string.Equals(args.SenderNickname, Config.GameMasterNickname, StringComparison.OrdinalIgnoreCase))
            {
                if (
                    args.Message == "Merging the discards back into the shoe and shuffling..." ||
                    args.Message == "The dealer's shoe has been shuffled."
                    )
                {
                    CardCounter.ShoeShuffled();
                    DispatchStratDebugMessage($"shoe shuffled -> {CardCounter}");
                }
            }
        }
Пример #2
0
        private bool ParseStandardCommand(Desk desk, Player player, string command)
        {
            switch (command)
            {
            case "结束游戏":
                desk.AddMessage("请寻找管理员结束.");
                return(true);

            case "记牌器":
                desk.AddMessage(CardCounter.GenerateCardString(desk));
                return(true);

            case "全场牌数":
                desk.AddMessage(string.Join(Environment.NewLine,
                                            desk.PlayerList.Select(p => $"{p.ToAtCodeWithRole()}: {p.Cards.Count}")));
                return(true);

            //case "弃牌":
            //player.GiveUp = true;
            //desk.AddMessage("弃牌成功");
            //return true;

            case "托管":
                if (desk.Players.Count(p => p is FakePlayer) == 2)
                {
                    desk.AddMessage("你觉得这样好玩么?");
                    return(true);
                }
                player.HostedEnabled = true;
                desk.AddMessage("托管成功");
                RunHostedCheck(desk);
                return(true);

            case "结束托管":
                player.HostedEnabled = false;
                desk.AddMessage("结束成功");
                return(true);
            }

            return(false);
        }
Пример #3
0
        private Game()
        {
            phase         = GamePhase.WaitingForPlayers;
            flowClockWise = true;

            discardPile = new Deck();
            drawPile    = new Deck();

            players    = new Player[10];
            numPlayers = 0;

            gameWatcher = new GameWatcher();

            perfectDeck = new DeckBuilderFacade()
                          .number
                          .SetAllNumberCards(2)
                          .SetIndividualNumberCards(0, 1)
                          .action
                          .SetActionCards(2)
                          .wild
                          .SetBlackCards(4)
                          .Build();

            semiPerfectDeck = new DeckBuilderFacade()
                              .number
                              .SetAllNumberCards(2)
                              .SetIndividualNumberCards(0, 1)
                              .Build();

            cardCount = 0;
            moveCount = 0;
            skipCount = 0;
            CardCounter cardCounter = new CardCounter();
            SkipCounter skipCounter = new SkipCounter();
            MoveCounter moveCounter = new MoveCounter();

            mediator = new ConcreteMediator(this, cardCounter, moveCounter, skipCounter);
        }
Пример #4
0
 public Player()
 {
     Counter = new CardCounter();
 }
Пример #5
0
        public virtual void HandleEventHandInfo([EventValue("player")] string player,
                                                [EventValue("hand")] List <Card> hand, [EventValue("split_round")] int?splitRound = null,
                                                [EventValue("sum")] int?sum = null)
        {
            DistributeHandAssistance(player, hand, splitRound);

            // player's name is "Dealer", player has one card and there is no sum => we're being told the dealer's upcard
            if (hand.Count == 1 && player == "Dealer" && !sum.HasValue)
            {
                State.DealersUpcard = hand.First();
            }

            // irrespective of whose hand (mine, the dealer's or another player's); feed the info to the card counter
            if (State.Stage == BlackjackStage.MyBetting || State.Stage == BlackjackStage.OthersBetting)
            {
                // fresh hands => forward the whole hand
                foreach (Card c in hand)
                {
                    CardCounter.CardDealt(c);
                }
                DispatchStratDebugMessage($"seen hand {hand.Select(c => c.ToUnicodeString()).StringJoin(" ")} -> {CardCounter}");
            }
            else if (hand.Count == 2 && player == "Dealer")
            {
                // for no good reason, the (initially hidden) hole card is the dealer's first card, not their second
                Card holeCard = hand.First();
                CardCounter.CardDealt(holeCard);
                DispatchStratDebugMessage($"seen hole card {holeCard.ToUnicodeString()} -> {CardCounter}");
            }
            else
            {
                // only forward the new (last) card
                // this also works for splits, since the first card was dealt previously and the second is new
                if (hand.Count > 0)
                {
                    Card lastCard = hand.Last();
                    CardCounter.CardDealt(lastCard);
                    DispatchStratDebugMessage($"seen card {lastCard.ToUnicodeString()} -> {CardCounter}");
                }
            }

            // now then, on to my turn
            if (player != ConnectionManager.MyNickname)
            {
                return;
            }

            int handIndex = splitRound.HasValue
                ? (splitRound.Value - 1)
                : 0;

            // grow additional hands
            while (handIndex >= State.MyHands.Count)
            {
                State.MyHands.Add(null);
            }

            if (State.MyHands[handIndex] == null)
            {
                State.MyHands[handIndex] = new Hand
                {
                    Cards = new SortedMultiset <Card>(hand),
                    Round = 0
                };
            }
            else
            {
                State.MyHands[handIndex].Cards = new SortedMultiset <Card>(hand);
                ++State.MyHands[handIndex].Round;
            }

            GloatOrCurse(handIndex);

            // warning: assumes order: hand_info[0] -> turn_info -> hand_info[1] -> hand_info[2] -> hand_info[3] ...

            if (State.Stage == BlackjackStage.MyTurn)
            {
                MakeBlackjackMove(handIndex);
            }
        }
Пример #6
0
 /// <summary>
 /// Using a Cardcounter to find the longest straight.
 /// Both the longest straight and straight starting point will be returned in form of out variabels. 
 /// </summary>
 private static void GetLongestStraight(CardCounter valueCounter, out int straightLenght, out int straightStartsAt)
 {
     int longestStraight = 0;
     int longestStraightStartsAt = 0;
     int currentStraigt = 0;
     int index = 0;
     foreach (Cards cards in valueCounter)
     {
         if (cards.Any())
         {
             currentStraigt++;
             if (currentStraigt > longestStraight)
             {
                 longestStraight = currentStraigt;
                 longestStraightStartsAt = index - currentStraigt + 1;
             }
         }
         else currentStraigt = 0;
         index++;
     }
     straightLenght = longestStraight;
     straightStartsAt = longestStraightStartsAt;
 }
Пример #7
0
 public NormalAI(ComputerPlayer ourPlayer) : base(ourPlayer)
 {
     counter = new CardCounter(ourPlayer);
 }
Пример #8
0
 private void Awake()
 {
     network   = brain.GetNetwork();
     cardCount = new CardCounter();
 }