Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Abacus - The Beaded Brain

5.00/5 (10 votes)
7 Mar 2023CPOL2 min read 7K   230  
A practical Abacus app - calculator and toy
The Abacus has been an important business tool for thousands of years. Its practice can be an important mental exercise, or a pleasant distraction.

Image 1

Introduction

The origins of the Abacus are unknown, but it has been used in East Asia thousands of years ago. This app reproduces the Chinese Abacus, known as the suanpan, and can be used as an efficient calculator, or practice for the challenge and mental exercise.

The App

Image 2

In the screen capture above, the app is in Calculator mode, as the red/yellow button center-right indicates, and the values of displaced beads are equivalent to 1400.

In the screen capture below, the app is in Exercise mode where the user is expected to add/subtract a random value from the running-tally.

Image 3

  • Press the Exercise/Calculator button to toggle mode.
  • Press the Reset button to reset to zero (calculator) or reset to last running-tally (exercise)
  • Click on beads to slide them along their respective poles

It can be great fun...

The Code

There are two important classes:

  1. classAbacusBeadsRack
  2. classAbacus_BeadsOrderOfMagnitude

The classAbacusBeadsRack

Every column (order of magnitude) of the abacus has two divisions - the upper half called 'heaven beads' and the lower half called 'earth beads'. Each half is made up of one bead-rack that keeps tracks of its own Max number of beads, Value (number of counted beads), eType (heaven, earth), Base and Worth.

  • Type - Heaven / Earth
  • Max - max number of beads in rack is determined by Type (2 or 5)
  • Value - current number of beads 'counted'
  • Base - unit value of each counted bead1
  • Worth - Value*Base (number of beads counted * base value of bead)

classAbacus_BeadsOrderOfMagnitude

The columns each represent one order of magnitude starting from least significant (far right) to most significant (far left). They consist of upper/lower Heaven & Earth beads racks. The sum of all the columns is the Abacus-Value, or final tally.

SweepAndPrune

The DrawAbacus() method draws each column in sequence from right-to-left and creates a SweepAndPrune data-set of the locations of each button in a var call cSP. The pic_MouseMove() and pic_MouseClick() event handlers poll the cSP is polled under the mouse location and returns the element found (button or bead) located under the mouse on the screen.

History

  • 7th March, 2023: Originally published
  • 11th March, 2023: the Random was not seeded - puzzle solutions were falling below zero or above 1 billion 
  • 14th March, 2023 - added a minimum size so that it doesn't fail to appear when destroyed while minimized - fixed the random exercise generator - added a better '?' solution button
  • 16th March, 2023 - added game play levels of difficulty that increase with player score  - improved button graphics 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)