PracticeSystem DesignAI EngineeringBlogsFAQsTestimonials
This is the free preview of the course. Purchase it to unlock all the contents.
1. Low Level Design
0/11 Chapters5h 50m7 Free
1. Building a game engine
0/745m7 Free
What is Low Level Design?
Free
Introduction to Low Level Desi...
Free
Setting Requirements and Objec...
Free
API and Package Structuring
Free
Parent vs. Base class function...
Free
Setting the main method
Free
Debugging the code
Free
2. Single Responsibility Principle
0/320m
3. Exploring Moves for the AI
0/326m
4. Dont Repeat Yourself
0/329m
5. Open-Closed Principle
0/428m
6. Liskov Substitution Principle
0/330m
7. Interface Segregation and Dependency Inversion
0/539m
8. Memory and Code Optimizations
0/331m
9. Test Driven Changes
0/321m
10. The Strategy Design Pattern
0/442m
11. Command and Strategy Patterns
0/333m
2. Machine Coding
0/5 Chapters5h 22m4 Free

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