Example #1
0
        protected override int dividePile(Pile pile)
        {
            int chosenDivisor;

            Console.WriteLine("\nHow many elements would you like to take from this pile?");

            while (true)
            {
                if (!Int32.TryParse(Console.ReadLine(), out chosenDivisor))
                {
                    Console.WriteLine("\nNot a valid value, choose a number between 0 and the size of the pile!");
                    continue;
                }

                if (chosenDivisor < 1 || chosenDivisor >= pile.size)
                {
                    Console.WriteLine("\nNot a valid number, choose one between 0 and the size of the pile!");
                    continue;
                }

                if ((pile.size - chosenDivisor).Equals(chosenDivisor))
                {
                    Console.WriteLine("\nNot a valid number, you cannot divide a pile into two equal pieces!");
                    continue;
                }

                Console.WriteLine("-------------------------------\n");

                return(chosenDivisor);
            }
        }
        public override Tuple <int, int> playTurn(List <Pile> piles)
        {
            Console.WriteLine("\n-------------------------------\nIt is the computer's turn (" + name + ")!");
            Console.WriteLine("\nThe current piles (ID, size):");

            foreach (Pile pile in piles)
            {
                Console.WriteLine("( " + pile.ID + ", " + pile.size + " ) ");
            }

            Pile chosenPile = choosePile(piles);

            int taken = dividePile(chosenPile);

            Console.WriteLine("\nIt choose the pile with ID = " + chosenPile.ID + " and took "
                              + taken + " elements from it!\n-------------------------------");

            return(new Tuple <int, int>(chosenPile.ID, taken));
        }
Example #3
0
        public override Tuple <int, int> playTurn(List <Pile> piles)
        {
            Pile chosenPile = choosePile(piles);

            return(new Tuple <int, int>(chosenPile.ID, dividePile(chosenPile)));
        }
 protected abstract int dividePile(Pile pile);
 protected override int dividePile(Pile pile)
 {
     return(pile.size % 2 == 0 ? pile.size / 2 - 1 : pile.size / 2);
 }