beaucarnes / fcc-project-tutorials

freeCodeCamp video project tutorials.
293 stars 416 forks source link

[tic tac toe], before implementing minimax #33

Open sreeharshaparuchur1 opened 3 years ago

sreeharshaparuchur1 commented 3 years ago

When the user clicks on tiles "3,4,5" (they should win), the AI player plays too (this is wrt the code at the end of section 5) and chooses tile number "2". On tracing the path of the programme, we see that in the script, the 'turn' function is called which is meant to "checkWin" which will return "True" (as the human player has won). But, according to the way java execution works, simply returning from that function doesn't stop the execution of the next line of code in the parent function. Thus, even though we win, the only condition being checked before the AI player playing is if the game has been drawn, not won. This can be rectified easily by changing line 31 from

if (!checkTie()) turn(bestSpot(), aiPlayer);

to

if (!checkTie() && !checkWin(origBoard, huPlayer)) turn(bestSpot(), aiPlayer);
ANURAG-PATHAK commented 3 years ago

please assign me this issue