logo hyperPad Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Login
    1. Home
    2. mc games
    3. Best
    M
    • Profile
    • Following 0
    • Followers 0
    • Topics 5
    • Posts 11
    • Best 5
    • Controversial 0
    • Groups 0

    Best posts made by mc games

    • Tutorial: how to map a 2-dimensional grid structure/matrix to a 1-dimensional array and back again

      Not sure if this is the best place to post this. Maybe we need a Tutorial section on the forum.

      Hyperpad now has array behaviors (yay!), but we’re limited to 1-dimensional arrays. One can do quite a bit with 1-dimensional arrays, but for some things, like grid-based games, 2-dimensional arrays would be ideal. For example, in a game like Battleship, 2-dimensional arrays would be ideal for keeping track of ship locations and the coordinates of hits and misses and then mapping the array information onto a graphic display.

      The good news is, we can do the same thing with 1-dimensional arrays, it just takes a few extra steps. So as an example, let’s take a 5x5 grid layout with a ship at coordinates (1,2)(2,2)(3,2) as shown in the left figure.

      alt text

      We can assign each square in the grid to an index in a 1-dimensional array with 25 elements as shown in the right figure. Remember, arrays are indexed beginning at 0. So our ship is sitting at array indices 11, 12, & 13.

      A 1-dimensional array representation of our ship, where we assign cells with a ship on them a “1” and other cells a “0”, would look like this:

      Array = (0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0)

      That is a visual representation of the problem, now how do we actually calculate the array index number for a given grid coordinate? We need one key number – the column dimension or grid width. In this case, we have 5 columns, so the column dimension is 5.

      To determine the array index for a given (x,y) coordinate we use the formula:

      Array index = (y*column dimension) + x

      For the ship at (1,2)(2,2)(3,2), and a column dimension of 5, we calculate:

      (1,2) --> (2*5)+1 = 11

      (2,2) --> (2*5)+2 = 12

      (3,2) --> (2*5)+3 = 13

      Which gives us our array indices of 11, 12, and 13.
      Pretty cool, huh?

      Now how about going the other way. We have our 1-dimensional array representation of the ship, how do we translate that to coordinates so we can then display a graphic representation of the ship in the grid?

      This is a little more involved, but not too bad. If we divide an array index by the column dimension, the remainder is our x coordinate and the whole number is our y coordinate.

      Let’s take the array index 13 from our previous example. The column dimension is 5. So divide 13 by 5 and get 2 with a remainder of 3, which maps to x=3, y=2.

      In Hyperpad we’ll need three behaviors to do this:

      Divide Values
      Round Number
      Modulus

      Given an array index “N” and a column dimension “D”

      To get x, we use the Modulus behavior which divides two numbers and returns the remainder

      x = N mod D

      To get y, first divide N by D with a Divide Values behavior,
      then input this result into a Round Number behavior, and set the Rounding Type to “Truncate”

      y=truncate[N/D]

      Hope this makes sense and is helpful.

      Note: this could possibly be done with multiple arrays,
      but where’s the fun in that! :smiley:

      posted in WIP and Showcase
      M
      mc games
    • RE: Historical Authenticity Contest

      Just put up a project called “Spot Nessie” for this. It’s a whack-a-mole type game.
      Have fun!

      posted in Announcements
      M
      mc games
    • Zombie Smash now on the App Store!

      It's called Zombie Smash: Last Light. (Zombie Smash name had already been used). Available for iPhone and iPad.
      Check it out:
      https://appsto.re/us/9rOjjb.i

      posted in General Discussion
      M
      mc games
    • PoetBot

      Just having a bit of fun with AI in hyperPad. Not sure where I’m going with this.

      PoetBot is an Artificially Intelligent (or not so intelligent) poet that composes mostly bad (unless you’re a Vogon) poetry with a nature theme. Sometimes an interesting poem appears like:

      night falling
      silence sleeping
      moon rising
      shadow creeping

      Several styles of poems are created including 2-line couplets, 3-line tercets and Haiku-ish poems, 4-line quatrains, Lune form poems (3 words, 5 words, 3 words), and Lantern form poems (1 word, 3 words, 5 words, 3 words, 1 word).

      The vocabulary words are stored in several arrays, one for each type of word (nouns, verbs, adjectives, etc.). Currently there are two themed vocabularies, a Nature them, and for those who like really bad poetry, a Vogon vocabulary. But be forewarned, Vogan poetry is the third worst in the universe!

      Vogon PoetBot examples:

      the fetid yellow liverslime…
      in the putrid tinklewort
      a coagula has burped

      the
      radiant blumptiferous replurg
      hurls near the putrid jandleturt
      what slurps this
      snot?

      Finally, if you branch the project and go into the scene titled “Other” there is a label “Arrays” with empty noun, verb, and adjective arrays where you can add words to create your own themes. Then add a button to the main menu page to goto your themed poetry page.

      Have fun!

      posted in WIP and Showcase
      M
      mc games
    • RE: Tutorial: how to map a 2-dimensional grid structure/matrix to a 1-dimensional array and back again

      @Jack8680 Ahh, arrays within arrays, thanks. This opens up all kinds of possibilities.

      posted in WIP and Showcase
      M
      mc games