From 9d3c8c0e6e1a7ba43bf3dc19350d1dca68b657a3 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 10 Feb 2019 11:16:07 +0800 Subject: Initial commit. --- SameGameJS/index.html | 144 ++++++++++++++++++++++ SameGameJS/samegame.js | 326 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 470 insertions(+) create mode 100644 SameGameJS/index.html create mode 100755 SameGameJS/samegame.js (limited to 'SameGameJS') diff --git a/SameGameJS/index.html b/SameGameJS/index.html new file mode 100644 index 0000000..ced352d --- /dev/null +++ b/SameGameJS/index.html @@ -0,0 +1,144 @@ + + + + +Chrisoft::Same Game + + + + + + + + + + + +
+ Chrisoft::Same Game +
+
+ Board size: + +    + Number of colours: + +    + Seed: + + + +
+ Score: +    + Optimal score by greedy strategy: +    + Seed: +
+
+
Game over! Score:
+
+
+ +
+ +
+ + diff --git a/SameGameJS/samegame.js b/SameGameJS/samegame.js new file mode 100755 index 0000000..6bac624 --- /dev/null +++ b/SameGameJS/samegame.js @@ -0,0 +1,326 @@ +var dimpx,dim,cc; +var seed,cscore; +var board=null; +var boarde=null; +var dx=[0,1,0,-1]; +var dy=[-1,0,1,0]; +var pendingrem=[]; +var sol=[]; +var optscore; +var ismobile; +String.prototype.getHash=function() +{ + var ret=0,ch; + if(this.length===0)return ret; + for(var i=0;i>>=0; + } + return ret; +} +function randomInt(min,max) +{ + seed*=214013;seed+=2531011;seed&=0xffffffff; + return min+(seed^seed>>15)%(max-min+1); +} + +function init() +{ + if( navigator.userAgent.match(/Android/i) + || navigator.userAgent.match(/webOS/i) + || navigator.userAgent.match(/iPhone/i) + || navigator.userAgent.match(/iPad/i) + || navigator.userAgent.match(/iPod/i) + || navigator.userAgent.match(/BlackBerry/i) + || navigator.userAgent.match(/Windows Phone/i) + ) + ismobile=true; + dimpx=(window.innerWidth>window.innerHeight?window.innerHeight:window.innerWidth)*(ismobile?0.9:0.75); + document.getElementById("containerDiv").style.width=dimpx+"px"; + document.getElementById("containerDiv").style.height=dimpx+"px"; +} +function gameInit() +{ + for(var e=document.getElementById("containerDiv").children,i=0;i=0&&i+dx[k]=0&&j+dy[k]=0&&i+dx[k]=0&&j+dy[k]=0&&i+dx[k]=0&&j+dy[k]=0&&i+dx[k]=0&&j+dy[k]=0&&i+dx[k]=0&&j+dy[k]=0&&i+dx[k]=0&&j+dy[k]-1) + for(var i=0;i=0&&i+dx[k]=0&&j+dy[k]=0&&p.x=0&&p.y0;--i) + for(var k=dim-1;k>=0;--k) + if(b[k][j]===0){var t=b[k][j];b[k][j]=b[k+1][j];b[k+1][j]=t;} + for(var k=0;kmaxn){stPnt=new Pnt(j,i);maxn=num;finalcol=col;} + else if(num==maxn) + { + if(j