moved predect to external file
This commit is contained in:
parent
8edcf37761
commit
43cbeb78ca
185
src/code.js
185
src/code.js
@ -148,189 +148,4 @@ function reset()
|
||||
tabloid.classList.remove('lol');
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
function calculate(like)
|
||||
{
|
||||
const dislike = (like == 1) ? 2 : 1;
|
||||
|
||||
//LIKE
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
//DISLIKE
|
||||
|
||||
for (var x = 0; x <3; x++)
|
||||
{
|
||||
if (board[0][x][0] == dislike && board[1][x][0] == dislike && board[2][x][0] == 0)
|
||||
{
|
||||
return [2, x];
|
||||
}
|
||||
if (board[0][x][0] == dislike && board[1][x][0] == 0 && board[2][x][0] == dislike)
|
||||
{
|
||||
return [1, x];
|
||||
}
|
||||
if (board[0][x][0] == 0 && board[1][x][0] == dislike && board[2][x][0] == dislike)
|
||||
{
|
||||
return [0, x];
|
||||
}
|
||||
}
|
||||
|
||||
for (var x = 0; x <3; x++)
|
||||
{
|
||||
if (board[x][0][0] == dislike && board[x][1][0] == dislike && board[x][2][0] == 0)
|
||||
{
|
||||
return [x, 2];
|
||||
}
|
||||
if (board[x][0][0] == dislike && board[x][1][0] == 0 && board[x][2][0] == dislike)
|
||||
{
|
||||
return [x, 1];
|
||||
}
|
||||
if (board[x][0][0] == 0 && board[x][1][0] == dislike && board[x][2][0] == dislike)
|
||||
{
|
||||
return [x, 0];
|
||||
}
|
||||
}
|
||||
|
||||
if (board[0][0][0] == dislike && board[1][1][0] == dislike && board[2][2][0] == 0)
|
||||
{
|
||||
return [2, 2];
|
||||
}
|
||||
if (board[0][0][0] == dislike && board[1][1][0] == 0 && board[2][2][0] == dislike)
|
||||
{
|
||||
return [1, 1];
|
||||
}
|
||||
if (board[0][0][0] == 0 && board[1][1][0] == dislike && board[2][2][0] == dislike)
|
||||
{
|
||||
return [0, 0];
|
||||
}
|
||||
|
||||
if (board[0][2][0] == dislike && board[1][1][0] == dislike && board[2][0][0] == 0)
|
||||
{
|
||||
return [2, 0];
|
||||
}
|
||||
if (board[0][2][0] == dislike && board[1][1][0] == 0 && board[2][0][0] == dislike)
|
||||
{
|
||||
return [1, 1];
|
||||
}
|
||||
if (board[0][2][0] == 0 && board[1][1][0] == dislike && board[2][0][0] == dislike)
|
||||
{
|
||||
return [0, 2];
|
||||
}
|
||||
|
||||
//CENTER
|
||||
|
||||
if (board[1][1][0] == 0)
|
||||
{
|
||||
return [1, 1];
|
||||
}
|
||||
|
||||
//CORNERS
|
||||
|
||||
if (board[0][0][0] == 0)
|
||||
{
|
||||
return [0, 0];
|
||||
}
|
||||
if (board[0][2][0] == 0)
|
||||
{
|
||||
return [0, 2];
|
||||
}
|
||||
if (board[2][0][0] == 0)
|
||||
{
|
||||
return [2, 0];
|
||||
}
|
||||
if (board[2][2][0] == 0)
|
||||
{
|
||||
return [2, 2];
|
||||
}
|
||||
|
||||
//EDGES
|
||||
|
||||
if (board[0][1][0] == 0)
|
||||
{
|
||||
return [0, 1];
|
||||
}
|
||||
if (board[2][1][0] == 0)
|
||||
{
|
||||
return [2, 1];
|
||||
}
|
||||
if (board[1][0][0] == 0)
|
||||
{
|
||||
return [1, 0];
|
||||
}
|
||||
if (board[1][2][0] == 0)
|
||||
{
|
||||
return [1, 2];
|
||||
}
|
||||
}
|
||||
|
||||
function resetPredict()
|
||||
{
|
||||
for (var x = 0; x <3; x++)
|
||||
{
|
||||
for (var y = 0; y <3; y++)
|
||||
{
|
||||
try
|
||||
{
|
||||
board[x][y][1].parentElement.classList.remove("predict");
|
||||
}
|
||||
catch{}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
<script src='./code.js'></script>
|
||||
<script src='./var.js'></script>
|
||||
<script src='./theme.js'></script>
|
||||
<script src='./predict.js'></script>
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
|
||||
|
184
src/predict.js
Normal file
184
src/predict.js
Normal file
@ -0,0 +1,184 @@
|
||||
function calculate(like)
|
||||
{
|
||||
const dislike = (like == 1) ? 2 : 1;
|
||||
|
||||
//LIKE
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
//DISLIKE
|
||||
|
||||
for (var x = 0; x <3; x++)
|
||||
{
|
||||
if (board[0][x][0] == dislike && board[1][x][0] == dislike && board[2][x][0] == 0)
|
||||
{
|
||||
return [2, x];
|
||||
}
|
||||
if (board[0][x][0] == dislike && board[1][x][0] == 0 && board[2][x][0] == dislike)
|
||||
{
|
||||
return [1, x];
|
||||
}
|
||||
if (board[0][x][0] == 0 && board[1][x][0] == dislike && board[2][x][0] == dislike)
|
||||
{
|
||||
return [0, x];
|
||||
}
|
||||
}
|
||||
|
||||
for (var x = 0; x <3; x++)
|
||||
{
|
||||
if (board[x][0][0] == dislike && board[x][1][0] == dislike && board[x][2][0] == 0)
|
||||
{
|
||||
return [x, 2];
|
||||
}
|
||||
if (board[x][0][0] == dislike && board[x][1][0] == 0 && board[x][2][0] == dislike)
|
||||
{
|
||||
return [x, 1];
|
||||
}
|
||||
if (board[x][0][0] == 0 && board[x][1][0] == dislike && board[x][2][0] == dislike)
|
||||
{
|
||||
return [x, 0];
|
||||
}
|
||||
}
|
||||
|
||||
if (board[0][0][0] == dislike && board[1][1][0] == dislike && board[2][2][0] == 0)
|
||||
{
|
||||
return [2, 2];
|
||||
}
|
||||
if (board[0][0][0] == dislike && board[1][1][0] == 0 && board[2][2][0] == dislike)
|
||||
{
|
||||
return [1, 1];
|
||||
}
|
||||
if (board[0][0][0] == 0 && board[1][1][0] == dislike && board[2][2][0] == dislike)
|
||||
{
|
||||
return [0, 0];
|
||||
}
|
||||
|
||||
if (board[0][2][0] == dislike && board[1][1][0] == dislike && board[2][0][0] == 0)
|
||||
{
|
||||
return [2, 0];
|
||||
}
|
||||
if (board[0][2][0] == dislike && board[1][1][0] == 0 && board[2][0][0] == dislike)
|
||||
{
|
||||
return [1, 1];
|
||||
}
|
||||
if (board[0][2][0] == 0 && board[1][1][0] == dislike && board[2][0][0] == dislike)
|
||||
{
|
||||
return [0, 2];
|
||||
}
|
||||
|
||||
//CENTER
|
||||
|
||||
if (board[1][1][0] == 0)
|
||||
{
|
||||
return [1, 1];
|
||||
}
|
||||
|
||||
//CORNERS
|
||||
|
||||
if (board[0][0][0] == 0)
|
||||
{
|
||||
return [0, 0];
|
||||
}
|
||||
if (board[0][2][0] == 0)
|
||||
{
|
||||
return [0, 2];
|
||||
}
|
||||
if (board[2][0][0] == 0)
|
||||
{
|
||||
return [2, 0];
|
||||
}
|
||||
if (board[2][2][0] == 0)
|
||||
{
|
||||
return [2, 2];
|
||||
}
|
||||
|
||||
//EDGES
|
||||
|
||||
if (board[0][1][0] == 0)
|
||||
{
|
||||
return [0, 1];
|
||||
}
|
||||
if (board[2][1][0] == 0)
|
||||
{
|
||||
return [2, 1];
|
||||
}
|
||||
if (board[1][0][0] == 0)
|
||||
{
|
||||
return [1, 0];
|
||||
}
|
||||
if (board[1][2][0] == 0)
|
||||
{
|
||||
return [1, 2];
|
||||
}
|
||||
}
|
||||
|
||||
function resetPredict()
|
||||
{
|
||||
for (var x = 0; x <3; x++)
|
||||
{
|
||||
for (var y = 0; y <3; y++)
|
||||
{
|
||||
try
|
||||
{
|
||||
board[x][y][1].parentElement.classList.remove("predict");
|
||||
}
|
||||
catch{}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user