Skip to content

[tic tac toe], before implementing minimax #33

Description

@sreeharshaparuchur1

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);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions