diff --git a/src/games/hunt/decercarlaliebre-model.js b/src/games/hunt/decercarlaliebre-model.js index 2b4b484..31808e7 100644 --- a/src/games/hunt/decercarlaliebre-model.js +++ b/src/games/hunt/decercarlaliebre-model.js @@ -88,8 +88,15 @@ Model.Game.InitGame = function() { }); this.HuntMakeGrid({}); function Connect(pos0,pos1,dir0,dir1) { + var i; $this.g.Graph[pos0][dir0]=pos1; - $this.g.Graph[pos1][dir1]=pos0; + $this.g.Graph[pos1][dir1]=pos0; + for(i=0;ipos && this.g.Dist[pos1-1][pos]==-1) { @@ -120,13 +121,13 @@ Model.Game.HuntMakeDist=function() { var updated=true; for(var loop=1;updated;loop++) { updated=false; - for(var pos=1;pos0 && gpos==positions[0]) positions.shift(); else repl[gpos]=index++; } - for(var gpos=0;gpos0) str+="x"+capt; return str; -} +}; Model.Move.Equals = function(move) { - if(move==null) + var i; + if(move===null) return false; if(move.p.length!=this.p.length) return false; - for(var i=0;i-1) this.board[piece.p]=piece; @@ -285,27 +289,28 @@ Model.Board.CopyFrom = function(aBoard) { this.pieceCount=[aBoard.pieceCount[0],aBoard.pieceCount[1]]; this.lastMoves={ "1": [aBoard.lastMoves["1"][0],aBoard.lastMoves["1"][1],aBoard.lastMoves["1"][2]], - "-1": [aBoard.lastMoves["-1"][0],aBoard.lastMoves["-1"][1],aBoard.lastMoves["-1"][2]], - } + "-1": [aBoard.lastMoves["-1"][0],aBoard.lastMoves["-1"][1],aBoard.lastMoves["-1"][2]] + }; this.mWho=aBoard.mWho; this.zSign=aBoard.zSign; -} +}; Model.Board.HuntInitialPosition = function(aGame, pieces) { + var pos; this.board=[]; - for(var pos=0;pos=0)) { + if(pos2!==null && ($this.board[pos2]===null || poss.indexOf(pos2)>=0)) { var valid=true; var bidir=Math.floor(d/2); for(var i=0;i=0 && piece.s==this.mWho) { CatchPiece(piece.p,[piece.p],[],[]); } } - if(moves.length==0 || aGame.g.huntOptions.compulsaryCatch==false) { + if(moves.length===0 || aGame.g.huntOptions.compulsaryCatch===false) { moves=moves.concat(this.HuntGetCatcheeMoves(aGame)); } else if(aGame.g.huntOptions.catchLongestLine) { var longest=0, moves0=[]; - for(var i=0; i=0 && piece.s==this.mWho) { for(var d=0;d-1) @@ -461,19 +466,19 @@ Model.Board.HuntMakeEvalData=function(aGame) { evalData.catcheePiecesDock.push(piece); } return evalData; -} +}; Model.Board.HuntEvaluateFreeZone = function(aGame,evalData,evalMap) { + var i, pos, pos0, pos1, d; var catcherZone={}; var smallestZone=null; var smallestCatcherFreeZone=-1; - for(var i=0; i0) { - var pos; - for(var pos0 in unexplored) + for(pos0 in unexplored) if(unexplored.hasOwnProperty(pos0)) { pos=parseInt(pos0); unexploredCount--; @@ -483,9 +488,9 @@ Model.Board.HuntEvaluateFreeZone = function(aGame,evalData,evalMap) { freePoss[pos]=true; freePossCount++; catcherZone[pos]=true; - for(var d=0; dmaxDist) maxDist=d; if(d>maxDist0) maxDist0=d; } - //dist+=minDist dist+=maxDist; dist2+=maxDist*maxDist; } evalMap.distFree=[dist,0]; evalMap.distFree2=[dist2,0]; evalMap.maxDistFree=[maxDist0,0]; -} +}; Model.Board.HuntEvaluateOppositeDistFromCatcher = function(aGame,evalData,evalMap) { var allFarthest=[]; - for(var i=0; imaxDist) { maxDist=dist; farthest=[pos]; @@ -550,9 +545,10 @@ Model.Board.HuntEvaluateOppositeDistFromCatcher = function(aGame,evalData,evalMa } allFarthest=allFarthest.concat(farthest); } - var dist=0, dist2=0, dists=0; - for(var i=0; i1?1:0,0]; -} +}; Model.Board.HuntEvaluateRisk = function(aGame,evalData,evalMap) { + var pos, metric; var riskPoss={}, openPoss={}; var riskCount=0, openCount=0; function AddOpen(pos) { @@ -650,21 +647,21 @@ Model.Board.HuntEvaluateRisk = function(aGame,evalData,evalMap) { } for(var i=0; i=0) { pieces[piece.i]=piece; pieceCount++; @@ -751,16 +750,16 @@ Model.Board.HuntEvaluateCatcheeGroups = function(aGame,evalData,evalMap) { var groupCount=0; while(pieceCount>0) { groupCount++; - for(var i in pieces) + for(i in pieces) if(pieces.hasOwnProperty(i)) break; - var piece=pieces[i]; - delete pieces[i]; + piece=pieces[i]; + delete pieces[i]; var pieces0={}; pieces0[i]=piece; var pieceCount0=1; while(pieceCount0>0) { - for(var i in pieces0) + for(i in pieces0) if(pieces0.hasOwnProperty(i)) break; var piece0=pieces0[i]; @@ -771,7 +770,7 @@ Model.Board.HuntEvaluateCatcheeGroups = function(aGame,evalData,evalMap) { var graph=aGame.g.Graph[piece0.p]; for(var d=0;dmaxEmptyNoCatcherGroup) maxEmptyNoCatcherGroup=group.poss.length; emptyNoCatcherGroup+=group.poss.length; - } else if(group.touchCatcher==true) + } else if(group.touchCatcher===true) minEmptyCatcherGroup+=group.poss.length; } } @@ -860,20 +860,20 @@ Model.Board.HuntEvaluateGroups = function(aGame,evalData,evalMap) { evalMap.maxEmptyNoCatcherGroup=[0,maxEmptyNoCatcherGroup]; evalMap.emptyNoCatcherGroup=[0,emptyNoCatcherGroup]; evalMap.minEmptyCatcherGroup=[minEmptyCatcherGroup<0?0:minEmptyCatcherGroup,0]; -} +}; Model.Board.HuntGameEvaluate = function(aGame,evalData,evalMap) { return { pieceCount: [1,1] }; -} +}; Model.Board.QuickEvaluate = function(aGame) { this.Evaluate(aGame,false,true); return this.mEvaluation; -} - +}; Model.Board.Evaluate = function(aGame,aFinishOnly,aTopLevel) { + var f; var repeat=aGame.GetRepeatOccurence(this); if(repeat>2) { this.mFinished=true; @@ -897,13 +897,13 @@ Model.Board.Evaluate = function(aGame,aFinishOnly,aTopLevel) { this.pieceCount[evalData.catcherSide], this.pieceCount[evalData.catcheeSide], ] - } + }; var evalFactors=this.HuntGameEvaluate(aGame,evalData,evalMap); var debugEval=arguments[3]=="debug"; - for(var f in evalFactors) + for(f in evalFactors) if(evalFactors.hasOwnProperty(f)) { var factors=evalFactors[f]; var values=evalMap[f]; @@ -916,7 +916,7 @@ Model.Board.Evaluate = function(aGame,aFinishOnly,aTopLevel) { } if(debugEval) { - for(var f in evalMap) + for(f in evalMap) if(evalMap.hasOwnProperty(f)) { if(typeof evalFactors[f]=="undefined") JocLog("Unused",f+": ",evalMap[f][0],evalMap[f][1]); @@ -925,25 +925,25 @@ Model.Board.Evaluate = function(aGame,aFinishOnly,aTopLevel) { } this.mEvaluation*=aGame.g.catcher; this.mEvaluation-=aGame.g.evaluate0; - -} +}; Model.Board.HuntCheckBoard=function(aGame) { - for(var i=0; i 0) ? 90 : -90; }else{ a = 180*Math.atan(dy/dx) / Math.PI ; if(dx<0) a= (a+180)%360; } return a; -} +}; Model.Board.ApplyMove = function(aGame,aMove) { + var piece, i; if(aMove.p.length==1) { - for(var i=0;i