private void PlayAITurn() { Board.ResetSpaceColors(); SelectedCard = AIPlayer.SelectCardToPlay(); BoardCardSpace boardSpace = AIPlayer.SelectSpaceToPlayOn(SelectedCard); PlayCard(boardSpace); }
private void PlayCard(BoardCardSpace boardSpace) { Card playedCard = SelectedCard.TakeCard(); boardSpace.PlaceCard(playedCard); Board.FlipFlopCard(boardSpace, ActivePlayer.Id); RoundOver(); }
public void TryToPlayCard(string boardSpaceName) { if (SelectedCard == null || SelectedCard.IsEmpty) { return; } BoardCardSpace boardSpace = Board.GetByName(boardSpaceName); if (!boardSpace.IsEmpty) { return; } PlayCard(boardSpace); }
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); }
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()); }