Skip to content

Commit

Permalink
work to support from nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Feb 26, 2013
1 parent 6e151b1 commit 0068a69
Show file tree
Hide file tree
Showing 28 changed files with 2,357 additions and 334 deletions.
6 changes: 3 additions & 3 deletions examples/banking/scripts/nools.js
Original file line number Diff line number Diff line change
Expand Up @@ -14796,7 +14796,7 @@ var Node = declare({
},

assert: function (assertable) {
this.propagateAssert(assertable);
this.__propagate("assert", assertable);
},

propagateModify: function (assertable, outNodes) {
Expand Down Expand Up @@ -14828,7 +14828,7 @@ var TypeNode = AlphaNode.extend({

assert: function (fact) {
if (this.constraint.assert(fact.object)) {
this.propagateAssert({fact: fact});
this.__propagate("assert", {fact: fact});
}
},

Expand Down Expand Up @@ -15046,7 +15046,7 @@ var BridgeNode = Node.extend({
for (var i in variables) {
fh[i] = o[variables[i]];
}
this.propagateAssert({match: mr, fact: fact});
this.__propagate("assert", {match: mr, fact: fact});
},

retract: function (assertable) {
Expand Down
6 changes: 3 additions & 3 deletions examples/browser/manners.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
];


var seat = { seat: 16 };
var seat = { seat: 64 };
var start = { state: 'start' };

var flow = nools.getFlow("manners"),
Expand All @@ -322,8 +322,8 @@
Count = flow.getDefined("count"),
session = flow.getSession();

for (var i = 0, l = guests16.length; i < l; i++) {
session.assert(new Guest(guests16[i]));
for (var i = 0, l = guests64.length; i < l; i++) {
session.assert(new Guest(guests64[i]));
}
session.assert(new LastSeat(seat));
session.assert(new Context(start));
Expand Down
2 changes: 1 addition & 1 deletion examples/fibonacci.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Result = function (result) {

var flow = nools.flow("Fibonacci Flow", function (flow) {

flow.rule("Recurse", {priority: 1}, [
flow.rule("Recurse",[
["not", Fibonacci, "f", "f.sequence == 1"],
[Fibonacci, "f1", "f1.sequence != 1"]
], function (facts) {
Expand Down
1 change: 0 additions & 1 deletion examples/fibonacci.nools
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ define Result {
}

rule Recurse {
priority:1,
when {
//you can use not or or methods in here
not(f : Fibonacci f.sequence == 1);
Expand Down
82 changes: 82 additions & 0 deletions examples/sudoku/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var nools = require("../../index.js"),
sudoku = require("./lib/sudoku");

var flow = nools.compile(require.resolve("./lib/rules/sudoku.nools"), {
define: {
CellGroup: sudoku.CellGroup,
Cell: sudoku.Cell,
CellCol: sudoku.CellCol,
CellRow: sudoku.CellCol,
CellSqr: sudoku.CellSqr,
Counter: sudoku.Counter,
Setting: sudoku.Setting,
Stepping: sudoku.Stepping
},
scope: {
explain: true
}
});


var simple = [
[null, 5, 6, 8, null, 1, 9, 4, null],
[9, null, null, 6, null, 5, null, null, 3],
[7, null, null, 4, 9, 3, null, null, 8],
[8, 9, 7, null, 4, null, 6, 3, 5],
[null, null, 3, 9, null, 6, 8, null, null],
[4, 6, 5, null, 8, null, 2, 9, 1],
[5, null, null, 2, 6, 9, null, null, 7],
[6, null, null, 5, null, 4, null, null, 9],
[null, 4, 9, 7, null, 8, 3, 5, null]
];

var medium = [
[8, 4, 7, null, null, null, 2, 5, 6],
[5, null, null, null, 8, null, null, null, 4],
[2, null, null, null, 7, null, null, null, 8],
[null, null, null, 3, null, 8, null, null, null],
[null, 5, 1, null, null, null, 8, 7, 2],
[null, null, null, 5, null, 7, null, null, null],
[4, null, null, null, 5, null, null, null, 7],
[6, null, null, null, 3, null, null, null, 9],
[1, 3, 2, null, null, null, 4, 8, 5]
];

var hard1 = [
[null, null, null, null, 5, 1, null, 8, null],
[null, 8, null, null, 4, null, null, null, 5],
[null, null, 3, null, null, null, 2, null, null],
[null, null, null, null, 6, null, null, null, 9],
[6, 7, null, 4, null, 9, null, 1, 3],
[8, null, null, null, 3, null, null, null, null],
[null, null, 2, null, null, null, 4, null, null],
[5, null, null, null, 9, null, null, 2, null],
[null, 9, null, 7, 1, null, null, null, null]
];

var sud = new sudoku.Sudoku(flow);
var repl = require("repl");
sud.setCellValues(simple).then(function () {
var sudokuRepl = repl.start("sudoku>>");
sudokuRepl.context.print = sud.dumpGrid.bind(sud);
sudokuRepl.context.step = function () {
sud.step().classic(function (err) {
if (err) {
console.log(err.stack);
}
});
};
sudokuRepl.context.solve = function () {
sud.solve().classic(function (err) {
if (err) {
console.log(err.stack);
} else {
sud.dumpGrid();
}
});
};
});




0 comments on commit 0068a69

Please sign in to comment.