[SOLVED] Checking if the Player has a Possible Move

https://snowyrawrgamer.itch.io/test-block-blast/download/EdfqPtVG5i3T3RJtOSecq_es_sgnNvlYRH9k34FK

(Link does not work anymore, see OP)

My code is such a mess right now, I tried for a good 30 minutes to fix the problem and it’s still all jumbled around right now. :pensive:

There’s a link to the project so you can test it out in the editor, let me know if you can figure it out. :pray:

As of that zip file, it is currently checking to see that ALL the squares fit instead of ANY.

EDIT:

Problem is solved! Tysm for everyone’s help :smile:

Open your mind

Top left image
Let’s assume gray tiles are empty
Red are occupied

Top Right
Imagine we duplicate our grid with different objects somewhere
And now we delete tiles which were occupied (or better yet don’t create them at all)
GREEN is our checker object
Now let’s move it each frame to the right by 1 tile position
IF our checker.X()+checker.Width() is greater than our fake grid X + Width()
Then we move our checker 1 tile position down and reset it to the left

BUT that is for noobs
And that is why

Bottom Left
We spawn as many checkers as we can on the left
And we let them go to the right 1 frame at a time
With that grid 8 frames would take to check if there is available move for this shape

BTW each move we check if checkers are in collision with gray tiles
If not then there is available move

BUT that is still for noobs
And that is why

Bottom Right
We spawn all our shapes on top on each other
And we move them all 1 frame to the right by 1 tile positon
Checking if they are NOT in collision with gray tiles
Some shapes cannot be dealt this way so we actually gonna need revert back to moving them 1 tile position down and resetting their X position when they reach end of board

You could do it with points to save performance
You could have multiple fake grids to check MORE combos at once
Whole check process could take 1 frame if you would do in more clever way
You could even give fake grid tiles ID variables
And advance checkers by these IDs
So if there is tile with ID 1 2 but not 3 and 4 and next existing is 5
We would go 1 2 5
So process would be speed up even further

Amount of optimization ideas i could vomit at you here would make this longest topic you would ever see in your life
Amount of ways it could be done would make this topic give me error for being too long (yes thats possible you can exceed allowed characters count)

You could literally in 1-4 frames check all combos with pieces being rotated in all possible directions
Even flipped horizontally or vertically (if that would change anything)

And all that could happen on hidden layer or beyond viewport
And you could run it as soon as player place piece on grid

All you really had to do is
Change checker X position (let’s assume your tiles are 16x16) add 16
Checker.X()+Checker.Width() is greater than Grid.X()+Grid.Width()
You could also store grid right side position in variable and compare against that
There is also condition to pick nearest object to SOMETHING
You could do all that when space key was just pressed to actually see what is happening
Then after you get it to move/detect properly just run it without any condition to kick it in each frame
To copy gird you could delete grid tile at position of original gird tile + some offset but only for occupied tiles
HECK you could not even delete anything
You could have there tiles with different colors and flip them

And then Keith came in with arrays
My god how that would speed up things but bit complex

Anyway lesson for today is even so you solved it
You got it working
YOU DO NOT need to even try what i said
But look how now many things just become obvious

You was looking to do it in THIS specific way instead of thinking outside of the box or just brute force your way trough it
That is worst thing you can do to yourself

Papu zero will be back with even more useless tips
Or not

Those are some great ideas, but they all seem pretty relevant to the solution I used.

Also, I just want to say, there are a LOT of solutions that look good on paper, but when you try to actually implement them in code, they break.

Take MagicSofa’s for example:

This looks like it would filter down the Squares, but in reality it actually just returns false if you have multiple Squares picked.

Also, at this moment I don’t really care how many frames it takes (as long as it isn’t a noticeable amount) and so I’m just happy that I got a solution of some sort :smile:

EDIT:

For reference, the only other people who gave other ideas (before I got the solution) were you and Keith. Keith’s array isn’t the best (as you’ve said yourself) and your idea was quite similar to mine :smile:

I also tried out all of MagicSofa’s improvements and they didn’t work (mostly because this whole solution thing is stuck inside another system)

Anyways, I’m just happy everything is working at the moment :smile:

Bubble gave you exact solution
You just didn’t connect it with what you already know

And i didn’t even read what you did
But i can bet you did rush it instead of doing it with for example press space to check another tile

Imagine this
Condition
Variable StartCheck is true

Action
Put Checker at X SOMETHING Y Something
Change variable StopChecker set to FALSE
That is how you reset it after player placed piece
But for now you manually set this variable to true with let’s say enter
StopChecker is there so whole check system run on its own and when you set it to true it stops

Now
Variable StopChecker = False
Space key is just pressed

Change Checker X position add 16

SUB EVENT to that
Checker X position is greater than Grid.BoundingBoxRight()-Checker.Width()

Change checker X position set to Grid.X()
Change checker Y position add 16

2nd sub event
Checker Y position is greater than Grid.BoundingBoxBottom()

ACTION
Change variable StopChecker set to TRUE

THAT is how you stop it when checker goes one tile position below grid

Of course it would vary between different pieces

But all that above logic lack is you just checking if checker is NOT in collision with occupied tiles
And so you hit space to test it does it work
ONE tile space at a time
You see everything and it works
You only remove Space key just pressed from above logic and it auto runs

Now you could test it with more checkers
You could test it with more grids
You could do A LOT

And somehow now its simple when you look at what i just wrote
Actually in my previous message with images i made it wrong
In duplicate grid you should delete tiles which are NOT occupied
And now you would check if checker is NOT in collision with existing tiles
And you would know if there is available move left or not

Never you should aim to build correct logic at once
You should always build pieces of it

Sorry, I missed Bubble’s reply when looking for who gave answers :sweat_smile:

Bubble’s response is pretty much the same thing as what I did, just without ghost blocks :smile:

I’m glad you’ve found a solution that works, but I just want to reiterate that this statement is not true. The whole point of object filtering is to reduce the number of picked instances based on a condition. It doesn’t matter if you used “pick all” - as I mentioned, all instances are picked anyway at the start of a new set of conditions.

The “compare two numbers” condition does not pick objects, and the way I wrote the above does look more like that condition than the one I was intending for you to use (“The variable Slot of Squares is equal to piece”)

MY BAD!

I was using Object Variable Value instead of Compare 2 Numbers :laughing:

Hm? You don’t want compare two numbers. That doesn’t pick objects. You want Object Variable Value, which does filter the Object type you select.

Misunderstood your other post, sorry! :sweat_smile:

Either way, I’ve got it solved. :smile: