var findWins = exports.findWins = function (player,board) { var valid = validMoves(board); var sofar = m.get(board,player); return m.set(m.filter(function (move) { return isWin(m.conj(sofar,move)); },valid)); };
// // The search algorithm (mostly) as presented in Figure 7-5 // function depthFirstSearch(initial, goal, _maxDepth) { var open = storage.stack([initial]) , closed = mori.set() , s = solution() , maxDepth = _maxDepth ? _maxDepth : 20 , explored = 1 ; if (initial.eq(goal)) { s = solution(goal, explored) } while (open.length() && s.solved() === false) { var n = open.pop(); closed = mori.conj(closed, n.toString()); n.moves(function(next) { explored += 1; if (closed.has(next.toString())) return; if (next.eq(goal)) s = solution(next, explored); if (next.depth() < maxDepth) open.push(next); }); } return s; }
it('should return valid HTML template for mori.set body', function() { assert.equal( toStr(Formatter.body(mori.set([1, 2, 3]))), '["ol",{"style":"list-style-type:none; padding-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-left: 12px"},["li",{},["span",{},["span",{"style":"color: rgb(136, 19, 145);"},"0: "],["object",{"object":1}]]],["li",{},["span",{},["span",{"style":"color: rgb(136, 19, 145);"},"1: "],["object",{"object":2}]]],["li",{},["span",{},["span",{"style":"color: rgb(136, 19, 145);"},"2: "],["object",{"object":3}]]]]'); });
it('should return valid HTML template for mori.set header', function() { assert.equal( toStr(Formatter.header(mori.set())), '["span",{},"Set"]'); });
var mori = require('mori'), styles = require('./styles'); var setC = mori.set().constructor; var mapC = mori.hashMap().constructor; function guard (object) { return !(mori.isVector(object) || mori.isMap(object) || mori.isSet(object) || mori.isList(object)); } function processChildren (parent, children, keyFn, valFn) { var i = 0; mori.each(children, function (child) { var li = parent.createChild('li'); var objectTag = li.createChild('span'); var nameSpan = objectTag.createChild('span'); keyFn(nameSpan, child, i); nameSpan.setStyle(styles.color); valFn(objectTag, child); i++; }); }
var mori = require('mori'); var mapa = mori.hashMap("key1", 100, "key2", "una cadena", "key3", true); var set = mori.set([1,2,3,4,5]); var vector = mori.vector("foo", "bar", "foobar"); //map, reduce var sequence = mori.map(function(item){ return item * 100; }, set); console.log('Map sobre set', sequence.toString()); var sumatorio = mori.reduce(function(acc, value){ return acc + value; }, 0, sequence); console.log('Reduce sobre seq', sumatorio); // indexOf function getIndexOf(vector, value){ return mori.reduceKV(function(acc, index, val){ console.log('Buscando ' + value + ' en ' + index,val); if(val === value){ return index; } else { return acc; } }, -1, vector); } console.log('ReduceKV sobre vector', getIndexOf(vector, 'foobar'));
var validMoves = exports.validMoves = function (board) { return m.set(m.filter(function(move){ return !m.has_key(m.get(board,X),move) && !m.has_key(m.get(board,O),move); },ALLMOVES)); };
var makeBoard = exports.makeBoard = function (Xs, Os) { return hashmap(X,m.set(Xs),O,m.set(Os)); };