Ejemplo n.º 1
0
        // Direction = V
        // Direction = H
        public bool AddMove(int Index, int Position, Direction Direction, out string clo)
        {
            clo = "non";
            //closeLine(Index, Position, v, Ori).
            VariableTerm aClo = new VariableTerm();

            FPEngine.SetPredicate(new Close_Line_4(new IntegerTerm(Index), new IntegerTerm(Position), new IntegerTerm((int)Direction), aClo, new ReturnCs(FPEngine)));

            if (FPEngine.Call())
            {
                clo = (string)aClo.ToCsObject();
                FPEngine.Success();
            }

            Term[] argss = { new IntegerTerm(Index), new IntegerTerm(Position), new IntegerTerm((int)Direction) };

            StructureTerm newLine = new StructureTerm(SymbolTerm.MakeSymbol("line", 3), argss);

            FPEngine.SetPredicate(new Assert_1(newLine, new ReturnCs(FPEngine)));

            if (FPEngine.Call())
            {
                FPEngine.Success();
                return true;
            }
            else
                return false;
        }
Ejemplo n.º 2
0
        public string go(bool FirstRed, GameLevel RedPlayer, GameLevel YellowPlayer)
        {
            List<int> Indexes = GenerateArray(7);
            List<int> Positions = GenerateArray(6);

            #region Create Terms Indexes and Positions
            ListTerm lindexes = new ListTerm(new IntegerTerm(Indexes[0]),
            new ListTerm(new IntegerTerm(Indexes[1]),
                new ListTerm(new IntegerTerm(Indexes[2]),
                    new ListTerm(new IntegerTerm(Indexes[3]),
                        new ListTerm(new IntegerTerm(Indexes[4]),
                            new ListTerm(new IntegerTerm(Indexes[5]),
                                new ListTerm(new IntegerTerm(Indexes[6]), SymbolTerm.MakeSymbol("[]"))))))));

            ListTerm lpositions = new ListTerm(new IntegerTerm(Positions[0]),
            new ListTerm(new IntegerTerm(Positions[1]),
                new ListTerm(new IntegerTerm(Positions[2]),
                    new ListTerm(new IntegerTerm(Positions[3]),
                        new ListTerm(new IntegerTerm(Positions[4]),
                            new ListTerm(new IntegerTerm(Positions[5]), SymbolTerm.MakeSymbol("[]")))))));
            #endregion

            FPEngine.SetPredicate(new Deldb_0(new ReturnCs(FPEngine)));

            if (!FPEngine.Call())
            {
                aReturnString = "false";
                return aReturnString;
            }

            FPEngine.Success();
            StructureTerm a;
            Term[] args = { lpositions };
            a = new StructureTerm(SymbolTerm.MakeSymbol("availablePositions", 1), args);

            FPEngine.SetPredicate(new Assert_1(a, new ReturnCs(FPEngine)));

            if (FPEngine.Call())
            {
                FPEngine.Success();

                Term[] argss = { lindexes };
                a = new StructureTerm(SymbolTerm.MakeSymbol("availableIndexs", 1), argss);

                FPEngine.SetPredicate(new Assert_1(a, new ReturnCs(FPEngine)));

                if (FPEngine.Call())
                {
                    FPEngine.Success();
                    S();

                    VariableTerm Index = new VariableTerm();
                    VariableTerm Position = new VariableTerm();
                    VariableTerm Dir = new VariableTerm();
                    VariableTerm Team = new VariableTerm();
                    VariableTerm Orientation = new VariableTerm();
                    String aDirection;

                    if (FirstRed)
                        switch (RedPlayer)
                        {
                            case GameLevel.Easy:
                                FPEngine.SetPredicate(new Go_5(Index, Position, Dir, Team, Orientation, new ReturnCs(FPEngine)));
                                break;
                            case GameLevel.Normal:
                                FPEngine.SetPredicate(new GoSmart_5(Index, Position, Dir, Team, Orientation, new ReturnCs(FPEngine)));
                                break;
                            case GameLevel.Hard:
                                break;
                        }
                    else
                        switch (YellowPlayer)
                        {
                            case GameLevel.Easy:
                                FPEngine.SetPredicate(new Go_5(Index, Position, Dir, Team, Orientation, new ReturnCs(FPEngine)));
                                break;
                            case GameLevel.Normal:
                                FPEngine.SetPredicate(new GoSmart_5(Index, Position, Dir, Team, Orientation, new ReturnCs(FPEngine)));
                                break;
                            case GameLevel.Hard:
                                break;
                        }

                    if (!FPEngine.Call())
                    {
                        aReturnString = "false";

                        return aReturnString;
                    }

                    this.aIndex = (int)Index.ToCsObject();
                    this.aPosition = (int)Position.ToCsObject();

                    this.aDirection = (Direction)Dir.ToCsObject();
                    string or = (string)Orientation.ToCsObject();
                    if (or == "left")
                        this.Ori = Ori.left;
                    else if (or == "leftright")
                        this.Ori = Ori.leftright;
                    else if (or == "rightleft")
                        this.Ori = Ori.rightleft;
                    else if (or == "right")
                        this.Ori = Ori.right;
                    else if (or == "up")
                        this.Ori = Ori.up;
                    else if (or == "updown")
                        this.Ori = Ori.updown;
                    else if (or == "downup")
                        this.Ori = Ori.downup;
                    else if (or == "down")
                        this.Ori = Ori.down;
                    else if (or == "non")
                        this.Ori = Ori.non;

                    FPEngine.Success();
                    aReturnString = (string)Team.ToCsObject();
                    return aReturnString;
                }
            }
            aReturnString = "false";
            return aReturnString;
        }