/// <summary> /// Deprecated! Reads the state map from file. /// </summary> /// <returns> /// The Dictionary representing the state map. /// </returns> /// <param name='filename'> /// The path to state map file. /// </param> /// <remarks> /// File format: <numVirtualStates> <numAgentProp> <numHelperProp> <numMonsterProp> <numSpecLocProp>. /// In the current implementation, numAgentProb = numHelperProp = 3, numMonsterProp = 4 or 5 depending /// on whether there is any hit point. /// /// Thereafter are: <agentRegion> <agentX> <agentY> <helperRegion> <helperX> <helperY>. /// Then: <monsterX> <monsterY> <seesAgent> <seesHelper> <additional props>[]. /// </remarks> public Dictionary <VirtualState, int> readStateMapping(string filename) { //UnityEngine.Debug.Log("readStateMapping from "+filename); string uncompressedStr = ZlibDecompression.decompress(filename); string[] strArray = uncompressedStr.Split(' '); Dictionary <VirtualState, int> result = new Dictionary <VirtualState, int>(); //int xSize = parentScript.levelData.xSize; //int ySize = parentScript.levelData.ySize; // 1. read number of virtual states int numVirtualStates = int.Parse(strArray[0]); UnityEngine.Debug.Log("readStateMapping from " + filename + ", num Virtual States =" + numVirtualStates); VirtualState state; // = new VirtualState(); //state.monsterProperty. int sizeMonster = int.Parse(strArray[3]) - 2; // exclude seesAgent and seesHelper int sizePerState = int.Parse(strArray[1]) + int.Parse(strArray[2]) + int.Parse(strArray[3]) + int.Parse(strArray[4]); int offset; for (int i = 0; i < numVirtualStates; i++) { state = new VirtualState(sizeMonster); offset = 4 + i * sizePerState; // a. agent and helper // exclude the first element, being the region id state.playerProperties[0, 0] = int.Parse(strArray[offset + 2]); state.playerProperties[0, 1] = int.Parse(strArray[offset + 3]); state.playerProperties[1, 0] = int.Parse(strArray[offset + 5]); state.playerProperties[1, 1] = int.Parse(strArray[offset + 6]); // b. NPC, exclude seesAgent and seesHelper because we are dealing with no abstraction here. offset = offset + 7; state.monsterProperty[0] = int.Parse(strArray[offset]); state.monsterProperty[1] = int.Parse(strArray[offset + 1]); for (int j = 4; j < sizeMonster + 2; j++) { state.monsterProperty[j - 2] = int.Parse(strArray[offset + j]); } // c. I'm not dealing with specialLocation here. // d. Add into result try{ result.Add(state, i); } catch { UnityEngine.Debug.Log("Duplicated Virtual State " + i + ": " + state.ToString()); } } return(result); }
/// <summary> /// Deprecated! Generates the state map. /// </summary> /// <returns> /// The Dictionary representing the state map. /// </returns> /// <param name='npcType'> /// Npc type. /// </param> public Dictionary <VirtualState, int> generateStateMap(int npcType) { //UnityEngine.Debug.Log("generateStateMap"); VirtualState state; Dictionary <VirtualState, int> result = new Dictionary <VirtualState, int>(); int sizeMonster = GameConstants.numProperties[npcType]; //state = new VirtualState(sizeMonster); // stateIndex 0 is termState, no need to store. int stateIndex = 1; // 1. construct a state // TODO: may need to change to ySize first, xSize next, also the coordinates is i, ySize - j -1 for (int p1x = 1; p1x < parentScript.levelData.xSize - 1; p1x++) { for (int p1y = 1; p1y < parentScript.levelData.ySize - 1; p1y++) { if (parentScript.levelData.map[p1x, parentScript.levelData.ySize - p1y - 1] != GameConstants.Wall) { for (int p2x = 1; p2x < parentScript.levelData.xSize - 1; p2x++) { for (int p2y = 1; p2y < parentScript.levelData.ySize - 1; p2y++) { if (parentScript.levelData.map[p2x, parentScript.levelData.ySize - p2y - 1] != GameConstants.Wall) { for (int mx = 1; mx < parentScript.levelData.xSize - 1; mx++) { for (int my = 1; my < parentScript.levelData.ySize - 1; my++) { if (parentScript.levelData.map[mx, parentScript.levelData.ySize - my - 1] != GameConstants.Wall) { state = new VirtualState(sizeMonster); state.playerProperties[0, 0] = p1x; state.playerProperties[0, 1] = p1y; state.playerProperties[1, 0] = p2x; state.playerProperties[1, 1] = p2y; state.monsterProperty[0] = mx; state.monsterProperty[1] = my; // if NPC is ghost, there is HP. if (npcType == GameConstants.GhostType) { for (int hp = 0; hp <= parentScript.ghostMaxHP; hp++) { state.monsterProperty[2] = hp; try{ result.Add(state, stateIndex); // if (stateIndex <= 10) // UnityEngine.Debug.Log("Virtual State " + stateIndex + // ": " + state.ToString()); stateIndex++; } catch { UnityEngine.Debug.Log("Duplicated Virtual State " + stateIndex + ": " + state.ToString()); } } } // Otherwise, no additional property else { try{ result.Add(state, stateIndex); // if (stateIndex <= 10) // UnityEngine.Debug.Log("Virtual State " + stateIndex + // ": " + state.ToString()); stateIndex++; } catch { UnityEngine.Debug.Log("Duplicated Virtual State " + stateIndex + ": " + state.ToString()); } } } } } } } } } } } UnityEngine.Debug.Log("generate state map for " + GameConstants.NPCTypeStr[npcType] + ", num Virtual States =" + stateIndex); return(result); }