Berry Bookies – A Horse Racing Game For The BerryClip

Jim Flewker, a retired languages teacher, has written a horse racing game in Python for use with the BerryClip addon board. In the game you select one of six horses using the BerryClip button and then wait for the result of the race.

The result of the race is shown on the command line and via the BerryClip’s 6 LEDs.

If you are lucky your pot of virtual money will grow … but beware … the bookie always wins in the end!

In Jim’s own words …

Simple horse racing simulators have been around forever – no claims to originality!

– 6 horses in every race, each with appropriate name and odds
– “cyclical” betting routine uses Berryclip LEDs and switch
– fixed bet amount (can be changed in the code)
– simple race progress display in Shell and also via Berryclip leds
– totally random winner
– race until you get fed up or run out of funds
– final feedback

I’ve learned quite a bit so far and had a lot of fun – thanks, Matt!
Still a raw beginner, so if anyone reading this has any tips for improvements, please email me: jim@dastor+org+uk (replace plus signs with full stops/periods).

Jim confesses to having no technical background or qualifications and started this project to have a go at programming and soldering. His weapons of choice were a Pi, a BerryClip and Python.

Berry Bookies Horse Racing Game

Installation

To install the script you can either grab the file directly :

wget https://bitbucket.org/MattHawkinsUK/rpispy-berryclip/raw/master/berry_bookies/berry_bookies.py

or download the complete set of BerryClip example scripts as described on the BerryClip Instructions page.

The game can be run by using :

sudo python berry_bookies.py

Instructions

When the game starts it will present a list of horses and their odds as shown below :

--------------------------------------------------
HORSES AND ODDS FOR THIS RACE
--------------------------------------------------
Jess of Greendale at 8-1
Miss Moss at 11-1
Daffy Dill at 15-1
Captain Custard at 3-1
Raspberry Pie at evens
Ruddy Miracle at 7-1

It will then start to list the horses. Press the BerryClip button when your chosen horse is displayed.

Once you’ve chosen a horse the race will begin!

--------------------------------------------------
Horse is Miss Moss.
Odds for this horse are: 11-1
To bet on this horse, press the BUTTON while its light is on.
Otherwise, just WAIT for the next horse!
You placed a bet on Miss Moss, horse number 2.
--------------------------------------------------
RACE NUMBER 1
Your current funds: 90
THEY'RE OFF!
5/>
5/> 1/>
5/> 1/> 5/>
5/> 1/> 5/> 6/>
5/> 1/> 5/> 6/> 6/>
5/> 1/> 5/> 6/> 6/> 6/>
5/> 1/> 5/> 6/> 6/> 6/> 1/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/> 1/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/> 1/> 6/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/> 1/> 6/> 3/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/> 1/> 6/> 3/> 2/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/> 1/> 6/> 3/> 2/> 2/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/> 1/> 6/> 3/> 2/> 2/> 1/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/> 1/> 6/> 3/> 2/> 2/> 1/> 5/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/> 1/> 6/> 3/> 2/> 2/> 1/> 5/> 1/>
5/> 1/> 5/> 6/> 6/> 6/> 1/> 5/> 1/> 6/> 3/> 2/> 2/> 1/> 5/> 1/> 6/>
HORSE 6 WON
--------------------------------------------------
The winner was Ruddy Miracle
Winning odds were 7-1
A bet on the winner won 80 including stake.
Better luck next time.
--------------------------------------------------
Funds: 90
Bet on another race y/n?n
--------------------------------------------------

At the end of the race you will have the chance to bet on another race. Will that lucky streak last or will you hope for a change of fortune?

Thoughts

This script has plenty of scope for modification to improve the game play. Here are some ideas for updating the script :

  • Allow the player to choose a stake
  • Randomly generate the horse names
  • Allow multiple players
  • Adjust the maths to change the race outcome
This entry was posted in BerryClip, Python, Software and tagged , . Bookmark the permalink.



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>