{"id":242,"date":"2025-01-07T02:33:05","date_gmt":"2025-01-07T02:33:05","guid":{"rendered":"https:\/\/smallmoon.net\/?p=242"},"modified":"2025-01-07T03:00:14","modified_gmt":"2025-01-07T03:00:14","slug":"wzq","status":"publish","type":"post","link":"https:\/\/smallmoon.net\/?p=242","title":{"rendered":"Gobang"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"zh-CN\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>\u4e94\u5b50\u68cb<\/title>\n    <style>\n        body {\n            font-family: sans-serif;\n            display: flex;\n            flex-direction: column;\n            align-items: center;\n            padding-top: 20px;\n        }\n        #gomoku-container {\n            display: flex;\n            flex-direction: column;\n            align-items: center;\n            width: 100%;\n            max-width: 450px; \/* \u8bbe\u7f6e\u6700\u5927\u5bbd\u5ea6\uff0c\u9632\u6b62\u8fc7\u5927 *\/\n        }\n        #gomoku-board {\n            display: grid;\n            grid-template-columns: repeat(15, 1fr);\n            grid-template-rows: repeat(15, 1fr);\n            width: 100%;\n            aspect-ratio: 1 \/ 1;\n            border: 2px solid #8b4513;\n            margin-bottom: 10px;\n            box-sizing: border-box;\n        }\n        #gomoku-board div {\n           display: flex;\n           align-items: center;\n           justify-content: center;\n            background-color: transparent !important;\n            border: 1px solid #8b4513 !important;\n            box-sizing: border-box !important;\n            cursor: pointer !important;\n        }\n        #gomoku-board div div {\n            width: 80% !important;\n            height: 80% !important;\n            border-radius: 50% !important;\n            background-color: inherit !important;\n\t\t\tborder: inherit !important;\n        }\n        #gomoku-status {\n            font-size: 1.2em;\n            margin-bottom: 10px;\n        }\n    <\/style>\n<\/head>\n<body>\n    <div id=\"gomoku-container\">\n        <div id=\"gomoku-board\"><\/div>\n        <div id=\"gomoku-status\"><\/div>\n    <\/div>\n<script>\n(function() {\n  function initGomokuGame() {\n    try {\n      const board = document.getElementById('gomoku-board');\n      const status = document.getElementById('gomoku-status');\n      if (!board || !status) {\n        throw new Error('\u65e0\u6cd5\u627e\u5230\u5fc5\u8981\u7684DOM\u5143\u7d20');\n      }\n\n      const size = 15;\n      let currentPlayer = 'black';\n      let gameOver = false; \n      let gameBoard = Array(size).fill().map(() => Array(size).fill(null));\n\n      function createBoard() {\n        board.innerHTML = ''; \n        for (let i = 0; i < size * size; i++) {\n          const cell = document.createElement('div');\n          cell.style.cssText = `\n            display: flex;\n            align-items: center;\n            justify-content: center;\n            background-color: transparent !important;\n            border: 1px solid #8b4513 !important;\n            box-sizing: border-box !important;\n            cursor: pointer !important;\n          `;\n          cell.addEventListener('click', () => makeMove(i));\n          board.appendChild(cell);\n        }\n      }\n\n      function makeMove(index) {\n        if (gameOver) return; \n\n        const row = Math.floor(index \/ size);\n        const col = index % size;\n        if (gameBoard[row][col]) return;\n\n        gameBoard[row][col] = currentPlayer;\n        const cell = board.children[index];\n        const piece = document.createElement('div');\n        piece.style.cssText = `\n          width: 80% !important;\n          height: 80% !important;\n          border-radius: 50% !important;\n          background-color: ${currentPlayer === 'black' ? 'black' : 'white'} !important;\n          ${currentPlayer === 'white' ? 'border: 1px solid black !important;' : ''}\n        `;\n        cell.appendChild(piece);\n\n        if (checkWin(row, col)) {\n          gameOver = true; \n          status.textContent = `${currentPlayer === 'black' ? '\u9ed1' : '\u767d'}\u68cb\u80dc\u5229\uff01`;\n        } else {\n          currentPlayer = currentPlayer === 'black' ? 'white' : 'black';\n          status.textContent = `\u8f6e\u5230${currentPlayer === 'black' ? '\u9ed1' : '\u767d'}\u68cb`;\n        }\n      }\n\n      function checkWin(row, col) {\n        const player = gameBoard[row][col];\n        const directions = [\n          [1, 0], [0, 1], [1, 1], [1, -1] \n        ];\n\n        for (const [dx, dy] of directions) {\n          let count = 1;\n          for (let i = 1; i < 5; i++) {\n            const newRow = row + i * dy;\n            const newCol = col + i * dx;\n            if (newRow >= 0 && newRow < size &#038;&#038; newCol >= 0 && newCol < size &#038;&#038; gameBoard[newRow][newCol] === player) {\n              count++;\n            } else {\n              break;\n            }\n          }\n          for (let i = -1; i > -5; i--) {\n            const newRow = row + i * dy;\n            const newCol = col + i * dx;\n            if (newRow >= 0 && newRow < size &#038;&#038; newCol >= 0 && newCol < size &#038;&#038; gameBoard[newRow][newCol] === player) {\n              count++;\n            } else {\n              break;\n            }\n          }\n          if (count >= 5) {\n            return true; \n          }\n        }\n        return false;\n      }\n\n      createBoard();\n      status.textContent = '\u6e38\u620f\u5df2\u52a0\u8f7d\uff0c\u8f6e\u5230\u9ed1\u68cb';\n    } catch (error) {\n      console.error('\u521d\u59cb\u5316\u6e38\u620f\u65f6\u53d1\u751f\u9519\u8bef:', error);\n    }\n  }\n\n  \n  if (document.readyState === 'interactive' || document.readyState === 'complete') {\n    initGomokuGame();\n  } else {\n    document.addEventListener('DOMContentLoaded', initGomokuGame);\n  }\n})();\n<\/script>\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>\u4e94\u5b50\u68cb<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[19],"class_list":["post-242","post","type-post","status-publish","format-standard","hentry","category-ai","tag-19"],"_links":{"self":[{"href":"https:\/\/smallmoon.net\/index.php?rest_route=\/wp\/v2\/posts\/242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smallmoon.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smallmoon.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smallmoon.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smallmoon.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=242"}],"version-history":[{"count":10,"href":"https:\/\/smallmoon.net\/index.php?rest_route=\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":253,"href":"https:\/\/smallmoon.net\/index.php?rest_route=\/wp\/v2\/posts\/242\/revisions\/253"}],"wp:attachment":[{"href":"https:\/\/smallmoon.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smallmoon.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smallmoon.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}