Video Tutorial: Tic-Tac-Toe in Python

Tic Tac ToeTic-Tac-Toe is one of the earliest strategy games that children learn.  It has few rules that are easy to grasp which makes it an excellent game to use to learn how to program in Python.  In this tutorial, I will walk you through the process of making the game in a step-by-step fashion.  This tutorial presupposes that you have at least a passing familiarity with Python concepts such as loops, functions, and lists. Each stage includes a video tutorial (on YouTube) explaining the concepts and how to complete the program along with the actual code you can download.  The game was programmed in Python 2.7.

This tutorial will be in five stages as follows: 

STAGE I: VIDEO / CODE
  • Create the main loop
  • Print the board
  • Get the user input
  • Put the user input in the board 
 
STAGE II: VIDEO / CODE
  • Check for player win (8 Possibilities)
 
STAGE III: VIDEO / CODE
  • Create the second player (NOT THE COMPUTER)
  • Check for the second player win (8 Possibilities)
  • Check for a full board (TIE)
 
STAGE IV: VIDEO / CODE
  • Combine Stages II & III into 1 Function
    • def is_winner(board, player):
  • Create a function to check if the board is full
    • def is_board_full(board):
 
STAGE V: VIDEO / CODE
  • Creating our game AI
    • def get_computer_move(board, player):
      • Return random number
      • Make sure the random number is for an empty spot
 
ON YOUR OWN
I have left the program intentionally unfinished - it is up to you to use your skills to complete the game AI and make it as formidable an opponent as you can. Good luck!
 
UPDATED
Here are some additional videos giving you some ideas on how to program your Tic-Tac-Toe game AI.
 
Tic-Tac-Toe Optimize 1 (Computer AI): VIDEO
Tic-Tac-Toe Optimize 2 (Computer AI): VIDEO

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.

@TokyoEdTech

Poll

What LMS does your school use?: