示例#1
0
        public IReadOnlyCollection <IMove> GetAvailableMoves(Player player)
        {
            //No moves are available within a second of the previous move occurring
            if (_getTime() - lastMoveTaken < TimeSpan.FromSeconds(1))
            {
                return(new List <IMove>());
            }


            var numberOfMovesSoFar = Squares.Count(sq => sq != ' ');
            var nextPlayer         = numberOfMovesSoFar % 2 == 0 ? _player1 : _player2;

            //No moves are available to players whos turn it aint
            if (nextPlayer != player)
            {
                return(new List <IMove>());
            }

            var nextPlayerSymbol = numberOfMovesSoFar % 2 == 0 ? 'x' : 'o';

            return(Squares
                   .Select((c, i) => c == ' ' ? new TicTacToeMove(this, i, nextPlayerSymbol) : null)
                   .Where(move => move != null)
                   .ToList()
                   .AsReadOnly());
        }
示例#2
0
 private bool CheckForStalemate() => Squares.All(sq => sq != ' ');