Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
hyperPad

hyperPad Forum

  1. Home
  2. WIP and Showcase
  3. Tutorial: how to map a 2-dimensional grid structure/matrix to a 1-dimensional array and back again

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

Scheduled Pinned Locked Moved WIP and Showcase
12 Posts 5 Posters 3.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Jack de WildeJ Jack de Wilde

    @mc-games (pretty clever, but multidimensional arrays work)

    mc gamesM Offline
    mc gamesM Offline
    mc games
    wrote on last edited by
    #3

    @Jack8680 I must be missing something. As far as I understand, the Array behavior in Hyperpad generates a collection of ordered values, hence a 1-dimensional array: Array(i).
    How does one create a 2-dimensional array: Array(i,j)?

    Jack de WildeJ 1 Reply Last reply
    0
    • mc gamesM mc games

      @Jack8680 I must be missing something. As far as I understand, the Array behavior in Hyperpad generates a collection of ordered values, hence a 1-dimensional array: Array(i).
      How does one create a 2-dimensional array: Array(i,j)?

      Jack de WildeJ Offline
      Jack de WildeJ Offline
      Jack de Wilde
      wrote on last edited by Jack8680
      #4

      @mc-games you can put arrays in arrays. For example in your 5*5 grid, you can have 5 arrays inside an array. It's a bit hard to explain, but here is a 2d array of your grid:
      [
      "["0,0","0,1","0,2","0,3","0,4"]",
      "["1,0","1,1","1,2","1,3","1,4"]",
      "["2,0","2,1","2,2","2,3","2,4"]",
      "["3,0","3,1","3,2","3,3","3,4"]",
      "["4,0","4,1","4,2","4,3","4,4"]"
      ]

      The index of the main array is the X value, then the index of the inside arrays are the y value. For example, if you want the object at 2,4, you would get the array at index 2, which will output the array ["2,0","2,1","2,2","2,3","2,4"]. Then you can get index 4 of that output, which will give the value 2,4. Note that the hyperPad forums are hiding the backslashes in the array, they are automatically created when you use modify array with characters that it might interpret as closing the main array/values:0_1492133730761_IMG_3175.PNG
      I've also formatted the array, it would actually like like this:
      ["["0,0","0,1","0,2","0,3","0,4"]","["1,0","1,1","1,2","1,3","1,4"]","["2,0","2,1","2,2","2,3","2,4"]","["3,0","3,1","3,2","3,3","3,4"]","["4,0","4,1","4,2","4,3","4,4"]"]

      mc gamesM 1 Reply Last reply
      3
      • Jack de WildeJ Jack de Wilde

        @mc-games you can put arrays in arrays. For example in your 5*5 grid, you can have 5 arrays inside an array. It's a bit hard to explain, but here is a 2d array of your grid:
        [
        "["0,0","0,1","0,2","0,3","0,4"]",
        "["1,0","1,1","1,2","1,3","1,4"]",
        "["2,0","2,1","2,2","2,3","2,4"]",
        "["3,0","3,1","3,2","3,3","3,4"]",
        "["4,0","4,1","4,2","4,3","4,4"]"
        ]

        The index of the main array is the X value, then the index of the inside arrays are the y value. For example, if you want the object at 2,4, you would get the array at index 2, which will output the array ["2,0","2,1","2,2","2,3","2,4"]. Then you can get index 4 of that output, which will give the value 2,4. Note that the hyperPad forums are hiding the backslashes in the array, they are automatically created when you use modify array with characters that it might interpret as closing the main array/values:0_1492133730761_IMG_3175.PNG
        I've also formatted the array, it would actually like like this:
        ["["0,0","0,1","0,2","0,3","0,4"]","["1,0","1,1","1,2","1,3","1,4"]","["2,0","2,1","2,2","2,3","2,4"]","["3,0","3,1","3,2","3,3","3,4"]","["4,0","4,1","4,2","4,3","4,4"]"]

        mc gamesM Offline
        mc gamesM Offline
        mc games
        wrote on last edited by
        #5

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

        1 Reply Last reply
        1
        • TutorialDoctorT Offline
          TutorialDoctorT Offline
          TutorialDoctor
          wrote on last edited by TutorialDoctor
          #6

          Indeed. I created a project on game press for a chess game. This would be much more realistic now. Thought that project was lost forever, but just found it in my email!

          0_1492182060239_IMG_2129.PNG

          Jack de WildeJ 1 Reply Last reply
          1
          • TutorialDoctorT TutorialDoctor

            Indeed. I created a project on game press for a chess game. This would be much more realistic now. Thought that project was lost forever, but just found it in my email!

            0_1492182060239_IMG_2129.PNG

            Jack de WildeJ Offline
            Jack de WildeJ Offline
            Jack de Wilde
            wrote on last edited by
            #7

            @TutorialDoctor speaking of chess games, I have one I should really finish 😛
            http://bit.ly/2oIDvna

            TutorialDoctorT 1 Reply Last reply
            0
            • CAnesiaC Offline
              CAnesiaC Offline
              CAnesia
              wrote on last edited by
              #8

              Thanks! for the tutorial and sharing. Right on time for my project.

              1 Reply Last reply
              0
              • Jack de WildeJ Jack de Wilde

                @TutorialDoctor speaking of chess games, I have one I should really finish 😛
                http://bit.ly/2oIDvna

                TutorialDoctorT Offline
                TutorialDoctorT Offline
                TutorialDoctor
                wrote on last edited by
                #9

                @Jack8680 much better than what I had. Please do finish!

                Jack de WildeJ 1 Reply Last reply
                0
                • TutorialDoctorT TutorialDoctor

                  @Jack8680 much better than what I had. Please do finish!

                  Jack de WildeJ Offline
                  Jack de WildeJ Offline
                  Jack de Wilde
                  wrote on last edited by Jack8680
                  #10

                  @TutorialDoctor I might eventually, but detecting check/mate would be a bit of effort

                  TutorialDoctorT 1 Reply Last reply
                  0
                  • Jack de WildeJ Jack de Wilde

                    @TutorialDoctor I might eventually, but detecting check/mate would be a bit of effort

                    TutorialDoctorT Offline
                    TutorialDoctorT Offline
                    TutorialDoctor
                    wrote on last edited by TutorialDoctor
                    #11

                    @Jack8680 I guess the theory is to check if all squares around the king are attacked and also to check if any of the pieces are attacking the square the king is on.

                    1 Reply Last reply
                    0
                    • Michael KhalfinG Offline
                      Michael KhalfinG Offline
                      Michael Khalfin
                      wrote on last edited by
                      #12

                      @TutorialDoctor But you would also have to make sure no pieces can defend and no pieces can take the attacking piece for checkmates...

                      1 Reply Last reply
                      0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Search