Each block has its own custom collision to only collide with the visible parts of the block. Also, the board is made up of 64 1x1 tile maps that can change color.
My question is, how could I check if the player has a valid move, and if not, set the variable “Lost” to True?
A valid move is when a player can place one of their 4 pieces onto the board, without it colliding with any other colors on the board, and without any of the piece hanging off the board. (For clarity, the pieces the player receives are randomly picked)
If I understand correctly, 1 move is valid if and only if:
no collision between blocks already present on the playing area
the block is not outside the playing area (8x8 squares)
For 1) it’s easy to test.
For 2) we can for example put an invisible sprite (very low order) which would be right on the light gray part (see below) and test that there is no collision with this sprite
Amigo, I don’t think it’s about detecting pieces already placed on the board by the player, it’s about predicting whether there is a valid place for a piece.
It will be interesting to see what ideas the brains come up with. All I’ve got is that you would have to go through each piece the player has left and place a ghost object of that shape on the board, moving it over one grid square at a time until one of two things - a place is found that meets the requirements or it gets to the end of the grid not having found a place.
Sadly, that doesn’t help. The light grey area is just a block there to check outside collision.
I’ve tried that and that’s where I got stuck. I’ve ran through many different iterations of moving the piece to every spot one by one, but all of them either incorrectly detect available/not available spots, or fire the checker before it’s done moving all the squares to the different spots.
If it helps, this is what I currently have (I’ve had many other versions but I delete them to try and remake it working )
You’ve thrown the tricky bit at us here. I’ll have a think at work…because there’s so many possible combinations (im assuming that you can rotate l shapes) it needs an efficient algorithm and i think using an array of spaces that are available and each animation is a pattern of checks agaist the array rather than literally testing collisions might be best. I’ll think about it while im making penguins
Actually, I haven’t implemented rotating shapes due to them not working with custom collision masks (I think?) currently my collision masks just look like this:
So they are fully set up for testing positions. The main problem I had was figuring out how to get the code to understand what constitutes a “correct” move. It’s really easy to tell it what an incorrect move is (collision with the outside or collision with a tile that has an ID that isn’t 0) but it’s much harder to check if the block isn’t in collision with a tile that has an ID that isn’t 0.
The reason I’m struggling is because if you have it go through every tile map object for every one of the 64 positions, that’s going to start messing up really fast, especially trying to run it 4 times in 1 frame (for the 4 blocks).
The only thing I can think of is MAYBE when I change a Tile ID from 0 to whatever other number, I place a collision checker there as well with the size of the block, and then check collision with that?
Wait…that might actually work! I’m gonna test it out in a few mins, I’ll let you know it goes.
I feel like you are overthinking this a bit. You already have the ability to check if a move is valid right? So you should be able to re-use that logic to check if any moves are available.
You only need to run this check when the board changes. It shouldn’t be happening at any other time. When a piece is placed on the board, the events should be locked until either the lose condition is met, or a valid move is found. Checking 256 collisions should be no problem for the engine, so I wouldn’t worry about keeping the UI responsive during the check. If you did want to make it faster, you could check tiles rather than use a collision mask.
There is no difference. One gives you the other. If the check for incorrect move fails, then it is a possible move. If you’re having trouble with this, then the issue must be in your event structure, not the actual checking logic. Otherwise, you would have problems with the player being able to make illegal moves.
What you would want is a loop that checks every possible position for each piece, and the loop breaks when a legal move is found. So basically there should be a single variable to represent that the current check is not a possible move. I might name it “blocked”.
I wouldn’t use a repeat x times for the whole thing because you can’t bail out of that - the event will always fire that many times. Instead, use ‘while’
Local vars: blocked = TRUE
piece = 4
X = 0
Y = 0
---------------------------------------
while
blocked = TRUE
piece > 0
do
<empty condition> | blocked = FALSE
------------------------------------------------
Squares.slot = piece | move Squares to X,Y
-------------------------------------------
Squares in collision? | blocked = TRUE
------------------------------------------------
<empty condition> | X += 1
--------------------------------------------
X > 7 | X = 0
| Y += 1
--------------------------------------------
Y > 7 | Y = 0
| piece -= 1
If at the end of the loop, blocked is still TRUE, then there are no moves left. On the other hand if at any point the Squares are not in collision with the existing tiles, then blocked will stay FALSE and the loop will stop checking any further since you only need 1 possible move to keep playing.