TTTnoAI

Size
2,784 Kb
Views
30,360

How do I make an tttnoai?

What is a tttnoai? How do you make a tttnoai? This script and codes were developed by Neeilan Selvalingam on 13 September 2022, Tuesday.

TTTnoAI Previews

TTTnoAI - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>TTTnoAI</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="XorO">
Would you like to play as X or O?<br><br>
<button class="xobtn" onclick="setHuman('x')">X</button>
<button class="xobtn" onclick="setHuman('o')">O</button>
</div>
<div id="board">
<div onclick="userClick(0,board)" id="0"></div>
<div onclick="userClick(1,board)" id="1"></div>
<div onclick="userClick(2,board)" id="2"></div><br>
<div onclick="userClick(3,board)" id="3"></div>
<div onclick="userClick(4,board)" id="4"></div>
<div onclick="userClick(5,board)" id="5"></div><br>
<div onclick="userClick(6,board)" id="6"></div>
<div onclick="userClick(7,board)" id="7"></div>
<div onclick="userClick(8,board)" id="8"></div>
</div> <script src="js/index.js"></script>
</body>
</html>

TTTnoAI - Script Codes CSS Codes

#XorO{ text-align: center; margin-top: 100px; font-family: Helvetica, Arial;
/* font-weight: bold; */ color: #9e9e9e; font-size: 24px;
}
#board { visibility: hidden; text-align: center; margin-left: auto; margin-right: auto; margin-top: 100px;
}
#board div { border: solid 5px #bcaaa4; margin-bottom: -10px; margin-left: -10px; display: inline-block; width: 100px; height: 100px; margin: none; overflow: hidden; color: #40c4ff; font-family: Arial; font-size: 80px; font-weight: bold;
}
.comp { color: #ff8a65;
}
.xobtn { display: inline; background: #039be5; height: 50px; width: 80px; border: none; color: white; font-size: 18px; border-radius: 5%;
}
.xobtn:hover { background: #01579b;
}

TTTnoAI - Script Codes JS Codes

var computer;
var human;
var board = ["", "", "", "", "", "", "", "", ""];
function setHuman(choice) { human = choice; if (choice === 'x') { computer = 'o'; } else { computer = 'x'; } document.getElementById("XorO").innerHTML = ""; document.getElementById("board").style.visibility = "visible";
}
function userClick(position, board) { if (board[position] == "") { board[position] = human; board = check(board); }
}
function check(board) { if (getWinner(board) === false) { if (winOnNextMove(board, computer, human) == false) { board = randomX(board); } else { board[winOnNextMove(board, computer, human)] = computer; } updateBoard(board); if (getWinner(board)) { gameOver(board); } } else { updateBoard(board); gameOver(board); }
}
function updateBoard(arr) { for (var i = 0; i < 9; i++) { if (arr[i] == computer) { document.getElementById("" + i).innerHTML = "<span class='comp'>" + arr[i] + "</span>"; } else { document.getElementById("" + i).innerHTML = arr[i]; } }
}
function randomX(arr) { if (arr[4]==""){ arr[4]=computer; return arr; } while (true) { var i = Math.floor(Math.random() * 9); if (arr[i] == "") { arr[i] = computer; return arr; } }
}
function getWinner(board) { switch (winCheck(board)) { case (computer): return 1; case (human): return -1; case "T": return 0; default: return false; }
}
function winCheck(arr) { if (((arr[0] == arr[4] && arr[0] == arr[8]) || (arr[2] == arr[4] && arr[2] == arr[6])) && arr[4] !== "") { return arr[4]; } for (var i = 0; i < 9; i += 3) { if ((arr[i] == arr[i + 1] && arr[i] == arr[i + 2]) && arr[i] !== "") { return arr[i]; } } for (var i = 0; i < 3; i++) { if ((arr[i] == arr[i + 3] && arr[i] == arr[i + 6]) && arr[i] !== "") { return arr[i]; } } if (arr.indexOf("") == -1) { return "T"; } return false;
}
function winOnNextMove(arr, player, opponent) { for (var i = 0; i < 9; i++) { var arr2 = arr.slice(); if (arr2[i] == "") { arr2[i] = player; if (getWinner(arr2) === 1) { return i; } } } for (var i = 0; i < 9; i++) { var arr3 = arr.slice(); if (arr3[i] == "") { arr3[i] = opponent; if (getWinner(arr3) === -1) { return i; } } } return false;
}
function gameOver(arr) { if (getWinner(arr) == 1) { alert("You lost!"); } else if (getWinner(arr) == -1) { alert("You won!"); } else if (getWinner(arr) == 0) { alert("Tie game!"); } restart();
}
function restart() { board = ["", "", "", "", "", "", "", "", ""]; updateBoard(board);
}
TTTnoAI - Script Codes
TTTnoAI - Script Codes
Home Page Home
Developer Neeilan Selvalingam
Username neeilan
Uploaded September 13, 2022
Rating 3
Size 2,784 Kb
Views 30,360
Do you need developer help for TTTnoAI?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Neeilan Selvalingam (neeilan) Script Codes
Name
MarkdownPreviewer
UTSCMap
GameOfLife
Firebase-test
Parallaxtest
RecipeBox
Simon Game
Scribe
MinimaxTTT
NeeilWiki
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!