Vous consultez actuellement le France version du site.
Voulez-vous passer à votre site local ?
12 TEMPS DE LECTURE MIN

PYTHON

Developing Noughts and Crosses in Python

Calvin Robinson details how to program the classic strategy game.

OUR EXPERT

Calvin Robinson is a former assistant principal and computer science teacher with a degree in computer games design and programming.

During this series of tutorials we’ve been using Python to develop a range of retro video games. Python is an incredibly versatile high-level programming language with a relatively simple syntax; it suits our needs.

Over the past few issues we’ve built a lunar space module landing game, a side-scrolling platformer, Pac-Man, the Game of Life and a 2D shooter. This issue we’ll build a very recognisable minigame, with challenges for those who want to take things a step further.

Before we begin, we’ll need to make sure we have the latest version of Python 3 installed. For everyone running a Debian-based distro this is as simple as sudo apt-get install python3 , after a brief sudo apt-get update , of course.

The beauty of Python is that we can use any text-based editor to work in: nano, emacs, vim and so on. Simply create a file with the extension .py and you’re good to go. The terminal command python3 before the name of the file will execute it. If you prefer a graphical user interface then there’s always the default IDLE. When launching Python3 IDLE always remember to select File>New File and type in the script window, rather than the shell. Python’s shell is a real-time development tool for testing commands. The script window offers save and edit functionality, and pressing F5 will do both simultaneously.

X marks the spot

Our game this issue is Tic Tac Toe, also known as Noughts and Crosses. For those unfamiliar, a three-bythree grid is drawn out and two players take it in turns to drawn their mark attempting to create a row of three. Player one is usually a cross ‘X’ and player two is a circle ‘O’. The first successful combination of three Xs or Os in a row is a win, including diagonal lines. Interestingly, you’re twice as likely to win as an X, so you’re definitely better off going first. For that reason, Tic Tac Toe is usually played on a ‘best of three’ rotation, taking turns to play Xs and Os each game.

Let’s begin. Start a new Python file, whether in a text editor or IDLE, and import Turtle graphics.

Débloquez cet article et bien plus encore avec
Vous pouvez en profiter :
Découvrez l'intégralité de cette édition
Accès instantané à plus de 600 titres
Des milliers d'anciens numéros
Pas de contrat ni d'engagement
Essayer pour €1.09
S'ABONNER
30 jours d'accès, puis seulement €11,99 / mois. Résiliation à tout moment. Nouveaux abonnés uniquement.


En savoir plus
Pocketmags Plus
Pocketmags Plus

Cet article est tiré de...


View Issues
Linux Format
November 2020
VOIR EN MAGASIN

Autres articles dans ce numéro


In This Issue
Linux is fun!
Some people have gained the impression that Linux might not
NEWS
Questions over Mozilla CEO remuneration
Discussion sparked in the community in September on the subject
Apple Swift System
Swift was brought out by Apple in 2014 to replace
Open source PowerPC laptop
Since IBM open sourced its PowerPC processors (see Newsdesk, LXF255)
HEAD IN THE CLOUD
Keith Edmunds is MD of Tiger Computing Ltd, which provides
STREAMY LOVER
Earlier in September, the much-anticipated release of GStreamer 1.18 was
Dell’s Linux laptops refreshed
We’ve been running plenty of stories of manufacturers releasing Linux-first
Microsoft Edge
A after teasing the possibility of bringing its newly Chromium-powered
Gnome turns v40
Gnome gets a hard time over its desktop but as
Distro watch
With its cutting-edge release KDE Plasma desktop and themed Qt-based
KINGS AND DATABASES
Are architects the new kingmakers of the database world? To
MOORE PROBLEMS
Jon Masters has been involved with Linux for over 22
Kernel Watch
Paul McKenney posted a thread titled “Litmus test for question
REVIEWS
Nvidia GeForce NOW
We weren’t hugely impressed with Google’s Stadia game streaming service,
Enos OS 0.4
A lightweight, Xubuntu-based distro aimed at beginners and those using
Manjaro 20.1.1
The latest point release of the ever-popular Arch-based distro. Available
Mind Control Delete
Get hit by a stray shot: dead. Repeat. Run out
DietPi
A lightweight, Debian-based distro that eschews a graphical interface for
INTERVIEW
BUILD THE ULTIMATE MEDIA SERVER
Samhain is upon us and all kind of creatures and
ZULIP ECONOMY
Tim Abbott has something of an impressive resumé, holding no
ROUNDUP
Power-user distros
Shashank Sharma has tested more distributions than you’ve had microwaved
IN-DEPTH
HISTORY OF THE PC
There’s no doubt that Windows is synonymous with the PC
Pi USER
IT’S TIME TO GET ON BOARD
Gary Croft is a digital and innovation manager at SGS,
Astro Pi 2021 launches your code into space!
The Astro Pi Challenge is an annual contest that gives
Girls in space
Turns out superhydrophobic-coated tanks reduce liquid slosh in spacecraft by
MCU magic
D developer Roey Benamotz has created the Lean Mean Programming
Getting creative with the Pi camera
Les Pounder is associate editor at Tom’s Hardware and a
Emulate the classic ZX Spectrum range
Les Pounder is associate editor at Tom’s Hardware and a
REGULARS AT A GLANCE
Answers
Got a burning question about open source or the kernel?
Mailserver
Write to us at Linux Format, Future Publishing, Quay House,
Firefox
Alexander Tolstoy makes it his aim to collect the best
Htop
There are several reasons for using Htop to keep an
Outrun
Outrun is a powerful system tool that can do cool
Pixelitor
We’ve previously reviewed an update of Pinta, a Microsoft Paint.NET
Memavaild
Performance-related tips and tweaks for Linux are normally aimed at
Krop
One of the most widely used formats of exchanging documents
Diagrams
The Python Package Inde (PyPI) contains over 260,000 projects, some
X-moto
Ask someone to name a challenging 2D motocross racing in
Fortify
Children often feel compassion towards theirbeloved toys and try to
Oomox
Since theme engine support was removed from GTK 3.18 a
Flowblade
Linux users who are involved with non-linear video editing have
TUTORIALS
SSH replacement for persistent connections
Shashank Sharma is an avid Arch user and a trial
Live stream from your Linux deskop
Nick Peers wonders if there’s a future in live streaming
Collaborate on office docs with NextCloud
Kseniya Fedoruk is a documents expert at OnlyOffice and spends
Visualise complex data in style using Timelion
Simon Quain is a site reliability engineer who likes discovering
Develop RAW photo-editing Skills
Alexander Tolstoy is a long-time enthusiast of image editing using
Chat
X
Support Pocketmags