From 43cbeb78caace87b0d062692728087d6c5fc5474 Mon Sep 17 00:00:00 2001 From: AUnicornWithNoLife Date: Sat, 10 Jul 2021 12:00:42 +0100 Subject: [PATCH] moved predect to external file --- src/code.js | 185 ------------------------------------------------- src/index.html | 1 + src/predict.js | 184 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+), 185 deletions(-) create mode 100644 src/predict.js diff --git a/src/code.js b/src/code.js index 9054876..0847f39 100755 --- a/src/code.js +++ b/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{} - } - } } \ No newline at end of file diff --git a/src/index.html b/src/index.html index 5955c7e..772b6ea 100755 --- a/src/index.html +++ b/src/index.html @@ -10,6 +10,7 @@ + diff --git a/src/predict.js b/src/predict.js new file mode 100644 index 0000000..5819d5b --- /dev/null +++ b/src/predict.js @@ -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{} + } + } +} \ No newline at end of file