Ejemplo n.º 1
0
 public override bool Equals(object?obj)
 {
     if (obj is null)
     {
         return(false);
     }
     if (obj.GetType() == this.GetType())
     {
         WaterJars o = (WaterJars)obj;
         return(o.Jar1State == this.Jar1State && o.Jar2State == this.Jar2State);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
        public ActionStateInterface doAction(string pAction)
        {
            WaterJars state = (WaterJars)this.Clone();

            switch (pAction)
            {
            case WaterJarsActions.EMPTY1:
                state.Jar1State = WaterJarsStates.EMPTY;
                break;

            case WaterJarsActions.EMPTY2:
                state.Jar2State = WaterJarsStates.EMPTY;
                break;

            case WaterJarsActions.FILL1:
                state.Jar1State = WaterJarsStates.L3;
                break;

            case WaterJarsActions.FILL2:
                state.Jar2State = WaterJarsStates.L4;
                break;

            case WaterJarsActions.TRANSFER1TO2:
                int transfer = Math.Min(state.Jar1State, 4 - state.Jar2State);
                Console.WriteLine($" action: {pAction}, transfer: {transfer}, jar1: {state.Jar1State}, jar2: {state.Jar2State} ");

                state.Jar1State -= transfer;
                state.Jar2State += transfer;
                break;

            case WaterJarsActions.TRANSFER2TO1:
                int transfer01 = Math.Min(state.Jar2State, 3 - state.Jar1State);
                Console.WriteLine($" action: {pAction}, transfer: {transfer01}, jar1: {state.Jar1State}, jar2: {state.Jar2State} ");


                state.Jar1State -= transfer01;
                state.Jar2State += transfer01;
                break;
            }

            return(state);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            WaterJars initial = new WaterJars(WaterJarsStates.EMPTY, WaterJarsStates.L1);

            List <ActionStateInterface> finals = new List <ActionStateInterface>()
            {
                new WaterJars(WaterJarsStates.EMPTY, WaterJarsStates.L2),
                new WaterJars(WaterJarsStates.L1, WaterJarsStates.L2),
                new WaterJars(WaterJarsStates.L2, WaterJarsStates.L2),
                new WaterJars(WaterJarsStates.L3, WaterJarsStates.L2)
            };

            UninformedSearch problem = new UninformedSearch(initial, finals);

            List <CandidateState> result = problem.search();

            foreach (CandidateState state in result)
            {
                Console.WriteLine(state.ToString());
            }

            Console.ReadLine();
        }