Project Review: Countdown Numbers

A simulation of the numbers game on the TV show, Countdown

Summary

Introduction

The Countdown Numbers project uses the logic from the numbers game on Countdown to enable a player to play against the computer (which I call Rachel) attempting to get the closest value to the target number as possible.

Game Rules

  • Six, face-down, numbered tiles are selected from 24 shuffled tiles. The tiles are arranged into 2 groups:
    • Large Numbers: There are 4 numbers in the large set. These are 25, 50, 75 and 100
    • Small Numbers: There are 20 numbers in the small set. 2 each of the numbers 1-10
  • One contestant selects between 0 and 4 numbers from the large set (a.k.a. from the top) and the remaining numbers are drawn from the small set to make six numbers in total
  • A random three-digit target number is then generated by the computer
  • The contestants must attempt to get as close as possible to the target number by using just the four basic arithmetic operators (+, -, ×, and ÷) and the six selected numbers
  • Brackets in the calculations are permitted and ordinary BODMAS operations apply
  • Not all of the digits need to be used
  • Concatenation of digits is not permitted (For example, you cannot use a “2” and “2” to make “22”)
  • At no intermediate step in the process can the current running total become negative, or the running total involve a fraction
  • Each numbered tile can only be used once in the calculation
  • Creates a database entry recording the details of the game.
  • The scoring is as follows:
    • 10 points are awarded for correctly achieving a solution that meets the target number
    • 7 points are awarded for getting within 5 of the target number
    • 5 points are awarded for getting within 10 points of the target number
    • Only the contestant whose solution is nearest to the the target scores
    • Both contestants score if it is a draw

Features

  • Uses a functional programming style to implement the game's rules logic into the program
  • Validates that the calculation method used by the player is permitted
  • Returns a game result and score displaying the winner
  • Returns a calculation by Rachel Riley which is as close as possible to the target number
  • Unlike the TV game show, there is no 30 second clock. This is intended so that recruiters and hiring managers don't have to wait for a countdown timer to expire

Objectives

This actually came about as a natural continuation of developing the countdown letters game. I simply wondered whether I could develop the numbers game as well.

The Approach & Solution

The numbers game is harder to develop than the letters game as it requires more thought in terms of validating the answer and finding a solution to the calculation used to arrive at the game's target number.

It involves using some of Python's non-standard data structures to efficiently perform the calculations.

A further development led me to create a database model to store the results of each of the games for reference and later retrieval. This is an example of using a database table to store a program's logic rather than to capture user-defined input from forms.

Evaluation

I am largely happy with the project, however, I would like to use hypothesis to test against some possible edge cases for a player's calculation input. Since there's a large combination of operators, brackets, and numbers that can be applied to a game's calculation, there's likely to be some sequence of characters that I haven't thought about testing.

Languages, Technologies & Skills Used

In approximate order of frequency used...
Languages: Python, HTML, Sass
Frameworks / Services: Django, Bootstrap, Font Awesome
Software: VS Code
Libraries: itertools, operator, collections, random, re, ast
Notable Packages: N/A
Infrastructure: GitHub, Docker, Poetry

Sources

Information and rules of the game was sourced from http://datagenetics.com/blog/august32014/index.html