Skip to content

🐛 [Bug]: Variable shadowing in getWinner() and race condition in aiTurn() in Tic-Tac-Toe #712

@Shital861

Description

@Shital861

Bug 1: Variable shadowing in getWinner() (tic-tac-toe.js)

📝 Description

The destructured variable x shadows the game symbol string "X" used throughout the codebase.

// Current (buggy)
const [a, x, c] = WINS[idx];
if (b[a] && b[a] === b[x] && b[x] === b[c]) { ... }

This creates a silent naming collision. Any future reference to x inside
getWinner() will resolve to a board index (number), not the game symbol "X"
(string), causing unpredictable behaviour.

🔄 Steps to Reproduce

1.Inspect getWinner()
2. the middle destructured variable is named x, colliding with the "X" game symbol used in the outer scope.

🎯 Expected Behavior

The getWinner() function should check all win combinations correctly. The middle index variable should be clearly named to represent a board position, with no naming collision with the game symbol "X" used in the outer scope. Future developers should be able to safely reference X (the game symbol) inside or near getWinner() without ambiguity.

❌ Actual Behavior / Error Logs

Identified via code review and live viewing — no runtime error thrown.

The destructured variable is named x, silently shadowing the
outer constant X = "X":

💻 Environment

  • OS: Windows 11
  • Python Version:3.11
  • File Name: tic-tac-toe.js

###Screenshot

Image

Bug 2: Race condition in aiTurn()

📝 Description

lockBoard(false) is called before placeMove(). This creates a brief
window where all cells are unlocked and a fast human click can fire a move
simultaneously with the AI's move.

🔄 Steps to Reproduce

  1. Start a game vs Computer (any difficulty)
  2. Wait for the AI's turn
  3. Click a cell rapidly the moment the AI finishes its delay timer
  4. Both moves may register in the same frame

🎯 Expected Behavior

When it is the AI's turn, the board should remain fully locked (all cells disabled) until the AI's move has been placed on the board. Only after placeMove() completes should cells be re-enabled for the next human turn.

❌ Actual Behavior / Error Logs

Identified via code review — not yet triggered at runtime.

lockBoard(false) fires BEFORE placeMove(), creating a window where
all empty cells are clickable while the AI move is not yet placed.

💻 Environment

  • OS: Windows 11
  • Python Version:3.11
  • File Name: tic-tac-toe.js

###Screenshot

Image
  • I am a registered GSSoC 2026 contributor.
  • I want to be assigned to fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions