Overview Puzzle Racing Word Guesser GAME HUB

In one of our games to help our users learn Binary, we will give the user:

  • Starting Number in Binary
  • Wanted Final Number in Decimal
  • Number of Actions

The user must turn the starting number into their given final number in the number of actions, which will be the minimum number of actions needed to transform the number.

The user will be able to:

  • Swap each individual number’s value back and forth from 0 and 1
  • Shift left and right to accomplish what would have been multiple value swaps into 1 action

This will:

  • Challenge the user to really think about binary, and how the numbers work

How will we accomplish this?

  • Generate 2 random numbers
  • Switch UI
  • Algorithm that simulates various combinations of how to transform 1 number into another
  • Take the least number of actions and return it, displaying it on the site

What will we use?

  • JavaScript & HTML (required, no python!!!)
  • Use variable/set to keep track of already checked combinations
%%javascript
function minActions(start, end) {
    const queue = [{current: start, actions: []}]; 
    const checked = new Set([start]); //used to ensure no dupes

    while (queue.length > 0) {
      const {current, actions} = queue.shift(); //replaces the leftmost item from the queue (item 0)

      if (current === end) { //checks if current number is equal to end value
        return actions;
      }
}
//remainder of code to find minimum
}
min = minActions(num1, num2) //nums will be randomly generated to fit within 8 bits of binary
console.log(min)
//or
document.getElementById("display").innerHTMl = min
//HTML display for player input including shifting and swapping (similar to lightbulb demo, but different themeing)

image