From 6df3c0770f490bbba012dfeb827e354ce020d981 Mon Sep 17 00:00:00 2001 From: Vincent Palmer Date: Tue, 30 Sep 2025 16:07:32 +0200 Subject: [PATCH] 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 --- presentation_no_iframe.html | 44 +++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/presentation_no_iframe.html b/presentation_no_iframe.html index a01dd3b..c4594c6 100644 --- a/presentation_no_iframe.html +++ b/presentation_no_iframe.html @@ -526,7 +526,7 @@ -

Play on your device or scan the QR code for mobile access

+

Play on your device or scan the QR code for mobile access

@@ -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() {