Skip to content

Latest commit

 

History

History
98 lines (74 loc) · 3.63 KB

README.md

File metadata and controls

98 lines (74 loc) · 3.63 KB

Kyrel

Kyrel is a simple browser-based game for learning about control flow and loops in javascript. It is reminiscent of a turing machine that manipulates a strip of tape, transforming it from an initial state to a final state.

Methods

The following special methods are available for traversing/transforming the row:

  • moveRight();
  • moveLeft();
  • useGreen();
  • useBlue();
  • draw();
  • erase();
  • onGreen();
  • onBlue();

Example Problem

Write a program which draws a green circle at the end of the row.

  function main() {
    moveRight();
    moveRight();
    moveRight();
    moveRight();
    useGreen();
    draw();
  }

This would result in the following transformation:

 ['.', '.', '.', '.', '.'] // start row (initial state)
 ['.', '.', '.', '.', 'g'] // end row (end state)

Start:

End:

Instructions

Clone this repo! (Or click "Download ZIP" on the right).

There are three problem sets, organized by difficulty: day_1, day_2, day_3.

Solutions may be found in the /solutions folder. NO PEEKING! Try your darndest before you give up. The name of the solution file will match the title of the problem. For example, the solution to turn_3rd_cell_blue can be found at challenges/solutions/turn_3rd_cell_blue.js.

Using kyrel.js

If you look in play.js you'll see this:

var initial_state = [ '.', '.', '.', '.', '.' ];

function main(n) {

  //////////////////////////////////
  ////                          ////
  //// v YOUR CODE BELOW HERE v ////
  ////                          ////
  //////////////////////////////////



  //////////////////////////////////
  ////                          ////
  //// ^ YOUR CODE ABOVE HERE ^ ////
  ////                          ////
  //////////////////////////////////

}
  • First, you need to manually configure your "starting row" (see play.js#L22) to match the initial state of the problem you're solving.

    • var initial_state = ['.', 'b', '.', 'g', '.'] // play.js#L22
      • 'b' means blue
      • 'g' mean green
      • '.' (dot) means empty
  • Next, write your instructions inside the main function in play.js.

    • TIP: If you declare your variables at the very TOP of the play.js file, your values will be in the "global scope". This can make it easier for you to see them in your console / play with them.
  • To run the program, open index.html in your browser and press "Play". This will execute the code you put in your main function in play.js#L24.

    • TIP: Make sure to refresh the page whenever you make changes to your javascript!
    • PRO-TIP: Always have your Chrome Developer Console open (here's how), and make sure to check for error messages!
  • When you've completed a problem, save your work! Make a copy of play.js and rename it e.g. solution-all-blue.js. Then, go back to play.js and clear out your main function so you can start fresh again.

Inspiration

Adapted from Kyrel.

More information about turing machines:

Possible slides: Kyrel.pdf or: google docs