Saya tidak bisa kode javascript, jadi saya mencuri jawaban Anda.
//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);
Itu menggunakan strategi yang juga saya gunakan.
EDIT: Bagus, baru saja mengalahkan skor Anda setelah sekitar 5 menit di mesin saya: D
Sunting: Lupa untuk turun dua kali alih-alih hanya sekali, ini adalah kode yang harus Anda gunakan:
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);
Juga, ada bug di dalamnya yang restart ketika tidak diperlukan, tapi saya tidak yakin bagaimana cara memperbaikinya. EDIT: Saat ini memiliki skor tertinggi 3116 (setelah 3 menit). Saya pikir aman untuk mengatakan algoritme ini lebih baik daripada hanya melakukan gerakan acak.
EDIT Versi yang lebih baru:
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);
EDIT: Versi baru lainnya, versi ini langsung turun setelah naik.
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);
EDIT: Perbarui: itu baru saja memecahkan rekor pribadi saya dengan skor yang cukup gila di 1.2596.
EDIT: Hei, saya bottomstacker: D Juga:
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);
(Sebenarnya bukan perubahan, hanya dikompresi.)
5 kali pesona? Tidak yakin. Bagaimanapun:
//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);
dan:
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);
Versi baru lainnya:
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);
dan:
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);
(Saya harap ini tidak terlalu menjadi masalah bahwa ini terus berlanjut di belakang layar gameover? Saya pikir Anda bisa menambahkan a.over=0
tempat yang sering dieksekusi. Saya akan mencari tahu suatu hari nanti.)
EDIT (lagi): Saya membuang cara permainan standar dan kembali ke cara lama dalam melakukan sesuatu. Saya sekarang menguji tambahan yang akan selalu digabung jika ada 2 ubin yang terdiri dari 16 atau lebih bersama-sama:
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);