Setting the main method
What this lesson covers
This lesson adds a Main class so the turn-based game engine can actually be played. The engine starts a tic-tac-toe game, and a while loop then runs until the engine reports that the board is complete. On each turn the user is prompted to make a move, entered as a row and column, and that move is applied to the board. The computer then makes its own move, but only if the game has not already ended after the user's turn. The human player and the computer are each given a symbol, and because the human moves first, the human plays X. The computer's move comes from a suggestMove function, which at this stage has no real intelligence: it scans the tic-tac-toe board and returns a move for the first empty cell, throwing an illegal state exception if none is left. The video notes that the computer and player objects are barely used yet because the logic is so simple. When the loop ends, the game result is printed. The lesson closes by setting up the next step, which is checking whether the code works at all before critiquing its design.
- The game loop alternates user and computer moves until the engine says the game is over
- The computer moves only if the game has not ended after the user's move
- suggestMove picks the first empty cell as a placeholder for real AI
- The code should be checked for correctness before its design is critiqued