Beispiel #1
0
        /// <param name="printLogs">Делегат вывода данных в окно логов</param>
        /// <param name="printCardsInTextBox">Делегат вывода в указанный RichTextBox список карт</param>
        /// <param name="obj">Доступные RichTextBox окна</param>
        public Sever(
            Action <string> printLogs,
            Action <RichTextBox, List <PlayingCard> > printCardsInTextBox,
            List <RichTextBox> obj
            )
        {
            // методы взаимодействия с формой
            PrintLogs           = printLogs;
            PrintCardsInTextBox = printCardsInTextBox;
            AllBoxes            = obj;
            PrintLogs("Сервер инициализирован");

            Mode = GameMode.AiVsAi;
            PrintLogs($"Текущий режим: {Mode}");

            // работа с колодой
            DeckBox = new DeckCards(); // сама колода
            PrintCardsInTextBox(AllBoxes[0], new List <PlayingCard> {
                DeckBox.ViewTrump()
            });                                                                                // показать козырь

            // выдача карт на руки
            for (var i = 0; i < 6; i++)
            {
                HandPlayer1Box.Add(DeckBox.TakeCard());
                HandPlayer2Box.Add(DeckBox.TakeCard());
            }
            ViewState();
            PrintLogs("Карты розданы");

            // определение активного игрока
            InitActivePlayer();
            PrintLogs("Сейчас ходит игрок " + ActivePlayer);

            // создание сервера
            Player1 = new Lori(DeckBox.ViewTrump(), "Lori One");
            Player2 = new Lori(DeckBox.ViewTrump(), "Lori Two");
        }
Beispiel #2
0
        /// <summary>
        /// Процесс взаимодействия сервера с ИИ
        /// </summary>
        /// <param name="player">Активный ИИ</param>
        private void AiInteractionProcess(Lori player, List <PlayingCard> hand)
        {
            // определение того, что нужно ожидать от ИИ
            ActionAI currentUserAction;

            if (TableBox.Count == 0)
            {
                PrintLogs($"{player} запрос хода ActionAI.FirstMove");
                currentUserAction = ActionAI.FirstMove;
            }
            else if (TableBox.Count % 2 == 0)
            {
                PrintLogs($"{player} запрос хода ActionAI.Attack");
                currentUserAction = ActionAI.Attack;
            }
            else
            {
                PrintLogs($"{player} запрос хода ActionAI.Protection");
                currentUserAction = ActionAI.Protection;
            }

            // через количества определим потом какие изменения были
            var countHandPlayerBoxOld = hand.Count;
            var countTableBoxOld      = TableBox.Count;

            // запрос хода у ИИ
            player.MakeMove(hand, TableBox, DeckBox.Count());

            // проверка что изменилось:
            // ActionAI.FirstMove не требует доп. проверки
            // ActionAI.Attack требует доп. проверки: подкинули или пасанули
            // ActionAI.Protection требует доп. проверки: забрали или отбились
            var countHandPlayerBoxNew = hand.Count;
            var countTableBoxNew      = TableBox.Count;

            if (currentUserAction == ActionAI.FirstMove)
            {
                PrintLogs($"{player} провел ActionAI.FirstMove");
            }
            else if (currentUserAction == ActionAI.Attack)
            {
                if (countHandPlayerBoxNew == countHandPlayerBoxOld && countTableBoxNew == countTableBoxOld)
                {
                    PrintLogs($"{player} провел ActionAI.Attack: Пас");
                    // нужно "сделать" пас:
                    // - скинуть карты со стола
                    // - закинуть карты в руки игрокам (если есть)
                    Discard();
                }
                else if (countHandPlayerBoxNew == countHandPlayerBoxOld - 1 && countTableBoxNew == countTableBoxOld + 1)
                {
                    PrintLogs($"{player} провел ActionAI.Attack: Подкинуть");
                }
                else
                {
                    throw new Exception("Неизвестная ситуация");
                }
            }
            else if (currentUserAction == ActionAI.Protection)
            {
                if (countTableBoxNew == 0 && countTableBoxOld + countHandPlayerBoxOld == countHandPlayerBoxNew)
                {
                    PrintLogs($"{player} провел ActionAI.Protection: Забрать карты со стола");
                    DealCardsToPlayers();
                }
                else if (countHandPlayerBoxNew == countHandPlayerBoxOld - 1 && countTableBoxNew == countTableBoxOld + 1)
                {
                    PrintLogs($"{player} провел ActionAI.Attack: Отбиться");
                }
                else
                {
                    throw new Exception("Неизвестная ситуация");
                }
            }
            else
            {
                throw new Exception("Такое состояние не должно определяться, что-то пошло не так");
            }
        }