CPUと対戦できる闘獣棋を作ってください
- User
CPUと対戦できる闘獣棋を作ってください
Assistant
I will search the project directory to understand the existing files and structure. Let's list the files.
I will read
package.jsonto understand the installed dependencies so we can determine if we need to install package likelucide-reactfor icons, or use standard SVG/emojis.I will search for the standard rules of Jungle Chess (闘獣棋 / Dou Shou Qi) to ensure the animal ranks, board layout, movement, and capturing rules are implemented accurately.
I will search for the exact starting positions of the animal chess pieces (闘獣棋) on the 7x9 board. This is important to ensure standard, accurate setup for players.
I will search for the starting coordinates of each animal piece in Jungle Chess (Dou Shou Qi) on the 7x9 grid.
I will search for the Chinese name of the board game "斗兽棋" along with "初始位置" (initial position) or "棋盘" (board map) to find the exact coordinates. This is a very robust way to get the exact layout of the 16 pieces (8 for each side).
I will search for standard Jungle Chess rules regarding Rat (鼠) capture and water interactions to ensure precise simulation.
I will read the initial content of
src/App.tsxto see how the template is set up.I will install the
lucide-reactpackage to provide high-quality icons for our game controls, difficulty settings, sidebars, sound toggles, and other UI elements.I will create a types file
src/types/jungle.tsto represent players, pieces, moves, board configurations, and the general game state. This keeps our code highly structured and type-safe.I will create the
src/utils/jungleEngine.tsfile, which will contain the core board geometry, initial piece layouts, complete rules for legal movement, river jumps, traps, and capturing, as well as an AI opponent engine using Minimax with Alpha-Beta pruning and a strategic heuristic evaluation function.I will fix the typescript compilation errors in
src/utils/jungleEngine.tsby importingCpuDifficulty, removing unused imports/variables, and ensuring all referenced types are resolved correctly.I will read the
canPieceCapturefunction insrc/utils/jungleEngine.tsto locate and clean up any unused parameters or variables.I will edit
src/utils/jungleEngine.tsto remove the unusedfromSquarevariable and the unusedboardparameter fromcanPieceCapture, including updating all the callers, to eliminate the TypeScript compiler warnings.I will read
src/utils/jungleEngine.tsaround lines 190 to 255 to locate the calls tocanPieceCaptureand remove the fifthboardargument.I will edit
src/utils/jungleEngine.tsto remove the extraboardargument from the three calls tocanPieceCapture. This will resolve the TypeScript compiler warnings inisValidMove.I will read the end of
src/utils/jungleEngine.tsto inspect thegetCpuMovefunction, then adapt it to support both players (RED and BLUE) so CPU vs CPU battles can work with different difficulty levels for each side.I will modify
getCpuMoveinsrc/utils/jungleEngine.tsso it accepts aplayerparameter. This allows either RED or BLUE to be controlled by the AI, which is necessary for CPU vs CPU games, and lets the player choose which side to play as if they want to switch in the future.I will create the main web application in
src/App.tsx. It will contain the game setup interface, board rendering, dynamic theme application, responsive game grid with coordinates, user controls (undo, redo, restart, help, sound, difficulties), interactive moves and capture highlights, the Web Audio synthesized sound generator, auto-saving/loading state, and CPU automation for PVC and CVC modes. Let's create the file.I will read the section around line 1101 in
src/App.tsxto understand the type error on that line.I will inspect the imports of
src/App.tsxfrom lines 1 to 40 so that I can remove the unused React hooks, Lucide icons, and engine imports.I will edit the imports at the beginning of
src/App.tsxto remove unused references and clean up the code.I will read the
triggerMovefunction insrc/App.tsxfrom lines 475 to 510 to find and remove the unused variablestargetPieceandfromSquare.I will edit
src/App.tsxaround thetriggerMovefunction to remove the unusedtargetPieceandfromSquarevariables.I will read
src/App.tsxaround lines 1070 to 1105 to locate the button that has the TS typing error and modify it to convertwinnerto a boolean properly.I will edit
src/App.tsxat line 1089 to change thedisabledprop of the "AIを1歩動かす" button todisabled={!!winner || isCpuCalculating}. This convertswinnerto a boolean correctly, satisfying TypeScript's type checker.I will read the
index.htmlfile using theread_filetool to inspect the title tag, and then change it to something appropriate for this Jungle Chess (闘獣棋) web application.I will update the title of the web application in
index.htmlto make it professional and clear: "闘獣棋 (Jungle Chess) - AI対戦対応の究極どうぶつしょうぎ".I will now run the project's build process using the
build_projecttool to ensure that all typescript typings and react code compile perfectly without errors.CPUと対戦できる本格的な**闘獣棋(どうじゅうき / Jungle Chess)**のWebアプリケーションが完成しました!
すべてのゲームルールが完全に実装されており、最先端のAI(アルファベータ枝刈り付きミニマックス法)を相手に難易度を選択して楽しむことができます。さらに、洗練されたデザインや4種類のデザインテーマ、シンセサイザーによる効果音システムなど、細部までこだわり抜いた高品質なアプリケーションです。
🎮 ゲームの主な特長と機能
-
本格的なルール再現(特殊ルール対応)
- 通常移動:前後左右への1マス移動(自分の獣穴への侵入不可)。
- 弱肉強食(序列):大象(8)からネズミ(1)までの階級システム。
- ネズミの特権 (1 vs 8):最弱のネズミだけが、最強のゾウを捕獲可能(ゾウからネズミは捕獲不可)。
- 川(水域)ルール:ネズミだけが川に入れます。川の中にいるネズミは、陸上のいかなるコマとも捕獲し合うことができません(川の中のネズミ同士のみ捕獲可能)。
- 川の跳躍:ライオン(7)とトラ(6)は、川を直線的に跳び越えられます。ただし、川の中にネズミ(敵・味方問わず)がいる場合はジャンプが遮られます。
- 罠(落とし穴):相手の獣穴を取り囲む罠に入ったコマは、一時的に強さが 0 になり、敵のすべてのコマ(ネズミ含む)から捕獲可能な状態になります。
-
3つの対戦モード
- 👤 🆚 🤖 CPU対戦(Player vs CPU):あなた(青・先手)と優秀なCPU(赤・後手)との対戦。
- 👤 🆚 👤 2人プレイ(Pass & Play):1台の端末で友達と交互に指し合うローカル対戦モード。
- 🤖 🆚 🤖 AI観戦(CPU vs CPU):AI同士が自動的に思考して戦う様子を鑑賞・シミュレーションできるモード。
-
高度な戦略CPU(ミニマックスAI)
- 難易度を**「初級(Easy)」「中級(Medium)」「上級(Hard)」**の3段階から選べます。
- アルファベータ枝刈り(Alpha-Beta Pruning)付きミニマックス法を搭載。
- CPUは以下の要素をリアルタイムに評価・計算して最適な手を選びます:
- コマの価値(大象、獅子、ネズミなどの戦力差)
- 敵の獣穴までの距離(攻めの姿勢)
- 罠にかかるリスク(強さ0へのペナルティ回避)
- 自陣の獣穴を守る防御ポイント
- 合法手の数(手詰まりの回避)
-
最高峰のユーザーインターフェース (UI/UX)
- 4つの美しくインタラクティブなボードテーマ:
- 🌳 ジャングル:緑豊かな森と澄んだ川を再現。
- 🪵 クラシック:伝統的な木製盤を想起させる、温かみのある本格グラフィック。
- ⚡ ネオン:サイバーパンク感のある未来的なダークネオン。
- 🔳 ミニマル:無駄を削ぎ落としたスタイリッシュな白黒デザイン。
- 分かりやすい視覚ガイド:
- コマを選択すると、進めるマスが緑のドットで光り、**キャプチャー(捕獲)可能な敵のマスが「赤色の剣マーク ⚔️」**で点滅します。
- 伝統的な木製・アクリルの丸型将棋チップを模したデザインに、動物絵文字・漢字・英語名・強さ数値(1〜8)を美しく表示。
- 本格的な棋譜ログ & 墓場(捕獲物リスト):
- 「1. 🔵 鼠 A3 → A4」などの本格的な棋譜表記。
- 互いに奪い取った動物のコマがプールされる視覚的な「捕獲品リスト」を完備。
- 4つの美しくインタラクティブなボードテーマ:
-
音響・システム補助機能
- 内蔵シンセサイザー(Web Audio API):音響ファイルを読み込むことなく、純粋なブラウザの音声波形制御により、選択音、移動音、捕獲時のクラッシュ音、川の跳躍音、罠に落ちたアラート音、勝利ファンファーレ、敗北の哀愁コードをリアルタイム生成します(消音も可能)。
- 「一手戻る(Undo)」「一手進む(Redo)」:完全に機能する巻き戻しバッファ。ミスをしても戻すことができます。
- 自動セーブ機能:ブラウザを閉じたりリフレッシュしたりしても、対局の状態がローカルストレージに自動保存され、いつでも再開できます。
📖 動物の強さ早見表(序列)
ランク コマ 英語名 特徴 8 象 🐘 Elephant 最強。ネズミ以外のすべてのコマを倒せるが、ネズミには一方的に負ける。 7 獅 🦁 Lion 準最強。川を前後左右に跳び越えられる。 6 虎 🐯 Tiger 3番手。川を前後左右に跳び越えられる。 5 豹 🐆 Leopard 中堅の猛獣。川の跳躍は不可。 4 狼 🐺 Wolf 中堅の捕食者。 3 狗 🐶 Dog 中堅の下位。 2 貓 🐱 Cat 下位の動物。 1 鼠 🐭 Rat 最弱。ただし**「最強の大象(8)を倒せる」唯一の存在。また、唯一「川の中に入れる」**。
💻 技術的詳細
- React 19 + TypeScript 構成による高速で型安全な描画。
- Vite による超高速ビルド。
- Tailwind CSS を用いたレスポンシブデザイン(PCの大画面から、スマートフォンのタッチパネル操作まで最適化されています)。
- ビルドテスト(
npm run build)も実行され、エラーなしで最適化インラインHTMLファイルが生成できることを確認済みです。
Files built:
src/types/jungle.ts,src/utils/jungleEngine.ts,src/App.tsx,index.html-