Esempio n. 1
0
        public static ICollection <int> Permutation(RoboCard[] cards, int start, int n)
        {
            HashSet <int> result = new HashSet <int>();

            if (start == n)
            {
                result.Add(RoboCard.EncodeCards(cards));
            }
            else
            {
                for (int i = start; i < cards.Length; i++)
                {
                    RoboCard tmp = cards[i];

                    cards[i]     = cards[start];
                    cards[start] = tmp;

                    result.AddRange(Permutation(cards, start + 1, n));

                    cards[start] = cards[i];
                    cards[i]     = tmp;
                }
            }

            return(result);
        }
Esempio n. 2
0
        public static RoboCard[] LoadCards(String filename, int amount)
        {
            RoboCard[]   cards  = new RoboCard[amount];
            StreamReader reader = null;

            try
            {
                reader = new StreamReader(filename, Encoding.UTF8);

                for (int i = 0; i < cards.Length; i++)
                {
                    cards[i] = RoboCard.DecodeCard(reader.ReadLine());
                }
            }
            catch
            {
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(cards);
        }
Esempio n. 3
0
 /// <summary>
 /// Save cards to file.
 /// </summary>
 /// <param name="filename">File to save to.</param>
 /// <param name="cards">Cards to save.</param>
 public static void SaveCardsToFile(String filename, IEnumerable <RoboCard> cards)
 {
     using (StreamWriter writer = new StreamWriter(filename, false))
     {
         foreach (RoboCard card in cards)
         {
             writer.WriteLine(RoboCard.EncodeCard(card));
         }
         writer.Close();
     }
 }
Esempio n. 4
0
        public static RoboCard[] CreateCardPile()
        {
            List <RoboCard> temp       = CreateCardPile(CARD_DECK_SIZE);
            Random          randomizer = new Random();

            RoboCard[] pile = new RoboCard[CARD_DECK_SIZE];
            for (int k = 0; k < CARD_DECK_SIZE; k++)
            {
                int randomIndex = randomizer.Next(temp.Count);
                pile[k] = temp[randomIndex];
                temp.RemoveAt(randomIndex);
            }

            return(pile);
        }
Esempio n. 5
0
 private bool DrawCards()
 {
     Cards = new RoboCard[8];
     try
     {
         for (int i = 0; i < 8; i++)
         {
             Cards[i] = CardPile[8 * (Round - 1) + i];
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Esempio n. 6
0
        public static RoboPosition PlayCardCore(RoboBoard board, RoboCard card, RoboPosition position)
        {
            foreach (RoboAction action in card.GetActionList(position))
            {
                if (position.IsDead || board.GetField(position).IsDestination)
                {
                    return(position);
                }
                position.Assign(PerformAction(board, ActionPhase.ActionCard, action, position));
            }

            position.Assign(PerformAction(board, ActionPhase.ActionConveyor, RoboAction.EMPTY, position));
            position.Assign(PerformAction(board, ActionPhase.ActionPusher, RoboAction.EMPTY, position));
            position.Assign(PerformAction(board, ActionPhase.ActionRotator, RoboAction.EMPTY, position));

            return(position);
        }
Esempio n. 7
0
 public static RoboPosition PlayCard(RoboBoard board, RoboCard card, RoboPosition position)
 {
     return(PlayCardCore(board, card, new RoboPosition(position)));
 }
Esempio n. 8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public RoboPlayer()
 {
     Cards    = new RoboCard[8];
     Position = new RoboPosition(0, 0, Direction.Up);
 }