Basically I have 4 grids Left, Right, Top, Bottom. Player can choose each of them and move all the blocks on that grid to the Middle grid to fulfill it, like tetris from 4 directions:
|0 0 0| |0 0 0| (0 is empty, 1 is generated block) |0 0 1| _ _ _ Bottom->Mid Right->Mid Top->Mid Left->Mid |0 0 0|0 0 0|0 1 0| |1 0 0| |1 1 0| |1 1 1| |1 1 1| |0 0 0|0 0 0|0 1 1| |1 0 0| |1 1 1| |1 1 1| |1 1 1| -> Win! Generate |1 0 0|0 0 0|0 1 1| |0 0 0| |0 1 1| |0 1 1| |1 1 1| another game. _ _ _ |0 0 0| |1 0 0| |1 0 0|
The point here is to make sure there is at least 1 way player can combine all 4 grids.
What I've tried so far is generate the right order first (Left->Right->Top....), then generate all the blocks 1 by 1. When a block is generated, i perfomn a check with the generated order (move all the blocks in Left to Mid, then Right then Top...) to see if its still working, the code is similar to this:
// (left->right, top->right->botttom->left, top... it doesn't have to be all 4 directions)
Random the right direction order.
Generate all possible coordinates from all the directions from the path above.
Initialize an empty list to store all chosen coordinates.
While(!(Generate enough x*x block))
{
Remove one coordinate from all possible coordinates and add it into chosen list.
if (!(Perform a check with the right order and the chosen list.))
Remove it from the chosen list.
}
The problem here is a block can be wrong at this point, but it can become right when another block is generated, so i can't choose to add or remove it and go to the next one:
|0 0 0| |0 0 1| |0 0 1| |0 0 1| |0 0 1| |0 0 1| _ _ _ _ _ _ |0 1 0|0 0 0|0 0 0| |0 1 0|0 0 0|0 0 0| |1 0 0|0 0 0|0 0 0| |1 0 0|0 0 0|0 0 0| |1 0 0|0 0 0|0 0 0| |1 0 0|0 0 0|0 0 0| _ _ _ _ _ _ |0 1 0| |0 1 0| |0 1 0| |0 1 0| |0 0 0| |0 0 0| At this point the logic is wrong But if I add 1 more block to the with Top->Left->Bottom order. top grid, it'll become right.
So is there a way I can generate each block and check its logic? Or is there a better way, algorithm to do it?
Aucun commentaire:
Enregistrer un commentaire