Exemple #1
0
        /// <summary>
        /// Checks whether two states are equal. Two states are defined equal when both canisters contain exactly the same amount of water.
        /// </summary>
        /// <param name="other">The other state to test for equality with this state.</param>
        /// <returns>True if both states are equal, otherwise false.</returns>
        public override bool Equals(Search.State other)
        {
            var s = other as State;

            if (s == null)
            {
                return(false);
            }
            return(s.K1 == this.K1 && s.K2 == this.K2);
        }
Exemple #2
0
        /// <summary>
        /// Checks whether two states are equal. Two states are defined equal when they contain the same positions in not necessarily the same order.
        /// </summary>
        /// <param name="other">The other state to test for equality with this state.</param>
        /// <returns>True if both states are equal, otherwise false.</returns>
        public override bool Equals(Search.State other)
        {
            var s = other as State;

            if (s == null)
            {
                return(false);
            }
            if (s.Positions.Length != this.Positions.Length)
            {
                return(false);
            }
            for (int i = 0; i < Positions.Length; i++)
            {
                // if all positions in s are different from Positions[i], return false
                if (s.Positions.All(p => p.X != Positions[i].X || p.Y != Positions[i].Y))
                {
                    return(false);
                }
            }
            return(true);
        }