CY +357-96-38-39-40
RU +7 965 2 38-39-40
WhatsApp
Telegram
Сообщение
Чат
info@24glo.com
Контакты
Чтобы сделать ход - нажмите на квадратик.
Крестики-нолики — это логическая игра для двух игроков, широко известная по всему миру. Она проста в освоении, но в то же время позволяет развивать стратегическое мышление.
Игра имеет древние корни. Аналогичные игры существовали в Древнем Египте и Древнем Риме. Например, в Риме была популярна игра «Terni Lapilli», где использовались отметки на каменных плитах. Современная форма игры начала активно распространяться в XIX и XX веках.
Классическая игра проходит на поле 3×3. Игроки поочередно ставят свои символы: один играет за «X», другой за «O». Выигрывает тот, кто первым выстроит три своих символа в ряд по вертикали, горизонтали или диагонали.
Существует множество вариаций игры. Например, гомоку (или «пять в ряд») играется на более крупном поле (обычно 15×15), и игрокам нужно выстроить пять символов подряд. Также популярны расширенные версии на полях 4×4 и 5×5.

Если оба игрока играют оптимально, то игра всегда заканчивается ничьей. Основные стратегии:
Из-за простых правил, эта игра часто используется в обучении программированию. Начинающие программисты пишут консольные версии, а более опытные – реализуют алгоритм минимакс, чтобы создать искусственный интеллект для игры.
<script>
let board = [''', ''', ''', ''', ''', ''', ''', ''', '''];
let currentPlayer = 'X';
let gameActive = true;
function createBoard() {
const boardElement = document.getElementById('board');
boardElement.innerHTML = '';
board.forEach((cell, index) => {
const cellElement = document.createElement('div');
cellElement.classList.add('cell');
cellElement.textContent = cell;
cellElement.addEventListener('click', () => makeMove(index));
boardElement.appendChild(cellElement);
});
}
function makeMove(index) {
if (board[index] === ''' && gameActive) {
board[index] = currentPlayer;
createBoard();
if (checkWinner()) {
document.getElementById('status').textContent = `Победитель: ${currentPlayer}`;
gameActive = false;
return;
}
if (!board.includes(''')) {
document.getElementById('status').textContent = "Ничья!";
gameActive = false;
return;
}
currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
document.getElementById('status').textContent = `Ваш ход: ${currentPlayer}`;
if (currentPlayer === 'O') {
setTimeout(computerMove, 500);
}
}
}
function computerMove() {
let bestMove = findBestMove();
if (bestMove !== -1) {
board[bestMove] = 'O';
createBoard();
if (checkWinner()) {
document.getElementById('status').textContent = "Компьютер победил!";
gameActive = false;
return;
}
if (!board.includes(''')) {
document.getElementById('status').textContent = "Ничья!";
gameActive = false;
return;
}
currentPlayer = 'X';
document.getElementById('status').textContent = `Ваш ход: ${currentPlayer}`;
}
}
function findBestMove() {
const winPatterns = [
[0, 1, 2], [3, 4, 5], [6, 7, 8],
[0, 3, 6], [1, 4, 7], [2, 5, 8],
[0, 4, 8], [2, 4, 6]
];
for (let pattern of winPatterns) {
let [a, b, c] = pattern;
if (board[a] === 'O' && board[b] === 'O' && board[c] === ''') return c;
if (board[a] === 'O' && board[c] === 'O' && board[b] === ''') return b;
if (board[b] === 'O' && board[c] === 'O' && board[a] === ''') return a;
}
for (let pattern of winPatterns) {
let [a, b, c] = pattern;
if (board[a] === 'X' && board[b] === 'X' && board[c] === ''') return c;
if (board[a] === 'X' && board[c] === 'X' && board[b] === ''') return b;
if (board[b] === 'X' && board[c] === 'X' && board[a] === ''') return a;
}
if (board[4] === ''') return 4;
let emptyCells = board.map((cell, index) => cell === ''' ? index : null).filter(index => index !== null);
return emptyCells.length > 0 ? emptyCells[Math.floor(Math.random() * emptyCells.length)] : -1;
}
function checkWinner() {
const winPatterns = [
[0, 1, 2], [3, 4, 5], [6, 7, 8],
[0, 3, 6], [1, 4, 7], [2, 5, 8],
[0, 4, 8], [2, 4, 6]
];
return winPatterns.some(pattern => {
const [a, b, c] = pattern;
return board[a] && board[a] === board[b] && board[a] === board[c];
});
}
function resetGame() {
board = [''', ''', ''', ''', ''', ''', ''', ''', '''];
currentPlayer = 'X';
gameActive = true;
document.getElementById('status').textContent = 'Ваш ход: X';
createBoard();
}
createBoard();
</script>
Крестики-нолики – это не просто детская игра, а мощный инструмент для тренировки логики. Несмотря на свою простоту, она продолжает вдохновлять разработчиков и математиков по всему миру.
24glo.com
| ▲
| Контакты
Copyright © 24GLO LTD ® 2004-2025. All rights reserved.