prediction

This commit is contained in:
AUnicornWithNoLife 2021-05-15 11:29:14 +01:00
parent c2d24a5f70
commit 3bf91c8953
5 changed files with 89 additions and 24 deletions

99
src/code.js Normal file → Executable file
View File

@ -1,25 +1,14 @@
function move(id) function move(id)
{ {
if (board[ids[id][0]][ids[id][1]][0] != 0) if (board[ids[id][0]][ids[id][1]][0] != 0)
{ {
return; return;
} }
var charater = ""; var charater = (ptm == 1) ? "X" : "O";
var optm = ptm; var optm = ptm;
if (ptm == 1) ptm = (ptm == 1) ? 2 : 1;
{
charater = "X";
ptm = 2;
}
else
{
charater = "O";
ptm = 1;
}
board[ids[id][0]][ids[id][1]][1].innerHTML = charater; board[ids[id][0]][ids[id][1]][1].innerHTML = charater;
board[ids[id][0]][ids[id][1]][0] = optm; board[ids[id][0]][ids[id][1]][0] = optm;
@ -52,17 +41,14 @@ function move(id)
return; return;
} }
if (ptm == 1) charater = (ptm == 1) ? "X" : "O";
{
charater = "X";
}
else
{
charater = "O";
}
info['go'].innerHTML = charater + "'s Go"; info['go'].innerHTML = charater + "'s Go";
var pre = calculate();
board[pre[0]][pre[1]][1].parentElement.classList.add('predict');
} }
function win() function win()
@ -156,4 +142,69 @@ function reset()
tabloid.classList.remove('win'); tabloid.classList.remove('win');
tabloid.classList.remove('lol'); tabloid.classList.remove('lol');
load();
}
function calculate()
{
var like = (ptm == 1) ? 2 : 1;
for (var x = 0; x <3; x++)
{
if (board[x][0][0] == like && board[x][1][0] == like && board[x][2][0] == 0)
{
return [x, 2];
}
if (board[x][0][0] == like && board[x][1][0] == 0 && board[x][2][0] == like)
{
return [x, 1];
}
if (board[x][0][0] == 0 && board[x][1][0] == like && board[x][2][0] == like)
{
return [x, 0];
}
}
for (var x = 0; x <3; x++)
{
if (board[0][x][0] == like && board[1][x][0] == like && board[2][x][0] == 0)
{
return [2, x];
}
if (board[0][x][0] == like && board[1][x][0] == 0 && board[2][x][0] == like)
{
return [1, x];
}
if (board[0][x][0] == 0 && board[1][x][0] == like && board[2][x][0] == like)
{
return [0, x];
}
}
if (board[0][0][0] == like && board[1][1][0] == like && board[2][2][0] == 0)
{
return [2, 2];
}
if (board[0][0][0] == like && board[1][1][0] == 0 && board[2][2][0] == like)
{
return [1, 1];
}
if (board[0][0][0] == 0 && board[1][1][0] == like && board[2][2][0] == like)
{
return [0, 0];
}
if (board[0][2][0] == like && board[1][1][0] == like && board[2][0][0] == 0)
{
return [2, 0];
}
if (board[0][2][0] == like && board[1][1][0] == 0 && board[2][0][0] == like)
{
return [1, 1];
}
if (board[0][2][0] == 0 && board[1][1][0] == like && board[2][0][0] == like)
{
return [0, 2];
}
} }

0
src/index.html Normal file → Executable file
View File

12
src/style.css Normal file → Executable file
View File

@ -16,6 +16,11 @@
width: 100px; width: 100px;
} }
#board
{
margin-right: 16px;
}
.center .center
{ {
margin-left: auto; margin-left: auto;
@ -72,4 +77,11 @@ button:hover
border-radius: 12px; border-radius: 12px;
background-color: #b86868; background-color: #b86868;
}
.predict
{
border-radius: 12px;
background-color: #9DB17C;
} }

0
src/theme.js Normal file → Executable file
View File

2
src/var.js Normal file → Executable file
View File

@ -62,6 +62,8 @@ function load()
gamemode = 1; gamemode = 1;
root = document.documentElement; root = document.documentElement;
info['go'].innerHTML = "X's Go";
setup(); setup();
} }