コード例 #1
0
        private MinMaxScore GetMinMaxScore(Board board, Play play, int depth)
        {
            MinMaxScore minMaxScore = new MinMaxScore
            {
                Play   = play,
                Points = 0
            };

            // Check win condition for player X
            if (board.IsVictoryCondition(Marker.X))
            {
                minMaxScore.Points = play.PlayerId == Marker.X ? 10 - depth : depth - 10;
                return(minMaxScore);
            }
            // Check win condition for player O
            if (board.IsVictoryCondition(Marker.O))
            {
                minMaxScore.Points = play.PlayerId == Marker.O ? 10 - depth : depth - 10;
                return(minMaxScore);
            }
            // Check draw condition
            if (board.AreAllPositionMarked())
            {
                return(minMaxScore);
            }
            // otherwise...
            return(null);
        }