ensure no warning on jshint

This commit is contained in:
mig 2017-05-05 11:02:14 +02:00
parent 174f1f0b4f
commit 6c90a2376e
2 changed files with 197 additions and 189 deletions

View file

@ -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;
for(i=0;i<dir0;i++)
if(typeof $this.g.Graph[pos0][i]=="undefined")
$this.g.Graph[pos0][i] = null;
for(i=0;i<dir1;i++)
if(typeof $this.g.Graph[pos1][i]=="undefined")
$this.g.Graph[pos1][i] = null;
}
Connect(10,6,4,5);
Connect(6,2,4,5);

View file

@ -11,18 +11,18 @@ Model.Game.HuntInitGame = function() {
compulsoryCatch: false,
catchLongestLine: false,
multipleCatch: true,
}
};
this.g.huntEval={
pieceCount: 1000000,
freeZone: 100,
dist: 1000,
}
};
this.g.RC=[];
this.g.Graph=[];
this.g.useDrop=false;
this.g.evaluate0=0;
this.g.debugEval=false;
}
};
Model.Game.HuntPostInitGame = function() {
this.HuntMakeDist();
@ -37,7 +37,7 @@ Model.Game.HuntPostInitGame = function() {
}
});
}
};
Model.Game.HuntMakeGrid = function(options) {
var opts={
@ -46,21 +46,21 @@ Model.Game.HuntMakeGrid = function(options) {
row0: 0,
col0: 0,
dirs: 4,
}
};
Object.assign(opts,options);
var posByRC={};
var posByRC={},pos,r,c;
var base=this.g.RC.length;
for(var r=0;r<opts.rows;r++)
for(var c=0;c<opts.cols;c++) {
var pos=base+r*opts.cols+c;
for(r=0;r<opts.rows;r++)
for(c=0;c<opts.cols;c++) {
pos=base+r*opts.cols+c;
this.g.RC[pos]=[r+opts.row0,c+opts.col0];
posByRC[""+r+","+c]=pos;
}
for(var pos=0;pos<this.g.RC.length;pos++) {
var r=this.g.RC[pos][0];
var c=this.g.RC[pos][1];
for(pos=0;pos<this.g.RC.length;pos++) {
r=this.g.RC[pos][0];
c=this.g.RC[pos][1];
var graph=[];
var pos1=posByRC[""+(r-1)+","+c];
if(typeof pos1 != "undefined")
@ -86,10 +86,11 @@ Model.Game.HuntMakeGrid = function(options) {
graph.push(null);
this.g.Graph.push(graph);
}
}
};
Model.Game.HuntMakeDist=function() {
var $this=this;
var pos, pos1, pos2, graph,d;
this.g.Dist=[];
this.g.DistMax=0;
function SetDist(a,b,c) {
@ -98,17 +99,17 @@ Model.Game.HuntMakeDist=function() {
$this.g.DistMax=c;
}
for(var i=0;i<this.g.Graph.length;i++) {
var distLine=[]
var distLine=[];
for(var j=0;j<=i;j++) {
distLine.push(-1);
}
this.g.Dist.push(distLine);
}
for(var pos=0;pos<this.g.Graph.length;pos++) {
var graph=this.g.Graph[pos];
for(var d=0;d<graph.length;d++) {
var pos1=graph[d];
if(pos1!=null) {
for(pos=0;pos<this.g.Graph.length;pos++) {
graph=this.g.Graph[pos];
for(d=0;d<graph.length;d++) {
pos1=graph[d];
if(pos1!==null) {
if(pos1<pos && this.g.Dist[pos-1][pos1]==-1) {
SetDist(pos-1,pos1,1);
} else if(pos1>pos && 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;pos<this.g.Graph.length;pos++) {
for(var pos1=0;pos1<pos;pos1++) {
for(pos=1;pos<this.g.Graph.length;pos++) {
for(pos1=0;pos1<pos;pos1++) {
if(this.g.Dist[pos-1][pos1]==loop) {
var graph=this.g.Graph[pos1];
for(var d=0;d<graph.length;d++) {
var pos2=graph[d];
if(pos2!=null) {
graph=this.g.Graph[pos1];
for(d=0;d<graph.length;d++) {
pos2=graph[d];
if(pos2!==null) {
if(pos2<pos && this.g.Dist[pos-1][pos2]==-1) {
SetDist(pos-1,pos2,loop+1);
updated=true;
@ -137,9 +138,9 @@ Model.Game.HuntMakeDist=function() {
}
}
graph=this.g.Graph[pos];
for(var d=0;d<graph.length;d++) {
var pos2=graph[d];
if(pos2!=null) {
for(d=0;d<graph.length;d++) {
pos2=graph[d];
if(pos2!==null) {
if(pos2<pos1 && this.g.Dist[pos1-1][pos2]==-1) {
SetDist(pos1-1,pos2,loop+1);
updated=true;
@ -153,21 +154,22 @@ Model.Game.HuntMakeDist=function() {
}
}
}
}
};
Model.Game.HuntRemovePositions=function(positions) {
var repl={}
var gpos;
var repl={};
var index=0;
positions.sort(function(a,b) {
return a-b;
});
for(var gpos=0;gpos<this.g.Graph.length;gpos++) {
for(gpos=0;gpos<this.g.Graph.length;gpos++) {
if(positions.length>0 && gpos==positions[0])
positions.shift();
else
repl[gpos]=index++;
}
for(var gpos=0;gpos<this.g.Graph.length;gpos++) {
for(gpos=0;gpos<this.g.Graph.length;gpos++) {
if(typeof repl[gpos]=="undefined") {
this.g.Graph[gpos]="X";
continue;
@ -176,7 +178,7 @@ Model.Game.HuntRemovePositions=function(positions) {
var graph1=[];
for(var d=0;d<graph.length;d++) {
var npos=graph[d];
if(npos!=null && typeof repl[npos]!="undefined")
if(npos!==null && typeof repl[npos]!="undefined")
graph1.push(repl[npos]);
else
graph1.push(null);
@ -185,7 +187,7 @@ Model.Game.HuntRemovePositions=function(positions) {
}
var graph0=[];
var rc0=[];
for(var gpos=0;gpos<this.g.Graph.length;gpos++)
for(gpos=0;gpos<this.g.Graph.length;gpos++)
if(typeof repl[gpos]!="undefined") {
graph0.push(this.g.Graph[gpos]);
rc0.push(this.g.RC[gpos]);
@ -193,7 +195,7 @@ Model.Game.HuntRemovePositions=function(positions) {
this.g.Graph=graph0;
this.g.RC=rc0;
this.g.PosName={};
}
};
Model.Game.HuntDist=function(pos0,pos1) {
if(pos0==pos1)
@ -204,12 +206,12 @@ Model.Game.HuntDist=function(pos0,pos1) {
pos1=tmp;
}
return this.g.Dist[pos0-1][pos1];
}
};
Model.Move.Init = function(args) {
if(typeof args !="undefined")
this.CopyFrom(args);
}
};
Model.Move.PosName={};
@ -235,40 +237,42 @@ Model.Move.ToString = function() {
if(capt.length>0)
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<this.p.length;i++)
for(i=0;i<this.p.length;i++)
if(move.p[i]!=this.p[i])
return false;
if(move.c===undefined && this.c===undefined)
return true;
if(move.c!==undefined && this.c!==undefined) {
for(var i=0;i<this.c.length;i++)
for(i=0;i<this.c.length;i++)
if(move.c[i]!=this.c[i])
return false;
return true;
}
return false;
}
};
Model.Board.InitialPosition = function(aGame) {
this.HuntInitialPosition(aGame,aGame.g.initialPos);
//this.Evaluate(aGame,false,true);
//aGame.g.evaluate0=this.mEvaluation+1000000*aGame.g.catcher;
this.zSign=aGame.zobrist.update(0,"who",-1);
}
};
Model.Board.CopyFrom = function(aBoard) {
var i;
this.board=[];
for(var i=0;i<aBoard.board.length;i++)
for(i=0;i<aBoard.board.length;i++)
this.board.push(null);
this.pieces=[];
for(var i=0;i<aBoard.pieces.length;i++) {
for(i=0;i<aBoard.pieces.length;i++) {
var piece0=aBoard.pieces[i];
var piece={
p: piece0.p,
@ -276,8 +280,8 @@ Model.Board.CopyFrom = function(aBoard) {
i: piece0.i,
a: piece0.a,
pv: piece0.pv,
pv2: piece0.pv2,
}
pv2: piece0.pv2
};
this.pieces.push(piece);
if(piece.p>-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<aGame.g.Graph.length;pos++)
for(pos=0;pos<aGame.g.Graph.length;pos++)
this.board.push(null);
this.pieces=[];
this.pieceCount=[0,0];
for(var who=0;who<2;who++) {
for(var i=0;i<pieces[who].length;i++) {
var pos=pieces[who][i];
pos=pieces[who][i];
var piece={
p: pos, // position on the board or -1 if out
s: 1-(who*2), // 1 = Player A or -1 = player B
i: this.pieces.length, // piece index
a: 0, // piece angle
}
a: 0 // piece angle
};
this.board[pos]=piece;
this.zSign=aGame.zobrist.update(this.zSign,"board",1-(who*2),pos);
this.pieces.push(piece);
@ -315,36 +320,36 @@ Model.Board.HuntInitialPosition = function(aGame, pieces) {
this.lastMoves={
"1": [null,null,null],
"-1": [null,null,null],
}
}
};
};
Model.Board.GenerateMoves = function(aGame) {
this.mMoves = [];
if(aGame.g.useDrop) {
this.mMoves=this.HuntGetAllDropMoves(aGame);
}
if(this.mMoves.length==0) {
if(this.mMoves.length===0) {
this.mMoves=this.HuntGetAllMoves(aGame);
if(this.mMoves.length==0) {
if(this.mMoves.length===0) {
this.mFinished=true;
this.mWinner=-this.mWho;
}
}
}
};
Model.Board.HuntGetCatcherMoves = function(aGame) {
var $this=this;
var $this=this, i;
var moves=[];
function CatchPiece(pos,poss,caught,caughtBidir) {
var gotMoves=false;
for(var d=0;d<aGame.g.Graph[pos].length;d++) {
var pos1=aGame.g.Graph[pos][d];
if(pos1!=null) {
if(pos1!==null) {
var piece1=$this.board[pos1];
if(piece1!=null && piece1.s==-$this.mWho) {
if(piece1!==null && piece1.s==-$this.mWho) {
var pos2=aGame.g.Graph[pos1][d];
if(pos2!=null && ($this.board[pos2]==null || poss.indexOf(pos2)>=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<caught.length;i++)
@ -355,12 +360,12 @@ Model.Board.HuntGetCatcherMoves = function(aGame) {
if(valid) {
var poss0=poss.concat([pos2]);
var caught0=caught.concat([pos1]);
if(aGame.g.huntOptions.multipleCatch==false) {
if(aGame.g.huntOptions.multipleCatch===false) {
moves.push({p:poss0,c:caught0});
gotMoves=true;
} else {
var gotMoves0=CatchPiece(pos2,poss0,caught0,caughtBidir.concat([bidir]));
if(gotMoves0==false || aGame.g.huntOptions.compulsaryCatch==false) {
if(gotMoves0===false || aGame.g.huntOptions.compulsaryCatch===false) {
moves.push({p:poss0,c:caught0});
gotMoves=true;
}
@ -373,18 +378,18 @@ Model.Board.HuntGetCatcherMoves = function(aGame) {
return gotMoves;
}
for(var i=0;i<this.pieces.length;i++) {
for(i=0;i<this.pieces.length;i++) {
var piece=this.pieces[i];
if(piece.p>=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<moves.length; i++) {
for(i=0; i<moves.length; i++) {
if(longest<moves[i].c.length) {
longest=moves[i].c.length;
moves0=[moves[i]];
@ -394,7 +399,7 @@ Model.Board.HuntGetCatcherMoves = function(aGame) {
moves=moves0;
}
return moves;
}
};
Model.Board.HuntGetCatcheeMoves = function(aGame) {
var moves=[];
@ -403,20 +408,20 @@ Model.Board.HuntGetCatcheeMoves = function(aGame) {
if(piece.p>=0 && piece.s==this.mWho) {
for(var d=0;d<aGame.g.Graph[piece.p].length;d++) {
var pos=aGame.g.Graph[piece.p][d];
if(pos!=null && this.board[pos]==null)
if(pos!==null && this.board[pos]===null)
moves.push({p:[piece.p,pos]});
}
}
}
return moves;
}
};
Model.Board.HuntGetAllMoves = function(aGame) {
if(this.mWho==aGame.g.catcher)
return this.HuntGetCatcherMoves(aGame);
else
return this.HuntGetCatcheeMoves(aGame);
}
};
Model.Board.HuntGetAllDropMoves = function(aGame) {
var moves=[];
@ -425,16 +430,16 @@ Model.Board.HuntGetAllDropMoves = function(aGame) {
var piece=this.pieces[i];
if(piece.p==-2 && piece.s==this.mWho) {
dockPiece=piece;
break
break;
}
}
if(dockPiece) {
for(var pos=0;pos<this.board.length;pos++)
if(this.board[pos]==null)
if(this.board[pos]===null)
moves.push({p:[pos]});
}
return moves;
}
};
Model.Board.HuntMakeEvalData=function(aGame) {
var evalData={
@ -446,7 +451,7 @@ Model.Board.HuntMakeEvalData=function(aGame) {
catcheePieces: [],
catcherPiecesDock: [],
catcheePiecesDock: [],
}
};
for(var i=0;i<this.pieces.length;i++) {
var piece=this.pieces[i];
if(piece.p>-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; i<evalData.catcherPieces.length; i++) {
for(i=0; i<evalData.catcherPieces.length; i++) {
var catcherPiece=evalData.catcherPieces[i];
var freePoss={},freePossCount=0,unexplored={},unexploredCount=1;
unexplored[catcherPiece.p]=true;
while(unexploredCount>0) {
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; d<aGame.g.Graph[pos].length; d++) {
var pos1=aGame.g.Graph[pos][d];
if(pos1!=null && this.board[pos1]==null && !freePoss[pos1] && !unexplored[pos1]) {
for(d=0; d<aGame.g.Graph[pos].length; d++) {
pos1=aGame.g.Graph[pos][d];
if(pos1!==null && this.board[pos1]===null && !freePoss[pos1] && !unexplored[pos1]) {
unexplored[pos1]=true;
unexploredCount++;
}
@ -504,44 +509,34 @@ Model.Board.HuntEvaluateFreeZone = function(aGame,evalData,evalMap) {
var dist=0;
var dist2=0;
var maxDist0=0;
if(!Array.isArray(evalData.catcheePieces))
debugger;
for(var i=0; i<evalData.catcheePieces.length; i++) {
for(i=0; i<evalData.catcheePieces.length; i++) {
var piece=evalData.catcheePieces[i];
//var minDist=Infinity;
var maxDist=0;
// !!!!!!!!! using freePoss ????
for(var pos in freePoss)
if(freePoss.hasOwnProperty(pos)) {
var d=aGame.HuntDist(pos,piece.p);
/*
if(d<minDist)
minDist=d;
if(d==1)
break;
*/
for(pos in smallestZone)
if(smallestZone.hasOwnProperty(pos)) {
d=aGame.HuntDist(pos,piece.p);
if(d>maxDist)
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; i<evalData.catcherPieces.length; i++) {
var piece=evalData.catcherPieces[i];
var dist,i,piece;
for(i=0; i<evalData.catcherPieces.length; i++) {
piece=evalData.catcherPieces[i];
var farthest=[];
var maxDist=0;
for(var pos=0;pos<aGame.g.Graph.length;pos++) {
var dist=aGame.HuntDist(pos,piece.p);
dist=aGame.HuntDist(pos,piece.p);
if(dist>maxDist) {
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; i<evalData.catcheePieces.length; i++) {
var piece=evalData.catcheePieces[i];
dist=0;
var dist2=0, dists=0;
for(i=0; i<evalData.catcheePieces.length; i++) {
piece=evalData.catcheePieces[i];
var d=0,d2=0,ds=0;
for(var j=0;j<allFarthest.length;j++) {
d0=aGame.HuntDist(allFarthest[j],piece.p);
@ -560,14 +556,14 @@ Model.Board.HuntEvaluateOppositeDistFromCatcher = function(aGame,evalData,evalMa
d2+=d0*d0;
ds+=Math.sqrt(d);
}
dist+=d/farthest.length;
dist2+=d2/farthest.length;
dists+=ds/farthest.length;
dist+=d/allFarthest.length;
dist2+=d2/allFarthest.length;
dists+=ds/allFarthest.length;
}
evalMap.oppDist=[-dist,0];
evalMap.oppDist2=[-dist2,0];
evalMap.oppDists=[-dists,0];
}
};
Model.Board.HuntEvaluateDistToCatcher = function(aGame,evalData,evalMap) {
var dist=0, dist2=0, dist3=0;
@ -594,7 +590,7 @@ Model.Board.HuntEvaluateDistToCatcher = function(aGame,evalData,evalMap) {
evalMap.dist2=[dist2,0];
evalMap.dist=[dist,0];
evalMap.maxDist=[maxDist,0];
}
};
Model.Board.HuntEvaluateCatchable = function(aGame,evalData,evalMap) {
var catchablePieces=0, catchableDir=0, catchableDangerPieces=0;
@ -603,16 +599,16 @@ Model.Board.HuntEvaluateCatchable = function(aGame,evalData,evalMap) {
var pos=catcheePiece.p;
var catchable=false;
var catchDanger=false;
var graph=aGame.g.Graph[pos]
var graph=aGame.g.Graph[pos];
for(var d=0;d<graph.length;d+=2) {
var pos1=graph[d];
var pos2=graph[d+1];
if(pos1!=null && pos2!=null) {
if(this.board[pos1]==null && this.board[pos2]==null) {
if(pos1!==null && pos2!==null) {
if(this.board[pos1]===null && this.board[pos2]===null) {
catchableDir++;
catchable=true;
} else if((this.board[pos1]==null && this.board[pos2].s==aGame.g.catcher) ||
(this.board[pos2]==null && this.board[pos1].s==aGame.g.catcher)) {
} else if((this.board[pos1]===null && this.board[pos2].s==aGame.g.catcher) ||
(this.board[pos2]===null && this.board[pos1].s==aGame.g.catcher)) {
catchableDir++;
catchDanger=true;
catchable=true;
@ -628,9 +624,10 @@ Model.Board.HuntEvaluateCatchable = function(aGame,evalData,evalMap) {
evalMap.catchableDir=[catchableDir,0];
evalMap.catchableDir2=[catchableDir*catchableDir,0];
evalMap.catchDangerFork=[catchableDangerPieces>1?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<evalData.catcheePieces.length; i++) {
var piece=evalData.catcheePieces[i];
var pos=piece.p;
pos=piece.p;
var graph=aGame.g.Graph[pos];
for(var d=0;d<graph.length;d+=2) {
var pos1=graph[d];
var pos2=graph[d+1];
if(pos1!=null && pos2!=null) {
if(pos1!==null && pos2!==null && pos2!==undefined) {
var piece1=this.board[pos1];
var piece2=this.board[pos2];
if(piece1==null && piece2==null) {
if(piece1===null && piece2===null) {
AddOpen(pos1);
AddOpen(pos2);
} else if(piece1!=null && piece1.s==aGame.g.catcher && piece2==null) {
} else if(piece1!==null && piece1.s==aGame.g.catcher && piece2===null) {
AddOpen(pos1);
AddRisky(pos2);
} else if(piece2!=null && piece2.s==aGame.g.catcher && piece1==null) {
} else if(piece2!==null && piece2.s==aGame.g.catcher && piece1===null) {
AddRisky(pos1);
AddOpen(pos2);
}
@ -672,31 +669,32 @@ Model.Board.HuntEvaluateRisk = function(aGame,evalData,evalMap) {
}
}
var openMetric=0;
for(var pos in openPoss)
for(pos in openPoss)
if(openPoss.hasOwnProperty(pos)) {
var metric=openPoss[pos];
metric=openPoss[pos];
openMetric+=metric*metric;
}
var riskMetric=0;
for(var pos in riskPoss)
for(pos in riskPoss)
if(riskPoss.hasOwnProperty(pos)) {
var metric=riskPoss[pos];
metric=riskPoss[pos];
riskMetric+=metric*metric;
}
evalMap.openRisk=[openMetric,0];
evalMap.forkRisk=[riskMetric,0];
}
};
Model.Board.HuntEvaluateAntiBack = function(aGame,evalData,evalMap) {
var i, piece;
var catcherPrev=0, catcheePrev=0, catcherPiecePrev=0, catcheePiecePrev=0;
for(var i=0; i<evalData.catcheePieces.length; i++) {
var piece=evalData.catcheePieces[i];
for(i=0; i<evalData.catcheePieces.length; i++) {
piece=evalData.catcheePieces[i];
if(piece.p==piece.pv2)
catcheePiecePrev++;
}
for(var i=0; i<evalData.catcherPieces.length; i++) {
var piece=evalData.catcherPieces[i];
for(i=0; i<evalData.catcherPieces.length; i++) {
piece=evalData.catcherPieces[i];
if(piece.p==piece.pv2)
catcherPiecePrev++;
}
@ -704,7 +702,7 @@ Model.Board.HuntEvaluateAntiBack = function(aGame,evalData,evalMap) {
var last=this.lastMoves[who];
// if(last[0]!=null && last[1]!=null && typeof last[0].c=="undefined" && typeof last[1].c=="undefined" &&
// last[0].p.length==2 && last[1].p.length==2 && last[0].p[0]==last[1].p[1] && last[1].p[0]==last[0].p[1])
if(last[0]!=null && last[0].Equals(last[2]))
if(last[0]!==null && last[0].Equals(last[2]))
if(aGame.g.catcher==who)
catcherPrev++;
else
@ -712,7 +710,7 @@ Model.Board.HuntEvaluateAntiBack = function(aGame,evalData,evalMap) {
}
evalMap.antiBack=[catcheePrev,catcherPrev];
evalMap.antiBackPiece=[catcheePiecePrev,catcherPiecePrev];
}
};
Model.Board.HuntEvaluateCatcheeConnections = function(aGame,evalData,evalMap) {
var conn=0;
@ -724,7 +722,7 @@ Model.Board.HuntEvaluateCatcheeConnections = function(aGame,evalData,evalMap) {
var graph=aGame.g.Graph[piece.p];
for(var d=0;d<graph.length;d++) {
var pos1=graph[d];
if(pos1!=null) {
if(pos1!==null) {
var piece1=this.board[pos1];
if(piece1 && piece1.s==piece.s)
pieceConn++;
@ -736,13 +734,14 @@ Model.Board.HuntEvaluateCatcheeConnections = function(aGame,evalData,evalMap) {
}
evalMap.catcheeConn=[0,conn];
evalMap.catcheeConnLog=[0,connLog];
}
};
Model.Board.HuntEvaluateCatcheeGroups = function(aGame,evalData,evalMap) {
var pieces={}
var i, piece;
var pieces={};
var pieceCount=0;
for(var i=0;i<this.pieces.length;i++) {
var piece=this.pieces[i];
for(i=0;i<this.pieces.length;i++) {
piece=this.pieces[i];
if(piece.s==-aGame.g.catcher && piece.p>=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];
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;d<graph.length;d++) {
var pos1=graph[d];
if(pos1!=null) {
if(pos1!==null) {
var piece1=this.board[pos1];
if(piece1 && (piece1.i in pieces) && !(piece1.i in pieces0)) {
pieces0[piece1.i]=piece1;
@ -782,35 +781,36 @@ Model.Board.HuntEvaluateCatcheeGroups = function(aGame,evalData,evalMap) {
}
}
evalMap.catcheeGroups=[groupCount,0];
}
};
Model.Board.HuntEvaluateGroups = function(aGame,evalData,evalMap) {
var i, piece, d, pos1, group;
var groups={};
var groupPos={};
var groupIndex=0;
for(var pos=0;pos<aGame.g.Graph.length;pos++) {
if(typeof groupPos[pos]=="undefined") {
var piece=this.board[pos];
piece=this.board[pos];
var currentGroup=null;
var graph=aGame.g.Graph[pos];
for(var d=0;d<graph.length;d++) {
var pos1=graph[d];
if(pos1!=null) {
for(d=0;d<graph.length;d++) {
pos1=graph[d];
if(pos1!==null) {
var piece1=this.board[pos1];
if((piece==null && piece1==null) ||
(piece!=null && piece1!=null && piece.s==piece1.s)) {
if((piece===null && piece1===null) ||
(piece!==null && piece1!==null && piece.s==piece1.s)) {
if(typeof groupPos[pos1]!="undefined") {
var groupPos1=groupPos[pos1];
if(currentGroup==null) {
if(currentGroup===null) {
groupPos[pos]=groupPos1;
groups[groupPos1].poss.push(pos);
currentGroup=groupPos1;
} else if(currentGroup!=groupPos1) {
// Merge groups
var group=groups[currentGroup];
group=groups[currentGroup];
var group1=groups[groupPos1];
group.poss=group.poss.concat(group1.poss);
for(var i=0; i<group1.poss.length; i++)
for(i=0; i<group1.poss.length; i++)
groupPos[group1.poss[i]]=currentGroup;
delete groups[groupPos1];
}
@ -818,21 +818,21 @@ Model.Board.HuntEvaluateGroups = function(aGame,evalData,evalMap) {
}
}
}
if(currentGroup==null) {
if(currentGroup===null) {
groups[groupIndex]={
type: piece==null?0:piece.s,
type: piece===null?0:piece.s,
poss: [pos],
touchCatcher: false,
}
};
groupPos[pos]=groupIndex++;
}
}
}
for(var i=0; i<evalData.catcherPieces.length; i++) {
var piece=evalData.catcherPieces[i];
for(var d=0;d<graph.length;d++) {
var pos1=aGame.g.Graph[piece.p][d];
if(pos1!=null) {
for(i=0; i<evalData.catcherPieces.length; i++) {
piece=evalData.catcherPieces[i];
for(d=0;d<aGame.g.Graph[piece.p].length;d++) {
pos1=aGame.g.Graph[piece.p][d];
if(pos1!==null) {
groups[groupPos[pos1]].touchCatcher=true;
}
}
@ -844,15 +844,15 @@ Model.Board.HuntEvaluateGroups = function(aGame,evalData,evalMap) {
var minEmptyCatcherGroup=0;
for(var g in groups)
if(groups.hasOwnProperty(g)) {
var group=groups[g];
group=groups[g];
if(group.type==-aGame.g.catcher)
catcheeGroups++;
else if(group.type==0) {
if(group.touchCatcher==false) {
else if(group.type===0) {
if(group.touchCatcher===false) {
if(group.poss.length>maxEmptyNoCatcherGroup)
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<aGame.g.Graph.length; i++) {
var i, piece;
for(i=0; i<aGame.g.Graph.length; i++) {
var pos=aGame.g.Graph[i];
var piece=this.board[pos];
if(piece!=null) {
piece=this.board[pos];
if(piece!==null) {
if(piece.p!=pos)
return "Piece "+piece+i+" has p "+piece.p+" while on board pos "+pos;
}
}
for(var i=0; i<this.pieces.length; i++) {
var piece=this.pieces[i];
for(i=0; i<this.pieces.length; i++) {
piece=this.pieces[i];
if(piece.p!=-1 && this.board[piece.p]!=piece)
return "Piece "+i+" not on board "+piece.p;
}
return null;
}
};
Model.Board.HuntAngle = function(aGame,pos0,pos) {
var rc0=aGame.g.RC[pos0];
@ -974,19 +974,20 @@ Model.Board.HuntAngle = function(aGame,pos0,pos) {
var a = 0;
var dx=r-r0;
var dy=c-c0;
if (dx==0){
if (dx===0){
a = (dy > 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<this.pieces.length;i++) {
var piece=this.pieces[i];
for(i=0;i<this.pieces.length;i++) {
piece=this.pieces[i];
if(piece.s==this.mWho && piece.p==-2) {
piece.p=aMove.p[0];
piece.a=0;
@ -996,7 +997,7 @@ Model.Board.ApplyMove = function(aGame,aMove) {
}
}
} else {
var piece=this.board[aMove.p[0]];
piece=this.board[aMove.p[0]];
this.zSign=aGame.zobrist.update(this.zSign,"board",piece.s,piece.p);
this.board[aMove.p[0]]=null;
this.board[aMove.p[aMove.p.length-1]]=piece;
@ -1007,9 +1008,9 @@ Model.Board.ApplyMove = function(aGame,aMove) {
this.zSign=aGame.zobrist.update(this.zSign,"board",piece.s,piece.p);
if(aMove.c!==undefined) {
var side=this.mWho==JocGame.PLAYER_A?0:1;
for(var i=0;i<aMove.c.length;i++) {
for(i=0;i<aMove.c.length;i++) {
piece=this.board[aMove.c[i]];
if(piece!=null) {
if(piece!==null) {
this.board[aMove.c[i]]=null;
this.zSign=aGame.zobrist.update(this.zSign,"board",piece.s,piece.p);
piece.p=-1;
@ -1023,8 +1024,8 @@ Model.Board.ApplyMove = function(aGame,aMove) {
this.lastMoves[this.mWho][0]=new (aGame.GetMoveClass())(aMove);
this.zSign=aGame.zobrist.update(this.zSign,"who",-this.mWho);
this.zSign=aGame.zobrist.update(this.zSign,"who",this.mWho);
}
};
Model.Board.GetSignature = function() {
return this.zSign;
}
};