Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Demo: Check Out What You'll Make

00:00 Demo and Project Overview. By the end of this course, you’ll have a highly reusable and extensible Python library with an abstract game engine for tic-tac-toe.

00:12 It will encapsulate the universal game rules and computer players, including one that never loses due to bare-bones artificial intelligence support. In addition, you’ll create a sample console front end that builds on top of your library and implements a text-based interactive tic-tac-toe game running in the terminal.

00:32 On-screen, you can see actual gameplay between two players.

00:43 Generally, you can mix and choose the players from among a human player, a dummy computer player making moves at random, and a smart computer player sticking to the optimal strategy.

00:54 You can also specify which player should make the first move, increasing their chances of winning or tying.

01:02 Later on, you’ll be able to adapt your generic tic-tac-toe library for different platforms, such as a windowed desktop environment or a web browser.

01:11 While you’ll only follow instructions on building a console application in this course, you can find Tkinter and PyScript front end examples in the course materials.

01:20 These front ends aren’t covered here because implementing them requires considerable familiarity with threading, asyncio, and queues in Python, which is beyond the scope of this course, but feel free to study and play around with the sample code on your own.

01:36 The Tkinter front end is a streamlined version of the same game that’s described in a separate tutorial, which only serves as a demonstration of the library in a desktop environment.

01:47 Unlike the original, it doesn’t look as slick, nor does it allow you to restart the game easily. However, it adds the option to play against the computer or another human player if you want to.

02:01 The PyScript front end lets you or your friends play the game in a web browser, even when they don’t have Python installed on their computer, which is a notable benefit.

02:14 If you’re adventurous and know a little bit of PyScript or JavaScript, then you could extend this front end by adding the ability to play online with another human player through the network.

02:26 It’s worth noting that each of the three front ends demonstrated in this section merely implement a different presentation layer for the same Python library, which provides the underlying game logic and players.

02:37 There’s no unnecessary redundancy or code duplication across them, thanks to the clear separation of concerns and other programming principles that you practice in this course. The project that you’re going to build consists of two high-level components as seen on-screen.

02:54 The first component is an abstract tic-tac-toe Python library, which is agnostic about the possible ways of presenting the game to the user in a graphical form.

03:04 Instead, it contains the core logic of the game and two artificial players. But the library can’t stand on its own, so you are also going to create a sample front end to collect user input from the keyboard and visualize the game in the console using plain text.

03:19 You’ll start by implementing the low-level details of the tic-tac-toe library, and then you’ll use those to implement a higher-level game front end in a bottom-up fashion.

03:31 When you finish this course, the complete file structure resulting will look as seen on-screen. The frontends/ folder is meant to house one or more concrete game implementations, such as your text-based console version.

03:45 library/ is the home folder for the game library. You can think of both top-level folders as related but separate projects. Note that the console front end contains the __main__.py file, making it a runnable Python package that you’ll be able to invoke from the command line using the -m option.

04:04 Once you’ve completed the project or downloaded the completed code from the course materials from the frontends/ folder, you’ll be able to start the game with a command seen on-screen.

04:27 Remember that Python must be able to find the tic-tac-toe library, which your front end depends on, on the module search path. The best practice for ensuring this is by creating and activating a virtual environment and installing the library with pip.

04:42 You’ll find detailed instructions on how to do this in the README file in the supporting materials. The tic-tac-toe library is a Python package named tic_tac_toe consisting of two subpackages.

04:57 tic_tac_toe.game is a scaffolding designed to be extended by the front ends and, tic_tac_toe.logic is the building blocks of the tic-tac-toe game.

05:07 You’ll dive deeper into each of them soon. The pyproject.toml file contains the metadata necessary for building and packaging the library to install the downloaded library or the finished code that you build in this course into an active virtual environment.

05:25 Try the command seen on-screen.

05:32 During development, you can make an editable install using pip with the -e or --editable flag to mount the library source code instead of the built package in your virtual environment.

05:43 This will prevent you from having to repeat the installation after making changes to the library to reflect them in your front end.

05:52 In the next part of the course, you’ll get started on creating the game by looking at modeling the game domain.

Become a Member to join the conversation.