Attualmente si sta visualizzando la versione Italy del sito.
Volete passare al vostro sito locale?
13 TEMPO DI LETTURA MIN

PYTHON

Recreate the famous Game of Life

Mihalis Tsoukalos casts a light on Python sets and shows how to implement the classic programming exercise the Game of Life in Python.

OUR EXPERT Mihalis Tsoukalos iis a Systems Engineer and a Technical Writer. He is the author of Go Systems Programming and Mastering Go, 3rd edition. You can reach him at www. mtsoukalos.euand @mactsouk.

Everyone loves 2D cellular automaton, to explore this exciting subject we’re going to use Game of Life as our working example. This isn’t to be confused with The Game of Life, the family board game that was first produced in 1960 and is still going strong today. So, let’s begin by explaining how Game of Life the non-board game edition works! Before we start you can get the code packs for this tutorial from the LXF Archive here: https://bit.ly/lxf284code.

Game of Life doubles up as both a programming exercise and an introduction to theoretical mathematics and computer science (don’t let that put you off! Ed), but in this tutorial we’re only dealing with the former. Although it might not seem it, the game is Turing Complete, which means that its data manipulation rules can be used to simulate a Turing Machine (see LXF271). We’ll look at this in more detail later in the article.

Game of Life can have various states, depending on the initial state of the board. Given an initial state, Game of Life doesn’t require any extra input from the user. Put simply, once it has an initial state, Game of Life can operate on its own with the help of its rules.

The patterns of life

Game of Life works by creating patterns. The figure (below) shows an example of patterns in the Game of Life, that displays living and dead cells. It uses black for living cells and white for dead cells, which is the colouring scheme used throughout this tutorial. Once you’ve read the rules of Game of Life, you’ll understand why not all black and white cell combinations are allowed. Hint: when a living cell has too many neighbours, it’s going to die! Bear in mind that there are two kinds of patterns: those that are changing and keep repeating; and patterns that are stable, which means that they’re not being updated.

This shows some stable patterns that might appear in Game of Life. The stability of a pattern depends on the rules. In the case of the square that comprises four cells, no cell dies because each cell has three living neighbours.
Sbloccate questo articolo e molto altro con
Si può godere di:
Godetevi questa edizione per intero
Accesso immediato a oltre 600 titoli
Migliaia di numeri arretrati
Nessun contratto o impegno
Prova per €1.09
ABBONATI ORA
30 giorni di accesso, poi solo €11,99 / mese. Disdetta in qualsiasi momento. Solo per i nuovi abbonati.


Per saperne di più
Pocketmags Plus
Pocketmags Plus

Questo articolo è...


View Issues
Linux Format
January 2022
VISUALIZZA IN NEGOZIO

Altri articoli in questo numero


