Creating Maximum Movement Indicators on a Board

  • I'm going to tag every math wizard I know on this forum for this one xD

    @Yann, R0J0hound, cvp, Tobye

    Firstly, this is for a board game I am developing. The idea is that once a user clicks on a unit, all available move spaces are shown on the board, just like in this game here:

    <img src="http://img.photobucket.com/albums/v413/jaimeastorga2000/Spybot.png" border="0">

    In the image above, the selected unit is allowed to move 4 spaces on the game board, so every possible place the program can move is highlighted.

    For my board game (you can see what I currently have in development here: CoHackTest), I want to implement the same thing, but I'm not sure where to begin.

    Each program is in a family called PlayerPrograms, which has 4 instance variables. The one that's relevant to our problem is the 'Move' variable, which stores the number of spaces our program will be allowed to move. The four instance variables are displayed upon program spawn:

    <img src="http://i.imgur.com/FABieCM.png" border="0">

    <img src="http://i.imgur.com/j1LaEfe.png" border="0">

    Does anyone know how one might calculate the maximum movable spots? There is an unused sprite in the 'ObjectDump' layout called 'MoveIndicator' that I intend to use to display the movable spots.

    Any, and I literally mean any, help or ideas on how to do this are appreciated.

    BoardGame.capx

    My initial thoughts are that I need an array to cover the entire game board spaces (each space is 64x64 in size), and then mark which spaces are empty and which ones are walls or currently occupied by another program.

  • I would done something along these lines:

    I have made a small drawing to help illustrate

    <img src="https://dl.dropboxusercontent.com/u/2560922/mobiledev/forum/recursiveCheckNextdoor.png" border="0" />

    I would create a Function, which checks the 4 fields surrounding a specific location. and then call it recursively if the field responds positively. The function should take a parameter on how many spot the player can move.

    So, from the illustration.

    Call the Function on the field where the player is. It checks all the fields marked by a "1". Inside the function there is a check if the field can be used. Subtract 1 from the "move" variable which was passed to the function call. If the field can be used and there are still "moves" left then call the function on the new location (in this case field marked by "1".

    This recursive call will continue until there are no more moves left.

    You can save in an array if the location could be moved to or not.

    Something along those lines...

  • cvp Thank you very much for the picture. This is starting to make more sense to me.

    I'm going to start with the creation of an array to basically document all the spaces on the board, but now I'm getting confused. I haven't really worked with a nested For loop inside another For loop:

    <img src="http://i.imgur.com/pZpTqId.png" border="0" />

    If I use loopindex, it gets the closest loop, right? So if I loopindex under the last For loop, it will be for the rows loop?

  • You can use loopindex("name of loop") to get the index you need.

  • Alright, I've implemented an array. The idea is that if a NoZone exists, the array will store a 0, if a program exists, it will store 1, and if the space is empty, it will store 2.

    The array has a depth of 3, with the first value being the value stored above, the second is the X value of the loop and the third is the Y value of the loop.

    <img src="http://i.imgur.com/KYA8DiN.png" border="0" />

    The game downloads the JSON file of the array after the grid has been generated. However, there is a problem - right now the array is populating everything as 2, meaning it thinks every square is empty.

    This can only happen if the checks for the walls is failing.

    In Yann's maze generation script, which is used to generate the random game board, he offsets every wall by 0.5, and I'm not quite sure why:

    <img src="http://i.imgur.com/kDdu12r.png" border="0" />

  • I've made some tweaks so now the array is correct for PART of the game board. There's a point where it starts saying every space is not a game board space, even though that is visually not true.

    <img src="http://i.imgur.com/6ZSxv1Y.png" border="0" />

    I've messed around with the array setup code to accommodate for the offset in Yann's random grid generator. Now I'm confused as to why this array input code works for PART of the grid but not the whole thing.

    <img src="http://i.imgur.com/tj6mMLA.png" border="0" />

  • Yann Was there a reason why all the NoZone sprites had to be offset by 0.5?

  • Here is a bit simpler version:

    Boardgame movement

  • vee41, how great of you to grace my thread with your presence!

    Joking aside, Firefly Village looks great so far!

    Currently, the link you posted doesn't work. I'll give it a few minutes as you might be uploading.

  • Fixed it, there is always additional space after the dropbox link for some reason :)

  • vee41, What do the Square.xi and Square.yi variables represent? And why is it necessary to set them to loopindexes?

  • X-index and Y-index.

    They represent the objects position at the array, so we can use them to index the array position of the square. They kind of link the 'realworld' object positions to the position in the array, this way array knows which squares are around it in each direction. So we can index the square left of square with array.at(xi+1, yi)

    Not the prettiest way to do things, but quite efficient in this case. :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think the problem, in my case, is that I want the array creation to be more flexible.

    For example, my program currently uses a script to randomly generate the game board. However, the array population function occurs in a different event sheet - the gameplay event sheet. This is because I want to be able to populate an array that represents the board state regardless of how the board was generated (whether through the random board generator or using a pre-created board state).

    However, your approach for populating the array should still work I think. You set the xi and yi values when you populate the array, so I suppose for it's okay in my program to generate the board, populate array, and then set the squares to match certain array values.

    I'll give it a shot using your array population method and let you know how it goes.

  • I think the problem, in my case, is that I want the array creation to be more flexible.

    For example, my program currently uses a script to randomly generate the game board. However, the array population function occurs in a different event sheet - the gameplay event sheet. This is because I want to be able to populate an array that represents the board state regardless of how the board was generated (whether through the random board generator or using a pre-created board state).

    However, your approach for populating the array should still work I think. You set the xi and yi values when you populate the array, so I suppose for it's okay in my program to generate the board, populate array, and then set the squares to match certain array values.

    I'll give it a shot using your array population method and let you know how it goes.

    It shouldn't matter whether the squares are generated or preplaced in my example, so it should work.

  • Your array population starts off by picking the square nearest to 0,0

    Does the array population still work if there is no square in the top left corner?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)