Exemple #1
0
 /// <summary>
 /// Creates a new move
 /// </summary>
 /// <param name="cardToPlay">The card to be played</param>
 /// <param name="slotToPlay">The slot to play into</param>
 public Move(Card cardToPlay, CardSlot slotToPlay)
 {
     CardToPlay = cardToPlay;
     SlotToPlay = slotToPlay;
 }
        /// <summary>
        /// Gets a random empty slot from one of the tiles
        /// </summary>
        /// <param name="tiles">The list of tiles to get a random empty slot from</param>
        /// <returns>A random empty slot, or null if there were no empty slots</returns>
        private CardSlot GetRandomEmptySlot(List<Tile> tiles, CardSlot.Position position)
        {
            List<CardSlot> emptySlots = new List<CardSlot>();

            // Gather all empty slots on the board
            foreach (Tile tile in tiles)
                foreach (CardSlot slot in tile.CardSlots)
                    if (slot.CurrentCard == null && slot.SlotPosition == position)   // Only cards from the computer's side for now
                        emptySlots.Add(slot);

            if (emptySlots.Count == 0)
                // Return null if no empty slots are found
                return null;
            else
                // Return random empty slot if list < 0
                return emptySlots[rand.Next(0, emptySlots.Count)];
        }
        private Card FindAppropriateCardToPlay(CardSlot slot, bool tryToWin)
        {
            // Create list of valid cards to play
            List<Card> validCards = new List<Card>();

            foreach (Card card in Hand.Cards)
                if (slot.OwnerTile.HasEmptySlotWithMatchingCube(card, slot))
                    validCards.Add(card);

            if (validCards.Count == 0)
            {
                Console.WriteLine("Couldn't find a matching card in hand for " + slot);
                return null;    // There are no valid cards to play on this slot
            }

            if (tryToWin == true)
            {
                // Play the best card we can
                if (slot.OwnerTile.Terrain == Tile.TerrainType.Flatland)
                    return GetLowestCard(validCards);
                else
                    return GetHighestCard(validCards);
            }
            else
            {
                // Play the worst card we can
                if (slot.OwnerTile.Terrain == Tile.TerrainType.Flatland)
                    return GetLowestCard(validCards);
                else
                    return GetHighestCard(validCards);
            }
        }
Exemple #4
0
        /// <summary>
        /// Checks if this side of the tile has a spare slot for this colour.
        /// e.g. If the number of Red Cards is equal to the number of Red Cubes, this returns false
        /// because the player needs to fill the other colours.
        /// </summary>
        /// <param name="card">The card to check for</param>
        /// <param name="slot">The slot to check against</param>
        /// <returns>The validity of the move</returns>
        public bool HasEmptySlotWithMatchingCube(Card card, CardSlot slot)
        {
            ColouredObject.Colours colour = card.Colour;
            CardSlot.Position position = slot.SlotPosition;

            return HasEmptySlotWithMatchingCube(colour, position);
        }
Exemple #5
0
        /// <summary>
        /// Checks if this side of the tile has a spare slot for this colour.
        /// e.g. If the number of Red Cards is equal to the number of Red Cubes, this returns false
        /// because the player needs to fill the other colours.
        /// </summary>
        /// <param name="colour">The colour to check for</param>
        /// <param name="position">The slot's position around the tile</param>
        /// <returns>The validity of the move</returns>
        public bool HasEmptySlotWithMatchingCube(ColouredObject.Colours colour, CardSlot.Position position)
        {
            if(HasCubeWithColour(colour))    // If a Cube with this colour exists
            {
                // Count how many cubes have this colour
                int numCubesWithColour = 0;
                foreach(Cube cube in _cubes)
                    if(cube.Colour == colour)
                        numCubesWithColour++;

                // See how many slots already have a card with this colour
                int numCardsWithColour = 0;
                foreach(CardSlot cardSlot in CardSlots)
                    // If the slot already has a card of this colour in it
                    if(cardSlot.SlotPosition == position && cardSlot.CurrentCard != null && cardSlot.CurrentCard.Colour == colour)
                         numCardsWithColour++;

                // Are there already the same amount of cubes with this colour as cards with this colour?
                if (numCardsWithColour >= numCubesWithColour)
                    return false;
                else
                    return true;
            }
            else
                return false;
        }
Exemple #6
0
        /// <summary>
        /// Returns an empty slot on the tile
        /// </summary>
        /// <param name="position">Which side of the tile to return from</param>
        /// <returns>An empty slot</returns>
        public CardSlot GetEmptySlot(CardSlot.Position position)
        {
            foreach (CardSlot slot in CardSlots)
                if (slot.SlotPosition == position && slot.Empty)
                    return slot;

            return null;
        }