public IEnumerator <ListTerm> GetEnumerator() { do { yield return(ListTerm.ListFromArray(configuration)); }while (NextPermutation()); }
public void Unify_con_lis() { ConstantTerm con = new ConstantTerm("ali"); ListTerm term = new ListTerm(); Assert.IsFalse(con.Unify(term)); }
public Permutation(ListTerm t) { BaseTermSet ts = new BaseTermSet(t); ts.Sort(); configuration = ts.ToArray(); }
private void JsonArray(TerminalSet _TS, out BaseTerm t) { BaseTerm e; List <BaseTerm> listItems = new List <BaseTerm>(); GetSymbol(new TerminalSet(terminalCount, LSqBracket), true, true); GetSymbol(new TerminalSet(terminalCount, IntLiteral, RealLiteral, StringLiteral, LSqBracket, RSqBracket, LCuBracket, TrueSym, FalseSym, NullSym), false, true); if (symbol.IsMemberOf(IntLiteral, RealLiteral, StringLiteral, LSqBracket, LCuBracket, TrueSym, FalseSym, NullSym)) { while (true) { JsonValue(new TerminalSet(terminalCount, Comma, RSqBracket), out e); listItems.Add(e); GetSymbol(new TerminalSet(terminalCount, Comma, RSqBracket), false, true); if (symbol.TerminalId == Comma) { symbol.SetProcessed(); } else { break; } } } GetSymbol(new TerminalSet(terminalCount, RSqBracket), true, true); t = new CompoundTerm("array", ListTerm.ListFromArray(listItems.ToArray(), BaseTerm.EMPTYLIST)); }
public void Unify_str_lis() { StructureTerm s = new StructureTerm("s", 2); ListTerm l = new ListTerm(); Assert.IsFalse(s.Unify(l)); }
public Combination(ListTerm t, int k) { BaseTermSet ts = new BaseTermSet(t); this.k = k; iterator = CombinationsEnum(ts, k).GetEnumerator(); }
public BaseTerm Eval() // evaluate the term { BaseTerm t = ChainEnd(); if (!t.IsEvaluatable) { IO.Error("{0} cannot be evaluated by is/2", t); } if (t is ValueTerm) { return(t); // a ValueTerm stands for itself } if (t.IsProperList && !((ListTerm)t).IsEvaluated) // evaluate all members recursively { ListTerm result = ListTerm.EMPTYLIST; List <BaseTerm> tl = ((ListTerm)t).ToList(); for (int i = tl.Count - 1; i >= 0; i--) { result = new ListTerm(tl [i].Eval(), result); } result.IsEvaluated = true; return(result); } return(t.Apply()); }
public void Unify_lis_str() { ListTerm list = new ListTerm(); StructureTerm con = new StructureTerm("s", 2); Assert.IsFalse(list.Unify(con)); }
public void Unify_lis_con() { ListTerm list = new ListTerm(); ConstantTerm con = new ConstantTerm(); Assert.IsFalse(list.Unify(con)); }
// try to bind the range specification variable (if present) to the range list. // if the minimun or the maximum range length was a variable, then bind it to the actual length just found bool TryBindingRangeRelatedVars(ListPatternElem g, int rangeLength, ListTerm RangeList, VarStack varStack) { if (g.MinLenTerm.IsVar) { g.MinLenTerm.Unify(new DecimalTerm(rangeLength), varStack); } if (g.MaxLenTerm.IsVar) { g.MaxLenTerm.Unify(new DecimalTerm(rangeLength), varStack); } if (g.RangeBindVar != null) { if (RangeList == null) { RangeList = ListTerm.EMPTYLIST; } if (!g.RangeBindVar.Unify(RangeList, varStack)) { return(false); // alas, the same range var was apparently used & bound earlier in the pattern } } return(true); }
public override Predicate exec(Prolog engine) { engine.setB0(); Term a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13; Predicate p1, p2, p3; a1 = arg1.Dereference(); a2 = arg2.Dereference(); a3 = arg3.Dereference(); a4 = arg4.Dereference(); a5 = arg5.Dereference(); Term[] h2 = { engine.makeVariable() }; a6 = new StructureTerm(f1, h2); a7 = engine.makeVariable(); a8 = engine.makeVariable(); a13 = new ListTerm(a5, s3); a12 = new ListTerm(a4, a13); a11 = new ListTerm(a3, a12); a10 = new ListTerm(a2, a11); a9 = new ListTerm(a10, s3); p1 = new Predicates.Concatenar_Arreglos_3(a9, a8, a1, cont); p2 = new Predicates.Concatenar_Valor_3(a7, a2, a8, p1); p3 = new Predicates.GenerarCamino_4(a3, a2, s3, a7, p2); return(new Predicates.Retractall_1(a6, p3)); }
static void DoJsonArray0(JsonTextBuffer avb, string attrName, ListTerm t, bool first) { avb.AppendPossibleCommaAndNewLine(first); // is this entire []-last the first element? avb.EmitOpenBracket(attrName, '['); DoJsonArray(avb, t, true); avb.EmitCloseBracket(']'); }
public void IsReference() { ListTerm t = new ListTerm(); AbstractTerm a = new ListTerm(); Assert.IsFalse(t.IsReference); Assert.IsFalse(a.IsReference); }
public void IsObject() { ListTerm t = new ListTerm(); AbstractTerm a = new ListTerm(); Assert.IsFalse(t.IsObject); Assert.IsFalse(a.IsObject); }
public void IsList() { ListTerm t = new ListTerm(); AbstractTerm a = new ListTerm(); Assert.IsTrue(t.IsList); Assert.IsTrue(a.IsList); }
public void IsStructure() { ListTerm t = new ListTerm(); AbstractTerm a = new ListTerm(); Assert.IsFalse(t.IsStructure); Assert.IsFalse(a.IsStructure); }
public void IsConstant() { ListTerm t = new ListTerm(); AbstractTerm a = new ListTerm(); Assert.IsFalse(t.IsConstant); Assert.IsFalse(a.IsConstant); }
public void Bind() { ListTerm term = new ListTerm(); ListTerm term2 = new ListTerm(); term.Bind(term2); Assert.AreSame(term, term.Reference()); }
public void Reference() { ListTerm term1 = new ListTerm(); ListTerm term2 = new ListTerm(); term1.Bind(term2); Assert.AreSame(term1, term1.Reference()); }
public void Push_ListTerm() { AMHeap heap = new AMHeap(); ListTerm con = new ListTerm(); heap.Push(con); Assert.AreSame(con, heap.Top()); }
static void DoJsonArray(JsonTextBuffer avb, ListTerm t, bool first) { if (t.IsEmptyList) { return; } DoJsonValue(avb, null, t.Arg(0), first); DoJsonArray(avb, (ListTerm)t.Arg(1), false); }
public ListTerm ToList() { ListTerm t = ListTerm.EMPTYLIST; for (int i = Count - 1; i >= 0; i--) { t = new ListTerm(this [i], t); // [a0, a0, ...] } return(t); }
public void Unify_ref_lis() { AbstractTerm term = new AbstractTerm(); ListTerm con = new ListTerm(); Assert.IsTrue(term.Unify(con)); Assert.AreSame(term.Reference(), con.Reference()); Assert.IsTrue(term.IsList); Assert.IsFalse(term.IsReference); }
public ArrayVariable(string name, TermArray ta, ListTerm subscripts) { this.ta = ta; this.name = ta.Name; this.subscripts = subscripts.ArgumentsToArrayList(); if (this.subscripts.Count != ta.Rank) { IO.Error("Wrong number of subscripts for '{0}': expected {1}, got {2}", name, ta.Rank, this.subscripts.Count); } }
static BaseTerm() { EMPTYLIST = new ListTerm(); NULLCURL = new DcgTerm(); DBNULL = new AtomTerm("db_null"); VAR = new Variable(); verNoMax = 0; varNoMax = 0; NUMVAR = "'$VAR'"; CUT = new Cut(0); FAIL = new AtomTerm("fail"); trace = false; }
public override Predicate exec(Prolog engine) { engine.setB0(); Term a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21; Predicate p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16; a1 = arg1.Dereference(); a2 = arg2.Dereference(); a3 = arg3.Dereference(); a4 = arg4.Dereference(); a5 = arg5.Dereference(); a6 = engine.makeVariable(); a7 = engine.makeVariable(); a8 = engine.makeVariable(); a9 = engine.makeVariable(); a10 = engine.makeVariable(); Term[] h2 = { engine.makeVariable() }; a11 = new StructureTerm(f1, h2); a12 = engine.makeVariable(); Term[] h4 = { engine.makeVariable(), engine.makeVariable() }; a13 = new StructureTerm(f3, h4); Term[] h6 = { engine.makeVariable() }; a14 = new StructureTerm(f5, h6); a15 = engine.makeVariable(); a16 = engine.makeVariable(); Term[] h9 = { engine.makeVariable() }; a17 = new StructureTerm(f8, h9); a18 = engine.makeVariable(); a19 = engine.makeVariable(); a20 = new ListTerm(a12, s10); a21 = new ListTerm(a19, s10); p1 = new Predicates.dollar_cut_1(a6, cont); p2 = new Predicates.Verificar_Laberinto_1(a1, p1); p3 = new Predicates.Concatenar_Arreglos_3(a20, a21, a1, p2); p4 = new Predicates.ObtenerArregloTrofeos_1(a19, p3); p5 = new Predicates.CrearTrofeos_3(a12, a8, a18, p4); p6 = new Predicates.Calcular_Cant_Trofeos_3(a16, a4, a18, p5); p7 = new Predicates.Retractall_1(a17, p6); p8 = new Predicates.dollar_minus_3(a15, s7, a16, p7); p9 = new Predicates.Contar_2(a12, a15, p8); p10 = new Predicates.Retractall_1(a14, p9); p11 = new Predicates.Retractall_1(a13, p10); p12 = new Predicates.GenerarCamino_5(a12, a9, a10, a2, a3, p11); p13 = new Predicates.Retractall_1(a11, p12); p14 = new Predicates.CrearCamino_5(a2, a3, a7, a9, a10, p13); p15 = new Predicates.dollar_multi_3(a2, a3, a8, p14); p16 = new Predicates.Calcular_Cant_Muros_2(a2, a7, p15); return(new Predicates.dollar_getLevel_1(a6, p16)); }
public ListTerm ToList() { ListTerm result = ListTerm.EMPTYLIST; int lo = lowBound.To <int> (); int hi = hiBound.To <int> (); for (int i = hi; i >= lo; i--) { result = new ListTerm(new DecimalTerm(i), result); } return(result); }
public void Unify_lis_ref() { ListTerm list = new ListTerm(); list.Next = new ConstantTerm("ali"); list.Next.Next = new ConstantTerm("samir"); AbstractTerm term = new AbstractTerm(); Assert.IsTrue(list.Unify(term)); Assert.AreSame(list.Head, term.Head); Assert.AreSame(list.Tail, term.Tail); }
public void Unify_lis_ne_lis() { ListTerm list1 = new ListTerm(); list1.Next = new ConstantTerm("ali"); list1.Next.Next = new ConstantTerm("[]"); ListTerm list2 = new ListTerm(); list2.Next = new ConstantTerm("ali"); list2.Next.Next = new ConstantTerm("foo"); Assert.IsFalse(list1.Unify(list2)); }
public static string Format(ListTerm lt) { if (!lt.IsProperList || lt.ProperLength != 2) { IO.Error("Format list must be a proper list of length 2"); return(null); } BaseTerm fstring = lt.Arg(0); BaseTerm args = lt.Arg(1).Arg(0); return(Format(fstring, args)); }
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; }
/// <summary> /// Determines whether this object is equal to another object. /// </summary> /// <param name="other">The other object.</param> /// <returns><see langword="true"/> when the objects are equal; /// otherwise, <see langword="false"/>.</returns> private bool Equals(ListTerm other) { return base.Equals(other) && Object.Equals(this.Head, other.Head) && Object.Equals(this.Tail, other.Tail); }
public override Predicate exec( Prolog engine ) { Term a1, a2, a3, a4, a5, a6, a7, a8, a9; Predicate p1, p2, p3, p4, p5; a1 = engine.aregs[1].Dereference(); a2 = engine.aregs[2].Dereference(); a3 = engine.aregs[3].Dereference(); a4 = engine.aregs[4].Dereference(); a5 = engine.aregs[5].Dereference(); Predicate cont = engine.cont; if ( !s1.Unify(a4, engine.trail) ) return engine.fail(); if ( !s1.Unify(a5, engine.trail) ) return engine.fail(); a6 = engine.makeVariable(); a8 = engine.makeVariable(); a7 = new ListTerm(a8, engine.makeVariable()); Term[] h3 = {a1, a2, a3}; a9 = new StructureTerm(f2, h3); p1 = new Predicates.dollar_cut_1(a6, cont); p2 = new Predicates.Assert_1(a9, p1); p3 = new Predicates.Free_Line_3(a1, a2, a3, p2); p4 = new Predicates.dollar_dummyLogic__4_2(a3, a8, p3); p5 = new Predicates.Available_Indexs_1(a7, p4); return new Predicates.dollar_getLevel_1(a6, p5); }