Daily Challenge (245 Part Series)
To play the game, you'll start with a gameMap, like this one:
+----+ |.B..| +,-,| --> The boundary of game map |....| B --> The initial color block |....| . --> The empty block |..B.| It is always a rectangular shape +----+
The goal of the game is to move the blocks in a way that would fill in the empty spaces.
- Each block can only move once.
- If it hits an obstacle, the block will make a 90 degree right turn. It will stop if it's path is still blocked.
- Specify the direction of movement for each color block (Left, Right, Up, Down).
- Your output should be a 2D array.
- Each subarray should contain 3 elements: [rowIndex, columnIndex, diretion].
rowIndexand `columnIndex are 0-based, diretion should be one of "Left", "Right", "Up" and "Down".
For the gameMap above, the output should be [[0,1,"Down"],[3,2,"Up"]].
Not all testcases have a solution, if there is no solution, please return a boolean value false.
For the gameMap above: we can move block A downward, which would make it turn right once it hits the walls, and it will stop next to where we started. We can move B up for the same
+----+ |aAbb| # First colered block is designated 'A' |aabb| |aabb| |aaBb| # Second colored block is designated 'B', etc. +----+ The output should be [[0,1,"Down"],[3,2,"Up"]].
Awesome, so now we have all the spaces colored. If you want to see a live version of this game, you can play it here: https://www.bgames.com/puzzle-games/flou/
+----+ |B...| |....| |....| |....| +----+ +----+ |.AB.| |....| |....| |....| +----+ +----+ |B...| |A...| |....| |....| +----+
Want to propose a challenge idea for a future post? Email email@example.com with your suggestions!