Example #1
0
        /// <summary>
        /// Copies the current contents of this Deck from the specified Deck.
        /// </summary>
        public void CopyFrom(Deck deck)
        {
            if(deck == null)
                throw new ArgumentNullException("deck");

            _cardValues.Clear();
            _cardValues.AddRange(deck._cardValues);
        }
Example #2
0
        /// <summary>
        /// Initializes the counts in a new FastDeck to the card counts in the specified Deck.
        /// </summary>
        public FastDeck(Deck deck)
        {
            if(deck == null)
                throw new ArgumentNullException("deck");

            Dictionary<int, int> cardCounts = deck.GetCountsOfCards();
            cardCounts.TryGetValue(1, out Ones);
            cardCounts.TryGetValue(2, out Twos);
            cardCounts.TryGetValue(3, out Threes);
        }
Example #3
0
        /// <summary>
        /// Creates a new Game that uses the specified random number generator.
        /// </summary>
        public Game(Rand rand)
        {
            if(rand == null)
                throw new ArgumentNullException("rand");

            _rand = rand;
            _deck = new Deck(_rand);
            _board = new Board();

            InitializeBoard();

            _prevBoard = new Board(_board);
            _tempBoard = new Board();
        }
Example #4
0
 /// <summary>
 /// Creates a new Deck with cards copied from the specified Deck.
 /// </summary>
 public Deck(Deck copyFrom)
 {
     CopyFrom(copyFrom);
 }
Example #5
0
        /// <summary>
        /// Main application entry point.
        /// </summary>
        private static void Main()
        {
            // Build the board and initialize the deck.
            Deck deck = new Deck(new Rand());
            Board board = new Board();
            Console.WriteLine("Let's initialize the board...");
            Console.WriteLine("The format for each line should be four characters, each a 1, 2, 3, or any other character to represent an empty space.");
            for(int y = 0; y < board.Height; y++)
            {
                Console.Write("Enter row {0}: ", y);
                string rowStr = Console.ReadLine();
                if(rowStr.Length != board.Width)
                {
                    Console.WriteLine("Invalid length of entered row.");
                    y--;
                    continue;
                }

                for(int x = 0; x < board.Width; x++)
                {
                    Card card = GetCardFromChar(rowStr[x], false);
                    if(card != null)
                    {
                        board[x, y] = card;
                        deck.RemoveCard(card.Value);
                    }
                }
            }
            Console.WriteLine("Board and deck successfully initialized.");

            Stack<Board> boardsStack = new Stack<Board>();
            Stack<Deck> decksStack = new Stack<Deck>();

            // Now let's play!
            while(true)
            {
            redo:

                // Print the current board status.
                Console.WriteLine("--------------------");
                for(int y = 0; y < board.Height; y++)
                {
                    for(int x = 0; x < board.Width; x++)
                    {
                        Card c = board[x, y];
                        if(c != null)
                            Console.Write("{0},", c.Value);
                        else
                            Console.Write(" ,");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("--------------------");
                Console.WriteLine("Current total score: {0}", board.GetTotalScore());

                // Get the next card.
                Console.Write("What is the next card? ");
                string nextCardStr;
                Card nextCard;
                do
                {
                    nextCardStr = Console.ReadLine();
                    if(nextCardStr == "undo")
                    {
                        board = boardsStack.Pop();
                        deck = decksStack.Pop();
                        goto redo;
                    }
                }
                while(nextCardStr.Length != 1 || (nextCard = GetCardFromChar(nextCardStr[0], true)) == null);
                NextCardHint nextCardHint = GetNextCardHint(nextCard);

                // Choose a move.
                Console.Write("Thinking...");
                ShiftDirection? aiDir = _bot.GetNextMove(new FastBoard(board), new FastDeck(deck), nextCardHint);
                if(aiDir != null)
                    Console.WriteLine("\nSWIPE {0}.", aiDir.Value.ToString().ToUpper());
                else
                {
                    Console.WriteLine("NO MORE MOVES.");
                    break;
                }

                // Confirm the swipe.
                ShiftDirection? actualDir = aiDir.Value;
                /*do
                {
                    Console.Write("What direction did you swipe in? (l, r, u, d, or just hit enter for the suggested swipe) ");
                    string dirStr = Console.ReadLine();
                    actualDir = GetShiftDirection(dirStr, aiDir.Value);
                }
                while(actualDir == null);*/
                List<IntVector2D> newCardCells = new List<IntVector2D>();
                board.Shift(actualDir.Value, newCardCells);

                // Get the new card location.
                int newCardIndex;
                if(newCardCells.Count > 1)
                {
                    Console.WriteLine("Here are the locations where a new card might have been inserted:");
                    for(int y = 0; y < board.Height; y++)
                    {
                        for(int x = 0; x < board.Width; x++)
                        {
                            int index = newCardCells.IndexOf(new IntVector2D(x, y));
                            if(index >= 0)
                                Console.Write((char)('a' + index));
                            else
                                Console.Write('.');
                        }
                        Console.WriteLine();
                    }
                    Console.Write("Where was it actually inserted? ");
                    do
                    {
                        string indexStr = Console.ReadLine();
                        if(indexStr.Length == 1)
                            newCardIndex = indexStr[0] - 'a';
                        else
                            newCardIndex = -1;
                    }
                    while(newCardIndex < 0 || newCardIndex >= newCardCells.Count);
                }
                else
                {
                    newCardIndex = 0;
                }

                // Get new card value.
                int newCardValue;
                if(nextCardHint == NextCardHint.Bonus)
                {
                    do
                    {
                        Console.Write("!!! What is the value of the new card? ");
                    }
                    while(!TryGetNewCardValue(Console.ReadLine(), out newCardValue));
                }
                else
                {
                    newCardValue = (int)nextCardHint + 1;
                }
                deck.RemoveCard(newCardValue);
                board[newCardCells[newCardIndex]] = new Card(newCardValue, -1);

                boardsStack.Push(new Board(board));
                decksStack.Push(new Deck(deck));
            }

            Console.WriteLine("FINAL SCORE IS {0}.", board.GetTotalScore());
        }