我无法编写JavaScript代码,所以我偷了你的答案。
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
a.move(c)
c++
if (c>3) {c=1}
m || mfs++;
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
它使用了我也使用的策略。
编辑:好的,在我的机器上大约5分钟后,它刚超过您的分数:D
编辑:忘记向下移动两次,而不是一次,这是您应该使用的代码:
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
m || mfs++;
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
另外,它还有一个错误,它可以在不需要时重新启动,但是我不确定如何解决。编辑:它目前具有3116的最高分(3分钟后)。我认为可以肯定地说这种算法要比随机移动更好。
EDIT较新版本:
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; mfs=0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
m || mfs++;
//up after 5 moves
5 < mfs && (a.move(0));
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
编辑:另一个新版本,此版本向上移动后立即向下移动。
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; mfs=0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
m || mfs++;
//up after 5 moves
5 < mfs && (a.move(0), c=4);
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
编辑:更新:它刚刚以12596的疯狂得分打破了我的个人记录。
编辑:嘿,我是bottomstacker:D也:
b=a.addRandomTile.bind(a);m=!1;a.addRandomTile=function(){m=!0;mfs=0;b()};mfs=0;c=1;setInterval(function(){m=!1;n=3>=c?c:2;a.move(n);c++;4<c&&(c=1);m||mfs++;5<mfs&&(a.move(0),c=4);10<mfs&&(mfs=0,a.restart())},250);
(实际上没有变化,只是压缩了。)
第五次有魅力吗?不确定。无论如何:
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; mfs=0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
if (c==0) {c=4}
m || mfs++;
//up after 5 moves
5 < mfs && (c=0);
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
和:
b=a.addRandomTile.bind(a);m=!1;a.addRandomTile=function(){m=!0;mfs=0;b()};mfs=0;c=1;setInterval(function(){m=!1;n=3>=c?c:2;a.move(n);c++;4<c&&(c=1);0==c&&(c=4);m||mfs++;5<mfs&&(c=0);10<mfs&&(mfs=0,a.restart())},250);
另一个新版本:
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; mfs=0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
if (c==0) {c=4}
m || mfs++;
//up after 5 moves
5 < mfs && (c=0);
//Found this in the source, as the criteria for a gameover. Might as well reset then ;)
if (!a.movesAvailable()) {
a.restart()
}
}, 250);
和:
a=new GameManager(4,KeyboardInputManager,HTMLActuator,LocalStorageManager);b=a.addRandomTile.bind(a);m=!1;a.addRandomTile=function(){m=!0;mfs=0;b()};mfs=0;c=1;setInterval(function(){m=!1;n=3>=c?c:2;a.move(n);c++;4<c&&(c=1);0==c&&(c=4);m||mfs++;5<mfs&&(c=0);a.movesAvailable()||a.restart()},250);
(我希望这在游戏结束画面后继续存在不是太大的问题?我认为您可以添加一个a.over=0
经常执行的地方。我有一天会解决这个问题。)
编辑(再次):我放弃了标准的gameover方法,并恢复为旧的工作方式。我现在正在测试一个添加项,如果有16个或更多的2个图块在一起,它将始终合并:
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() {
m = !0;
mfs = 0;
b();
};
mfs = 0;
c = 1;
setInterval(function() {
m = !1;
l = 8;
for (x = 0;x < 4;x++) {
for (y = 0;y < 4;y++) {
t1 = a.grid.cellContent({x:x, y:y});
t2 = a.grid.cellContent({x:x, y:y + 1});
t3 = a.grid.cellContent({x:x + 1, y:y + 1});
if (t1 & t2) {
if (t1.value == t2.value) {
if (t1.value > l) {
l = t1.value;
c = 2;
}
}
if (t1 & t3) {
if (t1.value == t2.value) {
if (t1.value > l) {
l = t1.value;
}
}
}
}
}
}
if (c <= 3) {
n = c;
} else {
n = 2;
}
a.move(n);
c++;
if (c > 4) {
c = 1;
}
if (c == 0) {
c = 4;
}
m || mfs++;
5 < mfs && (c = 0);
10 < mfs && (mfs = 0, a.restart());
}, 250);