logo hyperPad Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Login

    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
    5
    12
    908
    Loading More Posts
    • 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.
    • M
      mc games @Jack8680
      last edited by

      @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)?

      Jack8680J 1 Reply Last reply Reply Quote 0
      • Jack8680J
        Jack8680 @mc games
        last edited by Jack8680

        @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"]"]

        M 1 Reply Last reply Reply Quote 3
        • M
          mc games @Jack8680
          last edited by

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

          1 Reply Last reply Reply Quote 1
          • TutorialDoctorT
            TutorialDoctor
            last edited by 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

            Jack8680J 1 Reply Last reply Reply Quote 1
            • Jack8680J
              Jack8680 @TutorialDoctor
              last edited by

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

              TutorialDoctorT 1 Reply Last reply Reply Quote 0
              • CAnesiaC
                CAnesia
                last edited by

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

                1 Reply Last reply Reply Quote 0
                • TutorialDoctorT
                  TutorialDoctor @Jack8680
                  last edited by

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

                  Jack8680J 1 Reply Last reply Reply Quote 0
                  • Jack8680J
                    Jack8680 @TutorialDoctor
                    last edited by Jack8680

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

                    TutorialDoctorT 1 Reply Last reply Reply Quote 0
                    • TutorialDoctorT
                      TutorialDoctor @Jack8680
                      last edited by TutorialDoctor

                      @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 Reply Quote 0
                      • GameCRAZYG
                        GameCRAZY
                        last edited by

                        @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 Reply Quote 0
                        • First post
                          Last post