Add automatic play mode.

This commit is contained in:
yukirij 2024-08-20 01:53:32 -07:00
parent 6dda0a60da
commit 3fc98038ba

View File

@ -552,6 +552,13 @@ const INTERFACE = {
let message = null; let message = null;
ctx.fillStyle = INTERFACE.Color.Text; ctx.fillStyle = INTERFACE.Color.Text;
if(INTERFACE_DATA.auto_mode !== null) {
switch(INTERFACE_DATA.auto_mode) {
case 0: message = "Auto Dawn"; break;
case 1: message = "Auto Dusk"; break;
}
}
if(GAME_DATA.state.code == GAME.Const.State.Retire) { if(GAME_DATA.state.code == GAME.Const.State.Retire) {
ctx.fillStyle = INTERFACE.Color.HintCheck; ctx.fillStyle = INTERFACE.Color.HintCheck;
message = "Retire"; message = "Retire";
@ -720,6 +727,8 @@ const INTERFACE = {
play: null, play: null,
retire:false, retire:false,
auto_mode: null,
replay_turn: 0, replay_turn: 0,
history: history, history: history,
@ -839,6 +848,10 @@ const INTERFACE = {
INTERFACE_DATA.rotate = +(!INTERFACE_DATA.rotate); INTERFACE_DATA.rotate = +(!INTERFACE_DATA.rotate);
INTERFACE.draw(); INTERFACE.draw();
if(INTERFACE_DATA.auto_mode !== null && INTERFACE_DATA.auto_mode == (GAME_DATA.turn & 1)) {
setTimeout(INTERFACE.auto_play, 500);
}
} break; } break;
// Send action to server for validation. // Send action to server for validation.
@ -910,6 +923,17 @@ const INTERFACE = {
}, },
auto() { auto() {
if(INTERFACE_DATA.auto_mode === null) {
console.log("auto on");
INTERFACE_DATA.auto_mode = ((GAME_DATA.turn & 1) ^ 1);
} else {
console.log("auto off");
INTERFACE_DATA.auto_mode = null;
}
INTERFACE.draw();
},
auto_play() {
function state_score(state, player) { function state_score(state, player) {
let score = 0; let score = 0;
let opponent = player ^ 1; let opponent = player ^ 1;