Skip to content

Fix segmentation fault in TicTacToe minimax due to incorrect board state handling#195

Open
satyajit1288 wants to merge 1 commit into
ashishps1:mainfrom
satyajit1288:fix/tictactoe-minimax-state
Open

Fix segmentation fault in TicTacToe minimax due to incorrect board state handling#195
satyajit1288 wants to merge 1 commit into
ashishps1:mainfrom
satyajit1288:fix/tictactoe-minimax-state

Conversation

@satyajit1288
Copy link
Copy Markdown

Problem

The TicTacToe implementation was causing a segmentation fault during the computer's turn.

Root Cause

The minimax() function was operating on the shared Game::board instead of using simulated board states during recursive evaluation. This caused incorrect recursion behavior and eventual stack overflow.

Solution

  • Updated minimax() to accept Board state as a parameter.
  • Ensured recursive calls operate on copied board instances.
  • Removed dependency on shared mutable Game::board during simulation.

Impact

  • Prevents segmentation fault during computer's turn
  • Ensures correct state isolation in recursive minimax() evaluation
  • Improves correctness and robustness of move simulation

- Passed Board state as parameter to minimax()
- Removed dependency on shared Game::board during recursion
- Prevented infinite recursion causing stack overflow
- Ensured proper simulation of board states during move calculation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant