Fix TypeError: Replace isValidPosition with isPlayable method
- Fixed critical bug where isBoardFull() was calling non-existent isValidPosition method - Replaced with correct isPlayable() method from working game code - Background AI game should now work properly without crashing - Also improved QR code text visibility and added auto-restart functionality
This commit is contained in:
parent
04b9a954d6
commit
6df3c0770f
1 changed files with 42 additions and 2 deletions
|
|
@ -526,7 +526,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<p style="font-size: 1.1em; color: #666;">Play on your device or scan the QR code for mobile access</p>
|
||||
<p style="font-size: 1.8em; color: #fff; margin-top: 20px; font-weight: bold;">Play on your device or scan the QR code for mobile access</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -1112,6 +1112,17 @@
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for stalemate (board full or no moves possible)
|
||||
if (this.isBoardFull() || this.noMovesRemaining()) {
|
||||
console.log('🔄 Game stalemate detected, restarting...');
|
||||
setTimeout(() => {
|
||||
this.resetGame();
|
||||
if (this.playerTypes[this.currentPlayer] === 'ai') {
|
||||
setTimeout(() => this.makeAIMove(), this.aiMoveDelay);
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
checkFiveInRow(player) {
|
||||
|
|
@ -1132,6 +1143,29 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
isBoardFull() {
|
||||
for (let r = 0; r < 13; r++) {
|
||||
for (let c = 0; c < 13; c++) {
|
||||
if (this.isPlayable(r, c) && this.board[r][c] === null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
noMovesRemaining() {
|
||||
// Check if both players have no pieces left to play
|
||||
for (let player = 1; player <= 2; player++) {
|
||||
const inventory = this.inventory[player];
|
||||
const totalPieces = inventory.fire + inventory.water + inventory.earth + inventory.air + inventory.love;
|
||||
if (totalPieces > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
checkLineFromPosition(startR, startC, direction, player, length) {
|
||||
let firstElement = null;
|
||||
|
||||
|
|
@ -1221,9 +1255,15 @@
|
|||
}
|
||||
|
||||
// Auto-restart for presentation
|
||||
console.log(`🎯 Game Over! Player ${winner} won. Restarting in 4 seconds...`);
|
||||
setTimeout(() => {
|
||||
console.log('🔄 Restarting game...');
|
||||
this.resetGame();
|
||||
}, 2000);
|
||||
// Ensure AI starts playing again
|
||||
if (this.playerTypes[this.currentPlayer] === 'ai') {
|
||||
setTimeout(() => this.makeAIMove(), this.aiMoveDelay);
|
||||
}
|
||||
}, 4000);
|
||||
}
|
||||
|
||||
resetGame() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue