Ejemplo n.º 1
0
//все эти методы должны принимать в аргументах все что им надо
//TryToDefence(Hand, Triumph, Offence, Defence) -- отдельно сделать методы для проверки корректности перевода,
// - корректности покрыти CheckTransfer, CheckDefend
//только проверка корректности

// изменения в отдельном методе, и его можно не тестировать

        static public void TryToDefense(DefendInfo defend)
        {
            if (defend.Move == WhatMove.Take)
            {
                foreach (var e in Program.table.TablePosition)
                {
                    Program.players[Program.turn].hand.Add(e.OffCard);
                }
            }
            if (defend.Move == WhatMove.Defend)
            {
                int i = 0;
                for (; i < Program.table.TablePosition.Count; i++)
                {
                    if (!Program.table.TablePosition[i].IsBeaten())
                    {
                        break;
                    }
                }
                if (Program.table.TablePosition.Count - i - 1 != defend.BeatenCards.Count)
                {
                    throw new Exception();//��� � �� ����. ��������, ����� ������ ���������� �� �� �����...
                }
                for (int j = 0; j < Program.table.TablePosition.Count; j++)
                {//��� � �� ����, ��� ��-������� ��� ��������... ���� ���� ���� - �������
                    var inHand      = Program.players[Program.turn].hand.Contains(defend.BeatenCards[j]);
                    var sameSuit    = Program.table.TablePosition[i + j].OffCard.suit == defend.BeatenCards[j].suit;
                    var lessNominal = Program.table.TablePosition[i + j].OffCard.nominal > defend.BeatenCards[j].nominal;
                    var isTrump     = defend.BeatenCards[j].suit == Program.trumpCard.suit;
                    if (!inHand ||
                        (sameSuit && lessNominal) ||
                        (!sameSuit && !isTrump))
                    {
                        throw new Exception();
                    }
                    Program.players[Program.turn].hand.Remove(defend.BeatenCards[j]);
                    Program.table.TablePosition[i + j].DefCard = defend.BeatenCards[j];
                }
            }
            if (defend.Move == WhatMove.Translate)
            {
                foreach (var e in defend.BeatenCards)//������ ��� �������, ������� �� �� ������� 2 ���������� �����
                {
                    if (!Program.players[Program.turn].hand.Contains(e))
                    {
                        throw new Exception();
                    }
                    else
                    {
                        Program.table.TablePosition.Add(new PairCard()
                        {
                            OffCard = e, DefCard = null
                        });
                        Program.players[Program.turn].hand.Remove(e);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public DefendInfo Defend(MoveInfo moveInfo)//Table table, int enemyCardCount, List<Card> myHand)
        {
            var info = new DefendInfo();

            info.BeatenCards = new List <Card>();
            var table  = moveInfo.CurrentTable;
            var myHand = moveInfo.PlayerHand;

            if (table.TablePosition.Count == 1) //перевод, если карта одна
            {
                foreach (var value in myHand)
                {
                    if (value.nominal == table.TablePosition[0].OffCard.nominal)
                    {
                        info.BeatenCards.Add(value);
                        info.Move = WhatMove.Translate;
                        return(info);
                    }
                }
            }
            foreach (var value in table.TablePosition)
            {
                if (!value.IsBeaten())
                {
                    foreach (var value2 in myHand) //попытка отбиться с помощью не-козыря
                    {
                        if (value2.suit == value.OffCard.suit && value2.nominal > value.OffCard.nominal)
                        {
                            info.BeatenCards.Add(value2);
                        }
                    }
                    if (value.IsBeaten())
                    {
                        continue;
                    }
                    foreach (var value2 in myHand) //попытка отбиться с помозью козыря
                    {
                        if (Program.trumpCard.suit == value2.suit && value.OffCard.suit != Program.trumpCard.suit)
                        {
                            info.BeatenCards.Add(value2);
                        }
                    }
                    if (value.IsBeaten())
                    {
                        continue;
                    }
                    table.Clear(); //взять карты, вернуть пустой стол. арбитр разберется.
                    info.Move = WhatMove.Take;
                    return(info);
                }
            }
            return(info);
        }
Ejemplo n.º 3
0
        static public Dictionary <string, Card> defaultPack = FormDict(); //словарь со всеми картами.
        static void Main(string[] args)
        {
            Console.WriteLine("Let's play!");
            pack      = Arbiter.FormInitialPack();
            trumpCard = pack.First();
            players   = new Player[countOfPlayer];
            for (int i = 0; i < countOfPlayer; i++)
            {
                players[i] = new Player();
                Arbiter.GiveCardsToPlayer(players[i], pack);
            }
            foreach (Nominal nominal in (Nominal[])Enum.GetValues(typeof(Nominal)))
            {
                Card card = new Card(trumpCard.suit, nominal);
                for (int i = 0; i < countOfPlayer; i++)
                {
                    if (players[i].hand.Contains(card))
                    {
                        turn = (i + 1) % countOfPlayer;
                        break;
                    }
                }
            }
            bool t = false;

            while (true)
            {
                if (t)
                {
                    break;
                }
                AttackResponse firstAttack = players[(turn - 1 + countOfPlayer) % countOfPlayer].FirstMove(
                    new MoveInfo()
                {
                    CurrentTable = table, PlayerHand = players[(turn - 1 + countOfPlayer) % countOfPlayer].hand, Suit = trumpCard.suit
                });
                Arbiter.TryToAttack(firstAttack, (turn - 1 + countOfPlayer) % countOfPlayer);
                while (true)//Пока что понятия не имею, когда это закончить. нужна помощь
                {
                    DefendInfo defend = players[turn].Defend(
                        new MoveInfo()
                    {
                        CurrentTable = table, PlayerHand = players[(turn - 1 + countOfPlayer) % countOfPlayer].hand, Suit = trumpCard.suit
                    });
                    if (defend.Move == WhatMove.Translate)
                    {
                        turn += 1;
                        continue;
                    }
                    if (defend.Move == WhatMove.Take)
                    {
                        turn = (turn + 2) % countOfPlayer;
                        break;
                    }
                    AttackResponse addAttack = players[(turn + 1) % countOfPlayer].AdditionalMove(
                        new MoveInfo()
                    {
                        CurrentTable = table, PlayerHand = players[(turn - 1 + countOfPlayer) % countOfPlayer].hand, Suit = trumpCard.suit
                    });
                    Arbiter.TryToAttack(addAttack, (turn + 1) % countOfPlayer);
                    addAttack = players[(turn - 1 + countOfPlayer) % countOfPlayer].AdditionalMove(
                        new MoveInfo()
                    {
                        CurrentTable = table, PlayerHand = players[(turn - 1 + countOfPlayer) % countOfPlayer].hand, Suit = trumpCard.suit
                    });
                    Arbiter.TryToAttack(addAttack, (turn - 1 + countOfPlayer) % countOfPlayer);
                }
            }
        }