1import{j as n}from"./index-ypIK7kjN.js";import{a as T}from"./redux-vendor-BfV9BRyV.js";import{u as R}from"./react-vendor-DKynGxiw.js";const S="_kingfallRoot_1v8ot_24",K="_gameBackBtn_1v8ot_36",b={kingfallRoot:S,gameBackBtn:K},l={PAWN:"pawn",SCOUT:"scout",TOWER:"tower",KNIGHT:"knight",QUEEN:"queen"},g={PVP:"pvp",PVC:"pvc"},f={EASY:"easy",MEDIUM:"medium",HARD:"hard"},A={1:l.SCOUT,2:l.TOWER,3:l.KNIGHT,4:l.QUEEN},N={[l.PAWN]:"",[l.SCOUT]:"â",[l.TOWER]:"â ",[l.KNIGHT]:"⬡",[l.QUEEN]:"â
"},w={[l.PAWN]:"Pawn",[l.SCOUT]:"Scout",[l.TOWER]:"Tower",[l.KNIGHT]:"Knight",[l.QUEEN]:"Queen"};function x(r,e=l.PAWN){return{type:e,player:r,captures:e===l.PAWN?0:L(e),isKing:!1}}function L(r){for(const[e,t]of Object.entries(A))if(t===r)return Number.parseInt(e,10);return 0}function U(r){return r>=4?l.QUEEN:A[r]??l.PAWN}function y(r,e){return r>=0&&r<8&&e>=0&&e<8}function J(r){return r==="white"?-1:1}function I(r,e,t,i){const s=[],o=[],a=J(i.player),h=i.isKing?[-1,1]:[a];for(const d of h)for(const m of[-1,1]){const c=e+d,u=t+m;if(y(c,u)){if(r[c][u]===null)s.push({row:c,col:u,isCapture:!1});else if(r[c][u]?.player!==i.player){const v=c+d,k=u+m;y(v,k)&&r[v][k]===null&&o.push({row:v,col:k,isCapture:!0,capturedRow:c,capturedCol:u})}}}return{moves:s,captures:o}}function D(r,e,t,i){const s=[],o=[],a=[[-1,-1],[-1,1],[1,-1],[1,1]];for(const[h,d]of a){let m=1;for(;;){const c=e+h*m,u=t+d*m;if(!y(c,u))break;if(r[c][u]===null)s.push({row:c,col:u,isCapture:!1});else if(r[c][u]?.player!==i.player){o.push({row:c,col:u,isCapture:!0,capturedRow:c,capturedCol:u});break}else break;m+=1}}return{moves:s,captures:o}}function B(r,e,t,i){const s=[],o=[],a=[[-1,0],[1,0],[0,-1],[0,1]];for(const[h,d]of a){let m=1;for(;;){const c=e+h*m,u=t+d*m;if(!y(c,u))break;if(r[c][u]===null)s.push({row:c,col:u,isCapture:!1});else if(r[c][u]?.player!==i.player){o.push({row:c,col:u,isCapture:!0,capturedRow:c,capturedCol:u});break}else break;m+=1}}return{moves:s,captures:o}}function G(r,e,t,i){const s=[],o=[],a=[[-2,-1],[-2,1],[-1,-2],[-1,2],[1,-2],[1,2],[2,-1],[2,1]];for(const[h,d]of a){const m=e+h,c=t+d;y(m,c)&&(r[m][c]===null?s.push({row:m,col:c,isCapture:!1}):r[m][c]?.player!==i.player&&o.push({row:m,col:c,isCapture:!0,capturedRow:m,capturedCol:c}))}return{moves:s,captures:o}}function H(r,e,t,i){const s=[],o=[],a=[[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]];for(const[h,d]of a){let m=1;for(;;){const c=e+h*m,u=t+d*m;if(!y(c,u))break;if(r[c][u]===null)s.push({row:c,col:u,isCapture:!1});else if(r[c][u]?.player!==i.player){o.push({row:c,col:u,isCapture:!0,capturedRow:c,capturedCol:u});break}else break;m+=1}}return{moves:s,captures:o}}function M(r,e,t){const i=r[e][t];if(!i)return{moves:[],captures:[]};switch(i.type){case l.PAWN:return I(r,e,t,i);case l.SCOUT:return D(r,e,t,i);case l.TOWER:return B(r,e,t,i);case l.KNIGHT:return G(r,e,t,i);case l.QUEEN:return H(r,e,t,i);default:return{moves:[],captures:[]}}}function $(r,e,t){const i=r[e][t];if(!i||i.type!==l.PAWN)return!1;const{captures:s}=I(r,e,t,i);return s.length>0}function C(r,e){const t=[];for(let i=0;i<8;i+=1)for(let s=0;s<8;s+=1){const o=r[i][s];if(o&&o.player===e){const{captures:a}=M(r,i,s);a.length>0&&t.push({row:i,col:s,captures:a})}}return t}function W(r,e){for(let t=0;t<8;t+=1)for(let i=0;i<8;i+=1){const s=r[t][i];if(s&&s.player===e){const{moves:o,captures:a}=M(r,t,i);if(o.length>0||a.length>0)return!0}}return!1}function P(r,e){let t=0;for(let i=0;i<8;i+=1)for(let s=0;s<8;s+=1)r[i][s]&&r[i][s]?.player===e&&(t+=1);return t}function E(r,e){const t={[l.PAWN]:0,[l.SCOUT]:0,[l.TOWER]:0,[l.KNIGHT]:0,[l.QUEEN]:0};for(let i=0;i<8;i+=1)for(let s=0;s<8;s+=1){const o=r[i][s];o&&o.player===e&&(t[o.type]+=1)}return t}function j(r,e){for(let t=0;t<8;t+=1)for(let i=0;i<8;i+=1){const s=r[t][i];if(s&&s.player===e&&s.isKing)return{row:t,col:i,piece:s}}return null}function O(r,e){const t=[l.QUEEN,l.KNIGHT,l.TOWER,l.SCOUT,l.PAWN];for(const i of t)for(let s=0;s<8;s+=1)for(let o=0;o<8;o+=1){const a=r[s][o];if(a&&a.player===e&&a.type===i&&!a.isKing)return{row:s,col:o,piece:a}}return null}class V{difficulty;player;constructor(e=f.MEDIUM){this.difficulty=e,this.player="black"}setDifficulty(e){this.difficulty=e}getBestMove(e){const t=this.getValidMoves(e);
1if(!t||t.length===0)return console.log("AI: No valid moves available"),null;switch(console.log("AI: Found",t.length,"valid moves"),this.difficulty){case f.EASY:return this.pickRandom(t);case f.MEDIUM:return this.pickMedium(e,t);case f.HARD:return this.pickHard(e,t);default:return this.pickRandom(t)}}getValidMoves(e){const t=e.getState(),i=[],s=C(t.board,this.player),o=s.length>0;for(let a=0;a<8;a+=1)for(let h=0;h<8;h+=1){const d=t.board[a][h];if(!d||d.player!==this.player||o&&!s.some(v=>v.row===a&&v.col===h))continue;const{moves:m,captures:c}=M(t.board,a,h);if(o)for(const u of c)i.push({fromRow:a,fromCol:h,toRow:u.row,toCol:u.col,isCapture:!0,capturedRow:u.capturedRow,capturedCol:u.capturedCol});else{for(const u of m)i.push({fromRow:a,fromCol:h,toRow:u.row,toCol:u.col,isCapture:!1});for(const u of c)i.push({fromRow:a,fromCol:h,toRow:u.row,toCol:u.col,isCapture:!0,capturedRow:u.capturedRow,capturedCol:u.capturedCol})}}return i}pickRandom(e){return e[Math.floor(Math.random()*e.length)]}pickMedium(e,t){const i=e.getState(),s=t.map(h=>{let d=Math.random()*2;if(h.isCapture){d+=20;const c=i.board[h.capturedRow??0][h.capturedCol??0];c&&(c.isKing&&(d+=50),c.type===l.QUEEN?d+=25:c.type===l.KNIGHT?d+=15:c.type===l.TOWER?d+=12:c.type===l.SCOUT&&(d+=8))}d+=(h.toRow-h.fromRow)*2;const m=Math.abs(h.toCol-3.5);return d+=4-m,{move:h,score:d}});s.sort((h,d)=>d.score-h.score);const o=Math.min(3,s.length),a=s.slice(0,o);return a[Math.floor(Math.random()*a.length)].move}pickHard(e,t){const i=e.getState(),s=t.map(o=>{let a=Math.random();if(o.isCapture){a+=30;const m=i.board[o.capturedRow??0][o.capturedCol??0];m&&(m.isKing&&(a+=100),m.type===l.QUEEN?a+=30:m.type===l.KNIGHT?a+=20:m.type===l.TOWER?a+=15:m.type===l.SCOUT&&(a+=10))}a+=(o.toRow-o.fromRow)*3,o.toRow===7&&(a+=25);const h=Math.abs(o.toCol-3.5)+Math.abs(o.toRow-3.5);a+=(7-h)*.5,(o.toCol===0||o.toCol===7)&&(a-=2);const d=i.board[o.fromRow][o.fromCol];return d&&(d.type===l.QUEEN||d.type===l.KNIGHT)&&this.isPositionUnderAttack(i.board,o.toRow,o.toCol)&&(a-=15),{move:o,score:a}});return s.sort((o,a)=>a.score-o.score),s.length>1&&Math.random()<.1?s[1].move:s[0].move}isPositionUnderAttack(e,t,i){const s=[[-1,-1],[-1,1],[1,-1],[1,1]];for(const[o,a]of s){const h=t+o,d=i+a;if(h>=0&&h<8&&d>=0&&d<8){const m=e[h][d];if(m&&m.player==="white"){const c=t-o,u=i-a;if(c>=0&&c<8&&u>=0&&u<8&&!e[c][u])return!0}}}return!1}}class Q{board;currentPlayer;selectedPiece;validMoves;mustCapture;inMultiJump;multiJumpPiece;history;positionHistory;gameOver;winner;gameOverReason;gameMode;ai;aiThinking;listeners;constructor(){this.board=this.createEmptyBoard(),this.currentPlayer="white",this.selectedPiece=null,this.validMoves=[],this.mustCapture=!1,this.inMultiJump=!1,this.multiJumpPiece=null,this.history=[],this.positionHistory=[],this.gameOver=!1,this.winner=null,this.gameOverReason="",this.gameMode=g.PVP,this.ai=null,this.aiThinking=!1,this.listeners={move:[],capture:[],evolution:[],kingCrowned:[],kingCaptured:[],gameOver:[],turnChange:[],stateChange:[],aiThinking:[]}}setGameMode(e,t=f.MEDIUM){this.gameMode=e,e===g.PVC?this.ai=new V(t):this.ai=null}setAIDifficulty(e){this.ai&&this.ai.setDifficulty(e)}isAITurn(){return this.gameMode===g.PVC&&!!this.ai&&this.currentPlayer===this.ai?.player&&!this.gameOver}getAITimeout(){if(!this.ai)return 3e3;switch(this.ai.difficulty){case f.EASY:return 2e3;case f.MEDIUM:return 4e3;case f.HARD:return 6e3;default:return 3e3}}forceStopAIThinking(){if(console.log("AI timeout - forcing stop"),this.aiThinking=!1,this.emit("aiThinking",{thinking:!1}),this.isAITurn()&&!this.gameOver&&this.ai){const e=this.ai.getValidMoves(this);if(e&&e.length>0){const t=e[Math.floor(Math.random()*e.length)];console.log("AI fallback - making random move:",t),this.selectedPiece={row:t.fromRow,col:t.fromCol},this.calculateValidMoves(t.fromRow,t.fromCol),this.moveTo(t.toRow,t.toCol)}}this.emit("stateChange")}makeAIMove(){if(!this.isAITurn()||this.aiThinking||this.gameOver||!this.ai){console.log("AI move skipped:",{isAITurn:this.isAITurn(),aiThinking:this.aiThinking,gameOver:this.gameOver});return}
1console.log("AI starting move..."),this.aiThinking=!0,this.emit("aiThinking",{thinking:!0}),this.emit("stateChange");const e=this.getAITimeout(),t=window.setTimeout(()=>{this.aiThinking&&this.forceStopAIThinking()},e);window.setTimeout(()=>{try{const i=this.ai?.getBestMove(this);if(console.log("AI chose move:",i),i){const s=this.selectPiece(i.fromRow,i.fromCol);console.log("AI selected piece:",s),s?window.setTimeout(()=>{window.clearTimeout(t);const o=this.moveTo(i.toRow,i.toCol);console.log("AI moved:",o),this.aiThinking=!1,this.emit("aiThinking",{thinking:!1}),this.emit("stateChange"),this.inMultiJump&&this.isAITurn()&&(console.log("AI continuing multi-jump..."),window.setTimeout(()=>this.makeAIMove(),400))},250):(window.clearTimeout(t),console.log("AI failed to select piece"),this.aiThinking=!1,this.emit("aiThinking",{thinking:!1}),this.emit("stateChange"))}else window.clearTimeout(t),console.log("AI has no valid moves"),this.aiThinking=!1,this.emit("aiThinking",{thinking:!1}),this.emit("stateChange")}catch(i){window.clearTimeout(t),console.error("AI error:",i),this.aiThinking=!1,this.emit("aiThinking",{thinking:!1}),this.emit("stateChange")}},50)}createEmptyBoard(){return Array.from({length:8},()=>Array(8).fill(null))}initializeBoard(){this.board=this.createEmptyBoard();for(let e=0;e<3;e+=1)for(let t=0;t<8;t+=1)(e+t)%2===1&&(this.board[e][t]=x("black"));for(let e=5;e<8;e+=1)for(let t=0;t<8;t+=1)(e+t)%2===1&&(this.board[e][t]=x("white"));this.currentPlayer="white",this.selectedPiece=null,this.validMoves=[],this.mustCapture=!1,this.inMultiJump=!1,this.multiJumpPiece=null,this.history=[],this.positionHistory=[],this.gameOver=!1,this.winner=null,this.gameOverReason="",this.checkForForcedCaptures(),this.emit("stateChange")}on(e,t){this.listeners[e]&&this.listeners[e].push(t)}emit(e,t={}){this.listeners[e]&&this.listeners[e].forEach(i=>i(t))}selectPiece(e,t){if(this.gameOver||this.isAITurn()&&!this.aiThinking)return!1;const i=this.board[e][t];return this.inMultiJump?this.multiJumpPiece&&this.multiJumpPiece.row===e&&this.multiJumpPiece.col===t?(this.selectedPiece={row:e,col:t},this.calculateValidMoves(e,t),!0):!1:!i||i.player!==this.currentPlayer||this.mustCapture&&!C(this.board,this.currentPlayer).some(a=>a.row===e&&a.col===t)?!1:(this.selectedPiece={row:e,col:t},this.calculateValidMoves(e,t),this.emit("stateChange"),!0)}calculateValidMoves(e,t){const{moves:i,captures:s}=M(this.board,e,t);this.mustCapture||this.inMultiJump?this.validMoves=s:this.validMoves=[...i,...s]}deselectPiece(){this.selectedPiece=null,this.validMoves=[],this.emit("stateChange")}moveTo(e,t){if(this.gameOver||!this.selectedPiece)return!1;const i=this.validMoves.find(c=>c.row===e&&c.col===t);if(!i)return!1;const s=this.selectedPiece.row,o=this.selectedPiece.col,a=this.board[s][o];if(!a)return!1;this.saveState();let h=!1,d=null;if(i.isCapture&&(d=this.board[i.capturedRow??0][i.capturedCol??0],this.board[i.capturedRow??0][i.capturedCol??0]=null,a.captures+=1,h=!0),this.board[e][t]=a,this.board[s][o]=null,h&&d){d.isKing&&this.handleKingCapture(d.player);const c=a.type,u=U(a.captures);u!==c&&(a.type=u,this.emit("evolution",{piece:a,oldType:c,newType:u,row:e,col:t})),this.emit("capture",{capturer:a,captured:d,from:{row:s,col:o},to:{row:e,col:t}})}const m=a.player==="white"?0:7;return e===m&&!a.isKing&&(j(this.board,a.player)||(a.isKing=!0,this.emit("kingCrowned",{piece:a,row:e,col:t}))),this.emit("move",{piece:a,from:{row:s,col:o},to:{row:e,col:t},captured:h}),h&&a.type===l.PAWN&&$(this.board,e,t)?(this.inMultiJump=!0,this.multiJumpPiece={row:e,col:t},this.selectedPiece={row:e,col:t},this.calculateValidMoves(e,t),this.emit("stateChange"),!0):(this.endTurn(),!0)}handleKingCapture(e){this.emit("kingCaptured",{player:e});const t=O(this.board,e);t&&(t.piece.isKing=!0,this.emit("kingCrowned",{piece:t.piece,row:t.row,col:t.col}))}endTurn(){this.selectedPiece=null,this.validMoves=[],this.inMultiJump=!1,this.multiJumpPiece=null,this.currentPlayer=this.currentPlayer==="white"?"black":"white",!this.checkGameOver()&&(this.checkForForcedCaptures(),this.recordPosition(),this.emit
1("turnChange",{player:this.currentPlayer}),this.emit("stateChange"),this.isAITurn()&&window.setTimeout(()=>this.makeAIMove(),500))}checkForForcedCaptures(){const e=C(this.board,this.currentPlayer);this.mustCapture=e.length>0}checkGameOver(){const e=this.currentPlayer;return P(this.board,e)===0?(this.gameOver=!0,this.winner=this.currentPlayer==="white"?"black":"white",this.gameOverReason=`${this.winner} wins! All opponent pieces captured.`,this.emit("gameOver",{winner:this.winner,reason:this.gameOverReason}),!0):W(this.board,e)?!j(this.board,e)&&!O(this.board,e)?(this.gameOver=!0,this.winner=this.currentPlayer==="white"?"black":"white",this.gameOverReason=`${this.winner} wins! Opponent's king captured with no succession.`,this.emit("gameOver",{winner:this.winner,reason:this.gameOverReason}),!0):this.checkThreefoldRepetition()?(this.gameOver=!0,this.winner=null,this.gameOverReason="Draw by threefold repetition.",this.emit("gameOver",{winner:null,reason:this.gameOverReason}),!0):!1:(this.gameOver=!0,this.winner=this.currentPlayer==="white"?"black":"white",this.gameOverReason=`${this.winner} wins! Opponent cannot move.`,this.emit("gameOver",{winner:this.winner,reason:this.gameOverReason}),!0)}recordPosition(){const e=this.getBoardPositionKey();this.positionHistory.push(e)}getBoardPositionKey(){let e=this.currentPlayer;for(let t=0;t<8;t+=1)for(let i=0;i<8;i+=1){const s=this.board[t][i];s&&(e+=`|${t},${i},${s.player},${s.type},${s.isKing}`)}return e}checkThreefoldRepetition(){const e=this.getBoardPositionKey();return this.positionHistory.filter(i=>i===e).length>=3}saveState(){this.history.push({board:JSON.parse(JSON.stringify(this.board)),currentPlayer:this.currentPlayer,mustCapture:this.mustCapture,inMultiJump:this.inMultiJump,multiJumpPiece:this.multiJumpPiece?{...this.multiJumpPiece}:null,positionHistory:[...this.positionHistory]}),this.history.length>50&&this.history.shift()}undo(){if(this.history.length===0||this.gameOver||this.aiThinking)return!1;this.gameMode===g.PVC&&this.currentPlayer==="white"&&this.history.length>=2&&this.history.pop();const e=this.history.pop();return e?(this.board=e.board,this.currentPlayer=e.currentPlayer,this.mustCapture=e.mustCapture,this.inMultiJump=e.inMultiJump,this.multiJumpPiece=e.multiJumpPiece,this.positionHistory=e.positionHistory,this.selectedPiece=null,this.validMoves=[],this.emit("stateChange"),!0):!1}getState(){return{board:this.board,currentPlayer:this.currentPlayer,selectedPiece:this.selectedPiece,validMoves:this.validMoves,mustCapture:this.mustCapture,inMultiJump:this.inMultiJump,multiJumpPiece:this.multiJumpPiece,gameOver:this.gameOver,winner:this.winner,gameOverReason:this.gameOverReason,piecesThatMustCapture:this.mustCapture?C(this.board,this.currentPlayer):[],whitePieces:P(this.board,"white"),blackPieces:P(this.board,"black"),whiteEvolutions:E(this.board,"white"),blackEvolutions:E(this.board,"black"),gameMode:this.gameMode,aiThinking:this.aiThinking,isAITurn:this.isAITurn()}}newGame(){this.initializeBoard(),this.emit("stateChange")}}function p(r){const e=document.getElementById(r);if(!e)throw new Error(`Missing element: ${r}`);return e}class q{game;boardElement;messageElement;evolutionModal;gameOverModal;modeModal;aiThinkingElement;selectedDifficulty;constructor(e){this.game=e,this.boardElement=p("board"),this.messageElement=p("game-message"),this.evolutionModal=p("evolution-modal"),this.gameOverModal=p("game-over-modal"),this.modeModal=p("mode-selection-modal"),this.aiThinkingElement=p("ai-thinking"),this.selectedDifficulty=f.MEDIUM,this.setupEventListeners(),this.setupGameListeners(),this.setupModeSelection()}setupEventListeners(){p("new-game").addEventListener("click",()=>{this.showModeSelection()}),p("undo").addEventListener("click",()=>{this.game.undo()}),p("play-again").addEventListener("click",()=>{this.showModeSelection(),this.hideGameOverModal()}),this.evolutionModal.addEventListener("click",e=>{e.target===this.evolutionModal&&this.hideEvolutionModal()})}setupModeSelection(){const e=p("mode-pvp"),t=p("mode-pvc"),i=p("mode-screen"),s=p("difficulty-screen"),o=document.querySelectorAll(".btn-diff-full"),a=p("back-to-modes");e.addEventListener("click",()=>{this.game.setGameMode(g.PVP),this.updatePlayerNames(!1),this.hideModeSelection(),this.game.initializeBoard(),this.render()}),t.addEventListener("click",()=>{i.style.display="none",s.style.display="block"}),o.forEach(h=>{h.addEventListener("click",()=>{const d=h.dataset.difficulty;d&&(this.selectedDifficulty=d,this.game.setGameMode(g.PVC,this.selectedDifficulty),this.updatePlayerNames(!0),this.hideModeSelection(),this.game.initializeBoard(),this.render())})}),a.addEventListener("click",()=>{s.style.display="none",i.style.display="block"})}updatePlayerNames(e){const t=p("black-player-name");if(e){const i=this.selectedDifficulty.charAt(0).toUpperCase()+this.selectedDifficulty.slice(1);t.textContent=`Computer (${i})`}else t.textContent="Black"}showModeSelection(){p("mode-screen").style.display="block",p("difficulty-screen").style.display="none",this.modeModal.classList.add("active")}hideModeSelection(){this.modeModal.classList.remove("active")}setupGameListeners(){this.game.on("stateChange",()=>this.render()),this.game.on("evolution",e=>{this.showEvolutionModal(e),window.setTimeout(()=>this.hideEvolutionModal(),1500)}),this.game.on("kingCrowned",e=>{this.showMessage(`${e.piece.player}'s piece became King!`,"info")}),this.game.on("kingCaptured",e=>{this.showMessage(`${e.player}'s King was captured!`,"warning")}),this.game.on("gameOver",e=>{window.setTimeout(()=>this.showGameOverModal(e),500)}),this.game.on("turnChange",e=>{this.updateTurnIndicators(e.player)}),this.game.on("aiThinking",e=>{this.showAIThinking(e.thinking)})}showAIThinking(e){this.aiThinkingElement&&(this.aiThinkingElement.style.display=e?"block":"none")}render(){const e=this.game.getState();this.boardElement.innerHTML="",this.boardElement.classList.toggle("ai-turn",e.isAITurn||e.aiThinking),this.showAIThinking(e.aiThinking);for(let t=0;t<8;t+=1)for(let i=0;i<8;i+=1){const s=this.createSquare(t,i,e);this.boardElement.appendChild(s)}this.updatePlayerPanels(e),this.updateMessage(e)}createSquare(e,t,i){const s=document.createElement("div");s.className="square",s.classList.add((e+t)%2===0?"light":"dark"),s.dataset.row=String(e),s.dataset.col=String(t),i.selectedPiece&&i.selectedPiece.row===e&&i.selectedPiece.col===t&&s.classList.add("selected");const o=i.validMoves.find(h=>h.row===e&&h.col===t);o&&s.classList.add(o.isCapture?"capture-move":"valid-move"),i.mustCapture&&i.piecesThatMustCapture.some(d=>d.row===e&&d.col===t)&&s.classList.add("must-capture");const a=i.board[e][t];if(a){const h=this.createPiece(a,e,t,i);s.appendChild(h)}return s.addEventListener("click",()=>this.handleSquareClick(e,t)),s}createPiece(e,t,i,s){const o=document.createElement("div");o.className="piece",o.classList.add(e.player),e.isKing&&o.classList.add("king"),s.selectedPiece&&s.selectedPiece.row===t&&s.selectedPiece.col===i&&o.classList.add("selected");const a=document.createElement("span");return a.className="piece-symbol",a.textContent=N[e.type],o.appendChild(a),o.title=`${w[e.type]} (${e.captures} captures)${e.isKing?" - KING":""}`,o}handleSquareClick(e,t){const i=this.game.getState();if(i.gameOver||i.isAITurn||i.aiThinking)return;
1if(i.selectedPiece&&i.validMoves.find(a=>a.row===e&&a.col===t)){this.game.moveTo(e,t);return}const s=i.board[e][t];s&&s.player===i.currentPlayer?i.selectedPiece&&i.selectedPiece.row===e&&i.selectedPiece.col===t?i.inMultiJump||this.game.deselectPiece():this.game.selectPiece(e,t):i.selectedPiece&&!i.inMultiJump&&this.game.deselectPiece()}updatePlayerPanels(e){p("white-pieces").textContent=`${e.whitePieces} pieces`,p("black-pieces").textContent=`${e.blackPieces} pieces`,this.updateTurnIndicators(e.currentPlayer),this.updateEvolutionTracker("white",e.whiteEvolutions),this.updateEvolutionTracker("black",e.blackEvolutions)}updateTurnIndicators(e){p("white-turn").classList.toggle("active",e==="white"),p("black-turn").classList.toggle("active",e==="black")}updateEvolutionTracker(e,t){const i=document.querySelector(`#${e}-evolutions .evolution-list`);if(!i)return;i.innerHTML="";const s=[l.SCOUT,l.TOWER,l.KNIGHT,l.QUEEN];for(const o of s)if(t[o]>0){const a=document.createElement("div");a.className="evolution-badge",a.innerHTML=`<span>${N[o]}</span><span>${t[o]}</span>`,a.title=`${t[o]} ${w[o]}(s)`,i.appendChild(a)}i.children.length===0&&(i.innerHTML='<span style="color: var(--text-secondary); font-size: 0.8rem;">None yet</span>')}updateMessage(e){if(e.gameOver){this.showMessage(e.gameOverReason,"info");return}if(e.aiThinking){this.showMessage("Computer is thinking...","info");return}if(e.inMultiJump){const t=e.isAITurn?"Computer":"You";this.showMessage(`Multi-jump! ${t} must continue capturing.`,"warning");return}if(e.mustCapture){e.isAITurn?this.showMessage("Computer's turn - Must capture!","warning"):this.showMessage(`${e.currentPlayer}'s turn - Must capture!`,"warning");return}e.isAITurn?this.showMessage("Computer's turn",""):this.showMessage(`${e.currentPlayer}'s turn`,"")}showMessage(e,t=""){this.messageElement.textContent=e,this.messageElement.className="game-message",t&&this.messageElement.classList.add(t)}showEvolutionModal(e){const t=p("evolution-text"),i=p("evolution-animation");t.textContent=`${w[e.oldType]} evolved into ${w[e.newType]}!`,i.textContent=N[e.newType],i.style.color=e.newType===l.QUEEN?"#ffd700":e.newType===l.KNIGHT?"#4caf50":e.newType===l.TOWER?"#2196f3":"#9c27b0",this.evolutionModal.classList.add("active")}hideEvolutionModal(){this.evolutionModal.classList.remove("active")}showGameOverModal(e){const t=p("winner-text"),i=p("game-over-reason"),s=this.game.getState();e.winner?s.gameMode===g.PVC?e.winner==="white"?(t.textContent="You Win!",t.style.color="#4caf50"):(t.textContent="Computer Wins!",t.style.color="#e94560"):(t.textContent=`${e.winner.charAt(0).toUpperCase()+e.winner.slice(1)} Wins!`,t.style.color=e.winner==="white"?"#f0d9b5":"#333"):(t.textContent="Draw!",t.style.color="#888"),i.textContent=e.reason,this.gameOverModal.classList.add("active")}hideGameOverModal(){this.gameOverModal.classList.remove("active")}}function Y(){const r=T.useRef(!1),e=R();return T.useEffect(()=>{if(r.current)return;r.current=!0;const t=new Q;return new q(t),()=>{}},[]),n.jsxs("section",{className:b.kingfallRoot,children:[n.jsx("button",{type:"button",className:b.gameBackBtn,onClick:()=>e("/games"),children:"â Back to Games"}),n.jsxs("div",{className:"game-container",children:[n.jsxs("header",{className:"game-header",children:[n.jsx("h1",{children:"Kingfall"}),n.jsx("p",{className:"subtitle",children:"Chess meets Checkers"})]}),n.jsxs("div",{className:"game-layout",children:[n.jsxs("aside",{className:"player-panel player-black",children:[n.jsx("h2",{children:n.jsx("span",{id:"black-player-name",children:"Black"})}),n.jsxs("div",{className:"player-info",children:[n.jsx("div",{className:"turn-indicator",id:"black-turn"}),n.jsx("div",{className:"piece-count",id:"black-pieces",children:"12 pieces"})]}),n.jsx("div",{className:"ai-thinking",id:"ai-thinking",style:{display:"none"},children:n.jsx("span",{className:"thinking-dots",children:"Thinking"})}),n.jsxs("div",{className:"evolution-tracker",id:"black-evolutions",children:[n.jsx("h3",{children:"Evolved Pieces"}),n.jsx("div",{className:"evolution-list"})]})]}),n.jsxs("main",{className:"board-container",children:[n.jsx("div",{className:"board",id:"board"}),n.jsx("div",{className:"game-message",id:"game-message"})]}),n.jsxs("aside",{className:"player-panel player-white",children:[n.jsx("h2",{children:"White"}),n.jsxs("div",{className:"player-info",children:[n.jsx("div",{className:"turn-indicator active",id:"white-turn"}),n.jsx("div",{className:"piece-count",id:"white-pieces",children:"12 pieces"})]}),n.jsxs("div",{className:"evolution-tracker",id:"white-evolutions",children:[n.jsx("h3",{children:"Evolved Pieces"}),n.jsx("div",{className:"evolution-list"})]})]})]}),n.jsxs("div",{className:"controls",children:[n.jsx("button",{id:"new-game",className:"btn btn-primary",type:"button",children:"New Game"}),n.jsx("button",{id:"undo",className:"btn btn-secondary",type:"button",children:"Undo"})]}),n.jsxs("div",{className:"rules-panel",children:[n.jsx("h3",{children:"Evolution Guide"}),n.jsxs("div",{className:"evolution-guide",children:[n.jsxs("div",{className:"evolution-step",children:[n.jsx("span",{className:"piece-icon pawn-icon"}),n.jsx("span",{className:"arrow",children:"â"}),n.jsx("span",{className:"capture-count",children:"1 capture"}),n.jsx("span",{className:"arrow",children:"â"}),n.jsx("span",{className:"piece-icon scout-icon"}
1),n.jsx("span",{className:"piece-name",children:"Scout (diagonal)"})]}),n.jsxs("div",{className:"evolution-step",children:[n.jsx("span",{className:"piece-icon scout-icon"}),n.jsx("span",{className:"arrow",children:"â"}),n.jsx("span",{className:"capture-count",children:"2 captures"}),n.jsx("span",{className:"arrow",children:"â"}),n.jsx("span",{className:"piece-icon tower-icon"}),n.jsx("span",{className:"piece-name",children:"Tower (orthogonal)"})]}),n.jsxs("div",{className:"evolution-step",children:[n.jsx("span",{className:"piece-icon tower-icon"}),n.jsx("span",{className:"arrow",children:"â"}),n.jsx("span",{className:"capture-count",children:"3 captures"}),n.jsx("span",{className:"arrow",children:"â"}),n.jsx("span",{className:"piece-icon knight-icon"}),n.jsx("span",{className:"piece-name",children:"Knight (L-shape)"})]}),n.jsxs("div",{className:"evolution-step",children:[n.jsx("span",{className:"piece-icon knight-icon"}),n.jsx("span",{className:"arrow",children:"â"}),n.jsx("span",{className:"capture-count",children:"4 captures"}),n.jsx("span",{className:"arrow",children:"â"}),n.jsx("span",{className:"piece-icon queen-icon"}),n.jsx("span",{className:"piece-name",children:"Queen (any direction)"})]})]})]})]}),n.jsx("div",{className:"modal",id:"evolution-modal",children:n.jsxs("div",{className:"modal-content",children:[n.jsx("h2",{children:"Evolution!"}),n.jsx("p",{id:"evolution-text"}),n.jsx("div",{className:"evolution-animation",id:"evolution-animation"})]})}),n.jsx("div",{className:"modal",id:"game-over-modal",children:n.jsxs("div",{className:"modal-content",children:[n.jsx("h2",{id:"winner-text"}),n.jsx("p",{id:"game-over-reason"}),n.jsx("button",{id:"play-again",className:"btn btn-primary",type:"button",children:"Play Again"})]})}),n.jsxs("div",{className:"modal active",id:"mode-selection-modal",children:[n.jsxs("div",{className:"modal-content mode-selection",id:"mode-screen",children:[n.jsx("h2",{children:"Select Game Mode"}),n.jsxs("div",{className:"mode-buttons",children:[n.jsxs("button",{id:"mode-pvp",className:"btn btn-mode",type:"button",children:[n.jsx("span",{className:"mode-icon",children:"ð¥"}),n.jsx("span",{className:"mode-title",children:"Player vs Player"}),n.jsx("span",{className:"mode-desc",children:"Play against a friend"})]}),n.jsxs("button",{id:"mode-pvc",className:"btn btn-mode",type:"button",children:[n.jsx("span",{className:"mode-icon",children:"ð¤"}),n.jsx("span",{className:"mode-title",children:"Player vs Computer"}),n.jsx("span",{className:"mode-desc",children:"Challenge the AI"})]})]})]}),n.jsxs("div",{className:"modal-content difficulty-screen",id:"difficulty-screen",style:{display:"none"},children:[n.jsx("h2",{children:"Select Difficulty"}),n.jsxs("div",{className:"difficulty-buttons-full",children:[n.jsxs("button",{className:"btn btn-diff-full","data-difficulty":"easy",type:"button",children:[n.jsx("span",{className:"diff-icon",children:"ð"}),n.jsx("span",{className:"diff-title",children:"Easy"}),n.jsx("span",{className:"diff-desc",children:"Random moves"})]}),n.jsxs("button",{className:"btn btn-diff-full","data-difficulty":"medium",type:"button",children:[n.jsx("span",{className:"diff-icon",children:"ð¤"}),n.jsx("span",{className:"diff-title",children:"Medium"}),n.jsx("span",{className:"diff-desc",children:"Basic strategy"})]}),n.jsxs("button",{className:"btn btn-diff-full","data-difficulty":"hard",type:"button",children:[n.jsx("span",{className:"diff-icon",children:"ð"}),n.jsx("span",{className:"diff-title",children:"Hard"}),n.jsx("span",{className:"diff-desc",children:"Advanced AI"})]})]}),n.jsx("button",{id:"back-to-modes",className:"btn btn-secondary",type:"button",children:"â Back"})]})]})]})}export{Y as KingfallPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.