I am try to find an algorithm I can implement to automate a game I found in GitHub. Feel free to read it or test it out on your local machine as well to better understand the mechanics in case I fall short in my explanation.
Let's say I have generated a square map divided into cells, where each cell has a type and a value. There are 4 types of cells, let's call them EMPTY, WALL, BLOCK, and GOLD. In addition, the value of the cell is always a non-negative number (includes 0). Within this "map", there is one cell with the highest value in the map and is the only cell with type GOLD.
Each cell structure has some basic information regarding surrounding cells. Let's say this is the structure:
cell = {
left: {type: someValue, level: someValue},
up: {type: someValue, level: someValue},
right: {type: someValue, level: someValue},
down: {type: someValue, level: someValue},
type: someValue,
level: someValue
}
Let's say the below graph/chart represents the map, where empty cells are EMPTY, cells with 1 are BLOCKS and the single cell with 4 is the GOLD.
| Column A | Column B | Column C | Column D | Column E | Column F | Column G | Column H |
|---|---|---|---|---|---|---|---|
| 1 | WALL | WALL | 1 | 1 | |||
| 1 | 1 | 1 | |||||
| WALL | 4 | WALL | 1 | ||||
| 1 | 1 | 1 | |||||
| 1 | 1 | WALL | 1 |
My target endstate would look something like this, so that I can eventually traverse up to the GOLD (value of 4):
| Column A | Column B | Column C | Column D | Column E | Column F | Column G | Column H |
|---|---|---|---|---|---|---|---|
| 1 | WALL | WALL | |||||
| 1 | |||||||
| WALL | 4 | 3 | WALL | ||||
| 1 | 1 | 1 | 2 | ||||
| 1 | 1 | WALL |
You start on a random non-WALL, non-GOLD cell. You can only travel to a neighboring cell if the level value is +-1 or equal to your current cell's value. Cells of type WALL cannot be traversed to. Cells of BLOCK type are able to be "moved" if the value is greater than or equal to 1. Moving the BLOCK would then lower the value of cell by 1, and must be placed (and in turn, increase the value) in another cell. If the value falls to 0, the type of cell is transformed to EMPTY.
The goal is to traverse these cells, find the GOLD, and move values from BLOCKs to construct "steps" to be able to reach the GOLD at whatever elevation it is at.
I have tried to determine what kind of problem this is using some background knowledge. I am not sure if this is a graph problem or an array problem. I feel that there may be some graph/pathfinding algorithm that may be helpful to solve this problem, but not sure which or how to further determine the underlying type of problem this is!