Programming a Bot to Play the "Sushi Go Round" Flash Game

Update 2015/01/08: If you attended my NCSS class on making a bot for this game, you can download the file which has all the code in Feel free to send questions to me at [email protected] or tweet at me: @AlSweigart

This tutorial teaches how to write a bot that can automatically play the Flash game Sushi Go Round. The concepts in this tutorial can be applied to make bots that play other games as well. It's inspired by the How to Build a Python Bot That Can Play Web Games by Chris Kiehl. The primary improvement of this tutorial is it uses the cross-platform PyAutoGUI module to control the mouse and take screenshots. It is documented on its ReadTheDocs page.

Sushi Go Round is a resource management game similar to "Dine N Dash". You fill customer orders for different types of sushi and place them on the conveyor belt. Incoming customers may take other customer's sushi orders, forcing you to remake orders. Customers who wait too long to get orders end up leaving, costing you reputation. Angry customers can be placated with saki, but this bot does not make use of that feature. Ingredients will have to be ordered as they get low.

I've refined this bot so that it can successfully play all the way through the game, ending up with a score of about 38,000. The top scores are a little over 100,000, so there is still room for improvement with this bot. You can watch a YouTube video of the bot playing.

The source code and images for the bot can be downloaded here or viewed on GitHub.


Read More

Making a Text Adventure Game with the cmd and textwrap Python Modules

Text adventures are an old game genre where the entire world is textually described as a series of rooms. Play involves entering simple text commands such as "move north" or "eat pie". Each room in the game world has its own text description, items on the ground, and exits to adjacent rooms. "Room" is a general name for a single area in the game world: a room can be a large open canyon or the inside of a wardrobe. Multi-user text adventures, called MUDs or Multi-User Dungeons, were the precursor to modern MMORPGs. You can still play MUDs today by finding them on The Mud Connector.

Screenshot of an old text adventure game.

Text adventures are easyto make because they don't require graphics. This tutorial uses two Python modules, cmd and textwrap and makes minimal use of object-oriented programming, but you don't have to know OOP concepts to follow. (But in general, text adventures would do very well with an object-oriented approach.) This tutorial is for beginner Python 3 programmers.

The code for Text Adventure Demo is available on GitHub.


Read More

Why is Object-Oriented Programming Useful? (With a Role Playing Game Example)

This blog post is those still new to programming and have probably heard about "object-oriented programming", "OOP", "classes", "inheritance/encapsulation/polymorphism", and other computer science terms but still don't get what exactly OOP is used for. In this post I'll explain why OOP is used and how it makes coding easier. This post uses Python 3 code, but the concepts apply to any programming language.

There are two key non-OOP concepts to understand right off the bat:

  1. Duplicate code is a Bad Thing.
  2. Code will always be changed.


Read More

IDLE Reimagined

(Update: I've recorded a copy of a talk I gave at PyCon 2015's Education Summit about IDLE Reimagined and posted it to YouTube.)

I've started a wiki for an IDLE redesign project:

If you would like to help, please join the mailing list:!forum/idle-reimagined/

IDLE Reimagined mockup screenshot

From the wiki:

IDLE Reimagined is the code name for a redesign for Python's default IDLE editor with focus as an educational tool. IDLE's chief utility is that it comes installed with Python, making it simple for newbies to start programming. But professional software developers don't use IDLE as their IDE. Instead of turning IDLE into a sophisticated IDE for professional software developers, it can be tooled with features specifically to make it friendly to those learning to program.

Prime Directives for the new design:

  1. IR is designed not for experienced developers or those new to Python, but specifically for those new to programming.
  2. IR is meant to be a drop-in replacement of IDLE, and be installed with the default Python installer.
  3. IR's code will use the tkinter GUI toolkit (unless a better GUI toolkit is bundled with Python).
  4. IR is fully-featured offline, but also has features for finding help or sharing code online.
  5. "Simple is better than complex."

These are the features that will distinguish IR and make it a good candidate to replace IDLE:

  1. Single window design, with file editor on the upper pane and interactive shell on the lower pane. (No more confusing separate windows for shell & file editor.)
  2. Tabbed file editor.
  3. Foreign language support. (Though Python's keywords and standard library will still be in English, IDLE itself can be multi-lingual.)
  4. Tutorial plugin system for Codecademy-like tutorials.
  5. Integrated pip installer.
  6. Integrated pastebin feature. (Easily share code with those who can help you.)
  7. "Plain English" error message translations. Instant Google-search for error messages.
  8. Detects and warns if you are trying to run Python 2 code on Python 3.
  9. Lightweight real-time lint tool that will point out missing variables and syntax errors. (Checks for errors, but does not check for style or PEP8.)

Read More