private void createStatesGrid() { for (int i = 0; i < columnCount; i++) { List <Block.States> stateRow = new List <Block.States>(); for (int j = 0; j < rowCount; j++) { Block.States currentState = nodeGrid[i][j].state; stateRow.Add(currentState); } statesGrid.Add(stateRow); } }
public Node(int columnCount, int rowCount) { i = new int(); j = new int(); gScore = 0.0f; fScore = 0.0f; hScore = 0.0f; movementCost = 1.0f; state = Block.States.NOT_VISITED; neighbours = new List <Node>(); previous = null; cols = columnCount; rows = rowCount; }
// Parses txt file and creates blockGrid and statesGrid private void parseMaze() { string path = "Assets/Resources/TextFiles/maze20x20.txt"; StreamReader reader = new StreamReader(path); for (int i = 0; i < GRID_WIDTH; i++) { string line = reader.ReadLine(); List <Block.States> stateRow = new List <Block.States>(); List <GameObject> goRow = new List <GameObject>(); for (int j = 0; j < GRID_HEIGHT; j++) { Block.States currentState = Block.States.NOT_VISITED; switch (line[j]) { case 'O': currentState = Block.States.NOT_VISITED; break; case '#': currentState = Block.States.WALL; break; case 'S': currentState = Block.States.START; break; case 'E': currentState = Block.States.END; goal_i = i; goal_j = j; break; } GameObject go = Instantiate(Resources.Load("Prefabs/BlockPrefab", typeof(GameObject))) as GameObject; go.GetComponent <Block>().setCoordinates(i, j); go.GetComponent <Transform>().position = new Vector3(j, -i, 0); goRow.Add(go); stateRow.Add(currentState); } statesGrid.Add(stateRow); blockGrid.Add(goRow); } initialGrid = statesGrid; }
public void updateBlock(int i, int j, Block.States state) { blockGrid[i][j].GetComponent <Block>().switchState(state); blockGrid[i][j].GetComponent <Block>().checkState(); }