コード例 #1
0
ファイル: GameEngine.cs プロジェクト: victorbohmer/FlipFlop
        private void PlayAITurn()
        {
            Board.ResetSpaceColors();
            SelectedCard = AIPlayer.SelectCardToPlay();
            BoardCardSpace boardSpace = AIPlayer.SelectSpaceToPlayOn(SelectedCard);

            PlayCard(boardSpace);
        }
コード例 #2
0
ファイル: GameEngine.cs プロジェクト: victorbohmer/FlipFlop
        private void PlayCard(BoardCardSpace boardSpace)
        {
            Card playedCard = SelectedCard.TakeCard();

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

            RoundOver();
        }
コード例 #3
0
ファイル: GameEngine.cs プロジェクト: victorbohmer/FlipFlop
        public void TryToPlayCard(string boardSpaceName)
        {
            if (SelectedCard == null || SelectedCard.IsEmpty)
            {
                return;
            }

            BoardCardSpace boardSpace = Board.GetByName(boardSpaceName);

            if (!boardSpace.IsEmpty)
            {
                return;
            }

            PlayCard(boardSpace);
        }
コード例 #4
0
ファイル: Aziraphale.cs プロジェクト: victorbohmer/FlipFlop
        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);
        }
コード例 #5
0
ファイル: Aziraphale.cs プロジェクト: victorbohmer/FlipFlop
        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());
        }