Example #1
0
        /* FIN ATRIBUTOS */

        /* METODO QUE CREA UN LABERINTO DESDE PROLOG E INICIALIZA EL ATRIBUTO REPRESENTACIONLABERINTO Y LABERINTO
         * LA CANTIDAD DE TROFEOS ESTA DADA POR EL NIVEL DE DIFICULTAD ENTRE 0 Y 10, NADA DE TROFEOS O LLENO.
         */
        public void crearLaberinto(int dimensionX, int dimensionY, int nivelDificultad)
        {
            Term nil = SymbolTerm.MakeSymbol("0");
            bool resultado;
            //laberinto(L,DimX,DimY,Dificultad,MinimosCaminosSalida(noImplementado))
            Predicate    predicate;
            VariableTerm laberintoCompleto;
            Laberinto_5  lab;

            /* INSTANCIAS */
            VariableTerm laberinto  = new VariableTerm();
            VariableTerm trofeos    = new VariableTerm();
            VariableTerm inicio     = new VariableTerm();
            VariableTerm final      = new VariableTerm();
            IntegerTerm  dimX       = new IntegerTerm(dimensionX);
            IntegerTerm  dimY       = new IntegerTerm(dimensionY);
            IntegerTerm  dificultad = new IntegerTerm(nivelDificultad);

            if (pInterface == null)
            {
                pInterface = new PrologInterface();
            }
            /* FIN */

            //MIENTRAS NO GENERE UN RESULTADO INTENTARA CREAR UN LABERINTO
            do
            {
                /* === INSTANCIAS Y EJECUCION PARA LA CREACION DEL LABERINTO MEDIANTE PROLOG === */
                laberintoCompleto = new VariableTerm();
                lab       = new Laberinto_5(laberintoCompleto, dimX, dimY, dificultad, nil, new ReturnCs(pInterface));
                predicate = lab;
                pInterface.SetPredicate(predicate);
                resultado = pInterface.Call();
                /* === FINALIZA INSTANCIAS Y EJECUCIONES === */
                if (resultado)
                {
                    /* === ASIGNACION DE ATRIBUTOS DE CLASE === */
                    predicate = new Get_Lab_2(laberintoCompleto, laberinto, new ReturnCs(pInterface));
                    pInterface.SetPredicate(predicate);
                    pInterface.Call();
                    predicate = new Get_Trof_2(laberintoCompleto, trofeos, new ReturnCs(pInterface));
                    pInterface.SetPredicate(predicate);
                    pInterface.Call();
                    predicate = new Get_Inicio_2(laberintoCompleto, inicio, new ReturnCs(pInterface));
                    pInterface.SetPredicate(predicate);
                    pInterface.Call();
                    predicate = new Get_Final_2(laberintoCompleto, final, new ReturnCs(pInterface));
                    pInterface.SetPredicate(predicate);
                    pInterface.Call();
                    /* === FIN ASIGNACION === */

                    RepresentacionLaberinto = laberintoCompleto.Dereference();
                    Console.WriteLine(RepresentacionLaberinto.ToString());
                    Laberinto = new Laberinto((ListTerm)laberinto.Dereference(), (ListTerm)trofeos.Dereference(), ((IntegerTerm)inicio.Dereference()).IntValue(), ((IntegerTerm)final.Dereference()).IntValue(), dimensionX, dimensionY);
                }
            } while (!resultado);
        }
        /* FIN ATRIBUTOS */

        /* CONSTRUCTOR */

        public Laberinto(ListTerm laberinto, ListTerm trofeos, int inicio, int final, int dimX, int dimY)
        {
            this.laberinto = new List <int>();
            Trofeos        = new List <int>();

            ListTerm    aux = laberinto;
            IntegerTerm car = (IntegerTerm)aux.car.Dereference();

            this.Inicio = inicio;
            this.Final  = final;
            this.DimX   = dimX;
            this.DimY   = dimY;

            /* TRANSFORMANDO A LISTA */
            /* TRANSFORMANDO LABERINTO*/
            while (!aux.IsNil())
            {
                if (!aux.cdr.IsNil())
                {
                    aux = (ListTerm)aux.cdr.Dereference();
                }
                else
                {
                    lab.Add(car.IntValue());
                    break;
                }
                this.laberinto.Add(car.IntValue());
                car = (IntegerTerm)aux.car.Dereference();
            }

            /* TRANSFORMANDO TROFEOS */
            aux = trofeos;
            car = (IntegerTerm)aux.car.Dereference();

            while (!aux.IsNil())
            {
                if (!aux.cdr.IsNil())
                {
                    aux = (ListTerm)aux.cdr.Dereference();
                }
                else
                {
                    Trofeos.Add(car.IntValue());
                    break;
                }
                Trofeos.Add(car.IntValue());
                car = (IntegerTerm)aux.car.Dereference();
            }
        }