Esempio n. 1
0
        private void PlayAITurn()
        {
            Board.ResetSpaceColors();
            SelectedCard = AIPlayer.SelectCardToPlay();
            BoardCardSpace boardSpace = AIPlayer.SelectSpaceToPlayOn(SelectedCard);

            PlayCard(boardSpace);
        }
Esempio n. 2
0
        private void PlayCard(BoardCardSpace boardSpace)
        {
            Card playedCard = SelectedCard.TakeCard();

            boardSpace.PlaceCard(playedCard);
            Board.FlipFlopCard(boardSpace, ActivePlayer.Id);

            RoundOver();
        }
Esempio n. 3
0
        public void TryToPlayCard(string boardSpaceName)
        {
            if (SelectedCard == null || SelectedCard.IsEmpty)
            {
                return;
            }

            BoardCardSpace boardSpace = Board.GetByName(boardSpaceName);

            if (!boardSpace.IsEmpty)
            {
                return;
            }

            PlayCard(boardSpace);
        }
Esempio n. 4
0
        private BoardCardSpace FindRandomEmptyNeighbouringSpace(BoardCardSpace boardSpace)
        {
            List <Direction> directions = new List <Direction> {
                Direction.Left, Direction.Right, Direction.Up, Direction.Down
            };

            for (int i = 0; i < 4; i++)
            {
                Direction randomDirection = directions[random.Next(directions.Count)];
                directions.Remove(randomDirection);
                BoardCardSpace neighbouringSpace = Board.GetNeighbour(boardSpace, randomDirection);
                if (neighbouringSpace != null && neighbouringSpace.Card == null)
                {
                    return(neighbouringSpace);
                }
            }
            //returns null if it fails to find an empty neighbour
            return(null);
        }
Esempio n. 5
0
        public override BoardCardSpace SelectSpaceToPlayOn(PlayerCardSpace selectedCard)
        {
            //The AI will always take the highest card it can on the board where possible
            List <BoardCardSpace> spacesThatCanBeTaken = Board.Spaces.Where(x =>
                                                                            x.Card != null &&
                                                                            x.Card.Value < selectedCard.Card.Value &&
                                                                            x.Owner != 2)
                                                         .OrderByDescending(x => x.Card.Value)
                                                         .ToList();

            if (spacesThatCanBeTaken != null)
            {
                foreach (BoardCardSpace boardSpace in spacesThatCanBeTaken)
                {
                    BoardCardSpace emptyNeighbouringSpace = FindRandomEmptyNeighbouringSpace(boardSpace);
                    if (emptyNeighbouringSpace != null)
                    {
                        return(emptyNeighbouringSpace);
                    }
                }
            }

            return(Board.RandomEmptySpace());
        }