TTTnoAI
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 - 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);
}
Developer | Neeilan Selvalingam |
Username | neeilan |
Uploaded | September 13, 2022 |
Rating | 3 |
Size | 2,784 Kb |
Views | 30,360 |
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!
Name | Size |
MarkdownPreviewer | 3,147 Kb |
UTSCMap | 3,292 Kb |
GameOfLife | 6,445 Kb |
Firebase-test | 2,374 Kb |
Parallaxtest | 1,152 Kb |
RecipeBox | 6,082 Kb |
Simon Game | 3,313 Kb |
Scribe | 3,525 Kb |
MinimaxTTT | 2,823 Kb |
NeeilWiki | 2,824 Kb |
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!
Name | Username | Size |
Simple Responsive Text | Fbrz | 2,282 Kb |
Pruebas de d3.js | Juanmanuelcarnerero | 2,485 Kb |
Simple Login Form Template | Banunn | 3,571 Kb |
Css3 slide | Nakome | 3,190 Kb |
AngularJS Skills | Supro | 3,312 Kb |
NT Tribute | Skybutterfly | 2,850 Kb |
A Pen by Kevin | Kevinkenger | 2,642 Kb |
Classy Blockquote Styling | Andrewwright | 3,212 Kb |
Button fills | Zubfatal | 5,205 Kb |
Static Image to Video Block | Grayghostvisuals | 4,864 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!