beanz Magazine

Modelling Tic-Tac-Toe in Python

Sharat Ganapati on Flickr

A simple coding activity that creates a virtual tic-tac-toe board with pieces.

Programming a computer game lets you create your own world with your own rules. And if you break everything down and tackle each piece one at a time, even the most complex games can be simple to write. Let’s start with a classic: tic-tac-toe.

Step 1: Brainstorming

Before we pull up the code editor, let’s think about the design of our tic-tac-toe board. In a professional setting you’d look at different graphics packages, colours, animations. For now let’s stick with something simple and text based. A good tic-tac-toe board could be:

_ | _ | _
_ | _ | _
_ | _ | _

Where Xs and Os are added like so:

X | _ | O
_ | X | _
_ | _ | _

Step 2: Open the Code Editor

1. Fire up your browser and navigate to www.repl.it

 

Become a subscriber and get access to the rest of this article. Plus all our magazine articles.

Stories also include numerous links to help parents, kids, and teachers learn more. Get access today at just $15 per year!

Subscribe Today!

Also In The February 2018 Issue

In an era before telephones, a clever code was created to send messages by telegraph.

A simple coding activity that creates a virtual tic-tac-toe board with pieces.

Seven days to design, code, and debug a program with PyGame. What could go wrong?

Play with your friends or connect to Minecraft servers all around the world.

Turning scientific data into music can lead to new insights and new solutions.

Tools to help you design and print your own jewelry. Who says geeks can’t be fashionable?

Say hello to your new favorite robot: spherical, programmable, and durable. It can even swim!

The perfect language to help you transition into a new way of coding.

Create a new and improved variation of the classic 1960s board game with micro:bit.

Learn about the origin of Unix time, the calendar system used by digital devices.

Could a human brain be simulated by a computer? Would it think and feel like we do?

Links from the bottom of all the February 2018 articles, collected in one place for you to print, share, or bookmark.

Interesting stories about computer science, software programming, and technology for February 2018.