private void UpdateBlock(string cacheName,int x, int y, int z, BlockNeighbour[] connected,IPathfindingAgent agent) { var cache = nodes [cacheName]; cache [x, y, z].LValue = 0; cache [x, y, z].RValue = 0; cache [x, y, z].BValue = 0; cache [x, y, z].FValue = 0; for (int i = 0; i < connected.Length; i++) { var connect_blocks = connected [i].block; if (agent.canUseForPathfinding (connect_blocks)) { int xPosition = ((int)connect_blocks.intPosition.x); int zPosition = ((int)connect_blocks.intPosition.z); int x_diff = xPosition- x; int z_diff = zPosition - z; if (x_diff == 1 ) { //float estimatedReward = futureState.RValue; cache [x, y, z].RValue =.00001f; } else if (x_diff == -1) { //float estimatedReward = futureState.LValue; cache [x, y, z].LValue =.00001f; } else if (z_diff == 1) { //float estimatedReward = futureState.FValue; cache [x, y, z].FValue = .00001f; } else if (z_diff == -1) { //float estimatedReward = futureState.BValue; cache [x, y, z].BValue = .00001f; } } } }
public NodeState GetNode(string cacheName,int x, int y,int z,Block associatedBlock,IPathfindingAgent agent) { var cache = nodes [cacheName]; if (cache [x, y, z] == null) { cache [x, y, z] = new NodeState (this, x, y, z, cacheName, associatedBlock); var connected = associatedBlock.getConnected (); for (int i = 0; i < connected.Length; i++) { int xPos = (int)connected [i].block.intPosition.x; int yPos = (int)connected [i].block.intPosition.y; int zPos = (int)connected [i].block.intPosition.z; if (cache [xPos, yPos, zPos] != null) { UpdateBlock (cacheName, xPos, yPos, zPos, cache [xPos, yPos, zPos].AssocaitedBlock.getConnected (), agent); } } UpdateBlock (cacheName, x, y, z, connected, agent); } return cache [x, y, z]; }