예제 #1
0
 /// <summary>
 /// Checks if a brain is the same as this brain.
 /// 2 brains are the same if all of their genes match, their outputNodes match, their inputNodes match and the input and output counts match.
 /// </summary>
 /// <param name="other">The brain to compare against.</param>
 /// <returns>Returns <c>true</c> if the brain is the same; otherwise, <c>false</c>.</returns>
 private bool Equals(Brain other)
 {
     return(ConnectionGenes.SequenceEqual(other.ConnectionGenes) &&
            _outputNodes.SequenceEqual(other._outputNodes) &&
            _inputNodes.SequenceEqual(other._inputNodes) &&
            TrainingRoom.TrainingRoomSettings.InputCount == other.TrainingRoom.TrainingRoomSettings.InputCount &&
            TrainingRoom.TrainingRoomSettings.OutputCount == other.TrainingRoom.TrainingRoomSettings.OutputCount);
 }
예제 #2
0
        /// <summary>
        /// Checks if an object is the same as this organism.
        /// An object is the same if it is a organism, and if the organism specific equals method returns true.
        /// </summary>
        /// <param name="obj">The object to compare to.</param>
        /// <param name="once">The value that determines whether the inputs and outputs should also be used in the equals equation.</param>
        /// <returns>Returns <c>true</c> if it is the same; otherwise, <c>false</c>.</returns>
        public bool Equals(object obj, bool once)
        {
            if (!(obj is Organism organism))
            {
                return(false);
            }

            // Checks if a organism is the same as this organism.
            // 2 organisms are the same if all of their genes match, their outputNodes match,
            // their inputNodes match and the input and output counts match.
            bool sequenceEqual = ConnectionGenes.SequenceEqual(organism.ConnectionGenes);

            if (once)
            {
                return(sequenceEqual);
            }

            bool equal = Inputs.SequenceEqual(organism.Inputs);
            bool b     = Outputs.SequenceEqual(organism.Outputs);

            return(sequenceEqual &&
                   equal &&
                   b);
        }