WELCOME
MEET THE TEAM
This issue we’re looking at building a Raspberry Pi media centre as a first maker project. What’s your favourite Pi project to help kick-start would-be maker fans?
Maker bliss
We’re sure this Christmas many people will be
REGULARS AT A GLANCE
Man uses Linux and the world goes crazy!
Linus Tech Tips tries – and fails – to install Steam in Linux
Canonical brings Ubuntu to M1 Macs
Canonical has unveiled an updated Multipass, which makes it easy to run Linux on Apple’s latest machines
GitLab severs used in DDoS attacks
Security flaw in GitLab’s servers exploited
FORTUNE TELLING…
Accurately predicting trends can get you ahead of
HUMAN FAILURE
In any business system you want to eliminate
Steam Deck devs to use Manjaro KDE
Valve puts forward Manjaro Linux as a suitable test environment
Zink levels up
Outperforms Nvidia’s own drivers with Tomb Raider
Gamers 4 Linux!
Well, over one per cent of them love FOSS. Progress!
Distro watch
What’s behind the free software sofa?
WIREPLUMBER HAS LANDED
The release of Fedora 35 marked an exciting
GIVING THANKS
We just celebrated Thanksgiving here in the US,
KERNEL WATCH
Jon Masters summarises the latest happenings in the Linux kernel, because someone has to
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to lxf.answers@futurenet.com
Mailserver
WRITE TO US Do you have a burning
Alexander Tolstoy
is touring the world and ticking off the
Audacity
Version: 3.1 Web: www.audacityteam.org
Pscircle
Version: 1.3.1 Web: https://gitlab.com/ mildlyparallel/pscircle
Edotool
Version: 3.0.1d Web: https://github . com/evuraan/edotool
Quickemu
Version: 2.3.0 Web: https://github . com/wimpysworld/quickemu
USB Imager
Version: 1.0.8 Web: https://gitlab.com/ bztsrc/usbimager
GtkStressTesting
Version: 0.7.5 Web: https://gitlab.com/leinardi/gst
Key Mapper
Version: 1.2.1 Web: https://github.com/ sezanzeb/key-mapper
Sonic Robo Blast 2
Version: 2.2.9 Web: www.srb2.org
NumptyPhysics
Version: 0.3.9 Web: https://github.com/thp/numptyphysics
Js-dos
Version: 7.2.1 Web: https://github.com/ caiiiycuk/js-dos
Larynx
Version: 1.0 Web: https://github.com/ rhasspy/larynx
MALWARE ATTACKS
The complete guide to avoiding ransomware, blocking malware attacks and general nasties
REVIEWS
Intel Core i9 12900K
Intel was never going to be without its performance crown for long, so with appropriate pomp and ceremony Jacob Ridley introduces the new CPU king
Waterfox G4.0.3
Can Firefox-fanatic Jonni Bidwell be won over by water signs, debloating and a privacy boost?
Edge on Linux
Will Edge find space in the saturated Linux web browser market, just because Mayank Sharma thinks Microsoft has done a good job with the release?
NuTyx 21.10
If there’s a scale for rating the complexity of power-user distributions then Mayank Sharma has found one that’s at the lowest end of the spectrum
Itd Os 0.9
Distracted by the distro’s spruced-up desktop, Mayank Sharma failed to notice its lowly version number, and the other rather glaring shortcomings
Ubuntu Touch OTA-20
Jonni Bidwell once again delights at being able to use hardware that people told him to throw away ages ago…
Black Mesa
Andy Kelly really doesn’t want to go back to the Linux Format Test Chamber, but The Management are quite insistent…
ROUNDUP
Video conversion tools
If you get your codecs mixed up with your containers, a graphical video conversion program may make life easier. Neil Bothwick investigates
Input and output formats handled
The heart of the matter: what can you convert into to what else?
Processing with filters
Do you want to process the video while you’re converting it?
Using the user interface
The heart of the matter
Batch processing multiple videos
How easy is it to set up a run of videos for overnight processing?
Video-editing options
Sometimes you need to be selective, as some of these programs can be
Audio manipulation
Do you need to add, enhance or isolate audio from a video?
Extra features
Each of these programs brings something new to the table…
The Verdict
Video conversion tools
MEDIA CENTRE
Start 2022 off right with Jonni Bidwell’s outrageous media centre, powered by Pi, Kodi and just one too many LEDs
Kodi academy
New versions of Kodi and LibreELEC are out, but only for Raspberry Pi 4 users (for now)…
Setting up Kodi
LibreELEC is probably the easiest Linux distro you ever installed, and Kodi will be ready for action in no time
Hi-fidelity Kodi
Integrate the world’s most popular streaming site into Kodi and see how the Pi fares at high resolutions
The light fantastic
Add a touch of pizazz to your media centre with a border of colourful Ambilight-like, picture-reactive LEDs
Pi USER
Unofficial Android 12 lands on the Pi 4
Discover how you can (unofficially) try the latest mobile operating system on your Raspberry Pi
Pop!_OS (Pi edition)
Les Pounder loves pop… pop music, fizzy “pop” drinks and popcorn. But does he have an appreciation of Pop!_OS?
Cyberdeck Bonnet
Les Pounder dons his mirrored shades, adds the latest wetware to his Adafruit-enhanced Pi 400 and gets ready to hack the matrix
Create multi-level Scratch games
Les Pounder creates multi-level games with Scratch 3. He also needs to defeat hostile, hungry space hippos before they consume the Earth!
Build a Pi-powered network storage device
You can have your own high-end NAS device without breaking the bank, but Mats Tage Axelsson explains how it’s just a Pi and a bank of disks
Run a Pi Zero 2W social Fediverse server
We go boldly where no man has gone before… well, David Rutland has, into the Fediverse with just his trusty Raspbery Pi Zero 2 W
IN-DEPTH
LINUX AT THE PEAK OF PERFORMANCE
Mike Bedford explores the world’s fastest supercomputers to find out how Linux came to power every top 500 high-performance computer
TUTORIALS
Effortlessly transfer files across computers
Mere mortals use USB drives to transfer files, but Shashank Sharma wants convenience and security. Luckily, the right tool is just a command away…
Enhance your Linux system management
Nick Peers takes a deep dive into a tool that aims to be a one-stop shop for all your system maintenance and monitoring needs
How to emulate an Oric 8-bit computer
Les Pounder puts a daffodil in his lapel and enters his surprisingly spacious blue police box to once again take us back to the 1980s…
Set up a music studio using Qtractor
Feeling creative? Michael Reed looks into how to build a Linux-based home studio using free software that can be applied to any type of music
Set up and configure a custom RSS news feed
Deftly skirting the lines of legality, David Rutland reveals how he’s able to scrape all the news that’s good to read direct to his own server
Safely swap your filesystem to Btrfs
The Btrfs filing system is well-supported, reliable and packed with modern features, so Michael Reed will show you how to make good use of it
TOP OF THE FOSS
MAIL-IN- A-BOX
Hillary Clinton’s self-hosted mail server didn’t do her presidential campaign much good. Let’s see how Jonni Bidwell’s fares…
CODING ACADEMY
Accurate, open source IP-based localisation
Tim Armstrong reveals GeoIP.Network , an open source IP address localisation solution using Python that’s better than what went before!
Chat
X
Supporto Pocketmags