Adafruit will not be shipping orders Monday May 27, 2019 Memorial Day Orders placed after 11am EST Friday May 24 will go out Tuesday May 28.
0

How To Program Conway’s Game of Life on #RaspberryPi #piday @Raspberry_Pi

NewImage

Trevor Appleton created a tutorial to create Conway’s Game of Life in Python on Raspberry Pi

While looking through a few programming forums I kept noticing people with a slightly odd looking avatar.

I thought that for the same emblem to keep cropping up it must have some meaning, but I had no idea what that was.

It took a few attempts at googling to find the symbols meaning. Trying to describe a symbol to google is not easy! I found that the symbol was derived from Conway’s Game of Life. The symbol represents a Glider which is sometimes created during the Game of Life. The reason people use it as an avatar is because the symbol has been adopted by the hacking community in a similar way that Linux has Tux as its emblem.

Reading about the Game of Life on Wikipedia I became quite interested in the concept.

The Game of Life is in short a simulation of a group of cells. At every step in time, often referred to in the game as a tick, cells live or die depending on their surroundings.

There are four rules which are applied simultaneously to all the cells in the game.

1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
2. Any live cell with two or three live neighbours lives on to the next generation.
3. Any live cell with more than three live neighbours dies, as if by overcrowding.
4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

However I made my mind up that it must be too difficult to program, so I filed it away as one of those things to try when I am a better programmer.

For various reasons I was drawn towards giving pygame a whirl. I had played around with it in the past and felt it might potentially offer a nicer way to display certain things than Tkinter, which is my default for any GUI work in Python. I felt there was some potential there other than for writing games.

I learnt to program in Python using the free book ‘Invent Your Own Computer Games with Python’ by Al Sweigart. I cannot rate this book highly enough. If you want to learn Python, use this book. It is that good.

I knew he had also written a book aimed at teaching the basics of pygame. After my great experience with his first book, I thought I could not go wrong with his book called ‘Making Games with Python and Pygame’. (These two books plus his latest book ‘Hacking Secret Ciphers with Python’ can be found on the website http://inventwithpython.com/)

I skimmed through the first few chapters of this book and knowing I learn better by doing, I thought I would crack on and write my own game. But what? Having seen that the first of the games in the pygame book revolved around a grid system, I thought I could always try and write a version of the Game of Life. I still had a feeling it would be too difficult, but I was up for the challenge.

After starting and finishing the program much quicker than anticipated, and once again astounding myself with how easy things are to do in Python, I thought it would make a great blog post.

Pygame comes as standard on the Raspberry Pi however if you are using a different platform for programming then you can download it from here:

http://www.pygame.org/news.html

This tutorial will lead you through my thought process for developing and creating this game. There will be a link to the code at the end for those who want to download it. 🙂

I am going to assume you know how to start programming in Python. If not I have a previous blog which should get you up to speed.

Full Tutorial

998Each Friday is PiDay here at Adafruit! Be sure to check out our posts, tutorials and new Raspberry Pi related products. Adafruit has the largest and best selection of Raspberry Pi accessories and all the code & tutorials to get you up and running in no time!


Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, or even use Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for MakeCode, CircuitPython, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.

Join 10,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython 2019!

Have an amazing project to share? The Electronics Show and Tell with Google Hangouts On-Air is every Wednesday at 7:30pm ET! To join, head over to YouTube and check out the show’s live chat – we’ll post the link there.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Follow Adafruit on Instagram for top secret new products, behinds the scenes and more https://www.instagram.com/adafruit/


Maker Business — Robotics manufacturer Anki shuts down

Wearables — Brace for fabric

Electronics — DRC Confusion

Biohacking — Senolytic Therapies

Python for Microcontrollers — CircuitPython 4 released, upcoming hardware, and more! #Python #Adafruit #CircuitPython #PythonHardware @circuitpython @micropython @ThePSF @Adafruit

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !



No Comments

No comments yet.

Sorry, the comment form is closed at this time.