public void InitStart(Hacker hacker) { int[] _pos = new int[3]; _pos = hacker.GetPosition(); start.x = _pos[0]; start.y = _pos[1]; start.z = _pos[2]; }
public void Update(Hacker hacker) { //bool updateTargetFlag = false; if (!infoGot) { //获取当前角色序号 index = hacker.GetIndex(); //获取地图尺寸 mapSize = hacker.GetMapInfo(); // 20 2 22 //获取地图 foreach (int x in Range(mapSize[0])) { List <List <int?> > nextX = new List <List <int?> >(); foreach (int y in Range(1, mapSize[1] + 1)) { List <int?> nextY = new List <int?>(); foreach (int z in Range(mapSize[2])) { nextY.Add(hacker.GetMapType(x, y, z)); } nextX.Add(nextY); } map.Add(nextX); } //获取钥匙位置 int[] temp = { 0, 0, 0 }; keysPosition.Add(temp); foreach (int i in Range(1, 4)) { string sOut = "Key" + i + " "; keysPosition.Add(hacker.GetKeysPosition(i)); sOut += keysPosition[i][0] + " " + keysPosition[i][1] + " " + keysPosition[i][2]; //logger.info(sOut); } //获取出口位置 foreach (int i in Range(4)) { string sOut = "Exit" + i + " "; exitPosition.Add(hacker.GetExitPosition(i)); sOut += exitPosition[i][0] + " " + exitPosition[i][1] + " " + exitPosition[i][2]; //logger.info(sOut); } //获取电梯位置 foreach (int i in Range(1, 3)) { string sOut = "Elevator" + i + " "; List <int[]> elevatorTemp = new List <int[]>(); int[] ele = hacker.GetElevatorPosition(i); int[] eleF1 = { ele[0], 1, ele[1] }; int[] eleF2 = { ele[0], 2, ele[1] }; elevatorTemp.Add(eleF1); elevatorTemp.Add(eleF2); elevatorPosition.Add(elevatorTemp); sOut += elevatorPosition[i - 1][0][0] + " " + elevatorPosition[i - 1][0][1] + " " + elevatorPosition[i - 1][0][2] + "\n"; sOut += elevatorPosition[i - 1][1][0] + " " + elevatorPosition[i - 1][1][1] + " " + elevatorPosition[i - 1][1][2] + "\n"; //logger.info(sOut); } //获取逃跑者位置 foreach (int i in Range(1, 4)) { hackerPosition.Add(hacker.HackerPosition(i)); } //估计抓捕者位置 policePosition = exitPosition[0]; //updateTargetFlag = true; selfPosition = hacker.GetPosition(); target = ChooseTargetV2(); infoGot = true; //LOG /* * logger.info("index " + index); * logger.info("mapSize " + mapSize[0] + " " + mapSize[1] + " " + mapSize[2] + " "); * * for (int z = mapSize[2] - 1; z >= 0; z--) * { * string sOut = "[1]"; * for (int x = 0; x < mapSize[0]; x++) * { * sOut += map[x][0][z].ToString() + ","; * } * logger.info(sOut); * } * logger.info(" "); * * for (int z = mapSize[2] - 1; z >= 0; z--) * { * string sOut = "[2]"; * for (int x = 0; x < mapSize[0]; x++) * { * sOut += map[x][1][z].ToString() + ","; * } * logger.info(sOut); * } * logger.info(" "); */ //初始化 selfPosition = hacker.GetPosition(); string log2 = "POINTLIST "; pointList = SearchShortest(); foreach (int[] point in pointList) { log2 += "(" + point[0] + ", " + point[1] + ", " + point[2] + ") "; } //logger.info(log2); } //实时更新逃跑者位置与抓捕者(可能的)位置 foreach (int i in Range(1, 4)) { int[] tempPosition = hacker.HackerPosition(i); if ((tempPosition == null) && (hackerPosition[i - 1] != null)) { bool someoneIsArrestedTemp = true; foreach (int j in Range(4)) { /* * if (FindWayWholeMap(hackerPosition[i - 1], exitPosition[j]).Count > 1) * { * policePosition = hackerPosition[i - 1]; * someoneIsArrested = true; * updateTargetFlag = true; * logger.info("Hacker " + i + " is arrested! PolicePosition: (" + policePosition[0] + ", " + policePosition[1] + ", " + policePosition[2] + ")"); * break; * } */ if (FindWayWholeMap(hackerPosition[i - 1], exitPosition[j]).Count <= 1) { someoneIsArrestedTemp = false; } //logger.info("DISTANCE[" + j + "]: " + FindWayWholeMap(hackerPosition[i - 1], exitPosition[j]).Count); } if (someoneIsArrestedTemp) { policePosition = hackerPosition[i - 1]; someoneIsArrested = true; //updateTargetFlag = true; if (myKey != 0) { target = ChooseTargetV2(); } //logger.info("Hacker " + i + " is arrested! PolicePosition: (" + policePosition[0] + ", " + policePosition[1] + ", " + policePosition[2] + "), " + "policePositionUpdateSteps: " + policePositionUpdateSteps); } } hackerPosition[i - 1] = hacker.HackerPosition(i); } if (hacker.Warning()) { int[] policeNewPosition = hacker.GetPolicePosition(); if (!(policeNewPosition[0] == policePosition[0] && policeNewPosition[1] == policePosition[1] && policeNewPosition[2] == policePosition[2])) { target = ChooseTargetV2(); } policePosition = hacker.GetPolicePosition(); //updateTargetFlag = true; //target = ChooseTargetV2(); policePositionUpdateSteps = 0; //logger.info("Warning! PolicePosition: (" + policePosition[0] + ", " + policePosition[1] + ", " + policePosition[2] + ")" + ", SelfPosition: (" + selfPosition[0] + ", " + selfPosition[1] + ", " + selfPosition[2] + "), " + "policePositionUpdateSteps: " + policePositionUpdateSteps); } //实时更新自己拥有的钥匙 int newMyKey = hacker.haveKey(); if ((myKey == 0) && (newMyKey != 0)) { //logger.info("GET KEY " + newMyKey + "!"); //updateTargetFlag = true; myKey = newMyKey; target = ChooseTargetV2(); } myKey = newMyKey; if (!hacker.isMoving())//不在移动 { selfPosition = hacker.GetPosition(); if (FindWaySafe(selfPosition, target).Count == 0) { target = ChooseTargetV2(); } //int[] target = ChooseTarget(); /* * if (updateTargetFlag == true) * { * target = ChooseTargetV2(); * } */ track = FindWaySafe(selfPosition, target); if (track.Count > 0) { switch (track[0].direction) { case "U": hacker.MoveNorth(); break; case "D": hacker.MoveSouth(); break; case "L": hacker.MoveWest(); break; case "R": hacker.MoveEast(); break; } track.Remove(track[0]); } int timeRest = hacker.GetGameTime(); //logger.info("timeRest: " + timeRest); if (!hacker.Warning()) { policePositionUpdateSteps += 1; } } }
public void Update(Hacker hacker) { if (!infoGot) { //获取当前角色序号 index = hacker.GetIndex(); //获取地图尺寸 mapSize = hacker.GetMapInfo(); // 20 2 22 //获取地图 foreach (int x in Range(mapSize[0])) { List <List <int?> > nextX = new List <List <int?> >(); foreach (int y in Range(1, mapSize[1] + 1)) { List <int?> nextY = new List <int?>(); foreach (int z in Range(mapSize[2])) { nextY.Add(hacker.GetMapType(x, y, z)); } nextX.Add(nextY); } map.Add(nextX); } //获取钥匙位置 int[] temp = { 0, 0, 0 }; keysPosition.Add(temp); foreach (int i in Range(1, 4)) { string sOut = "Key" + i + " "; keysPosition.Add(hacker.GetKeysPosition(i)); sOut += keysPosition[i][0] + " " + keysPosition[i][1] + " " + keysPosition[i][2]; //logger.info(sOut); } //获取出口位置 foreach (int i in Range(4)) { string sOut = "Exit" + i + " "; exitPosition.Add(hacker.GetExitPosition(i)); sOut += exitPosition[i][0] + " " + exitPosition[i][1] + " " + exitPosition[i][2]; //logger.info(sOut); } //估计抓捕者位置 policePosition = exitPosition[0]; //获取电梯位置 foreach (int i in Range(1, 3)) { string sOut = "Elevator" + i + " "; List <int[]> elevatorTemp = new List <int[]>(); int[] ele = hacker.GetElevatorPosition(i); int[] eleF1 = { ele[0], 1, ele[1] }; int[] eleF2 = { ele[0], 2, ele[1] }; elevatorTemp.Add(eleF1); elevatorTemp.Add(eleF2); elevatorPosition.Add(elevatorTemp); sOut += elevatorPosition[i - 1][0][0] + " " + elevatorPosition[i - 1][0][1] + " " + elevatorPosition[i - 1][0][2] + "\n"; sOut += elevatorPosition[i - 1][1][0] + " " + elevatorPosition[i - 1][1][1] + " " + elevatorPosition[i - 1][1][2] + "\n"; //logger.info(sOut); } //获取逃跑者位置 foreach (int i in Range(1, 4)) { hackerPosition.Add(hacker.HackerPosition(i)); } infoGot = true; //LOG /* * logger.info("index " + index); * logger.info("mapSize " + mapSize[0] + " " + mapSize[1] + " " + mapSize[2] + " "); * * for (int z = mapSize[2] - 1; z >= 0; z--) * { * string sOut = "[1]"; * for (int x = 0; x < mapSize[0]; x++) * { * sOut += map[x][0][z].ToString() + ","; * } * logger.info(sOut); * } * logger.info(" "); * * for (int z = mapSize[2] - 1; z >= 0; z--) * { * string sOut = "[2]"; * for (int x = 0; x < mapSize[0]; x++) * { * sOut += map[x][1][z].ToString() + ","; * } * logger.info(sOut); * } * logger.info(" "); */ //初始化 selfPosition = hacker.GetPosition(); /* * string log2 = "POINTLIST "; * // pointList = SearchShortest(); * * foreach (int[] point in pointList) * { * log2 += "(" + point[0] + ", " + point[1] + ", " + point[2] + ") "; * } * logger.info(log2); */ } //实时更新逃跑者位置与抓捕者(可能的)位置 foreach (int i in Range(1, 4)) { int[] tempPosition = hacker.HackerPosition(i); if ((tempPosition == null) && (hackerPosition[i - 1] != null)) { foreach (int j in Range(4)) { if (FindWayWholeMap(hackerPosition[i - 1], exitPosition[j]).Count > 1) { policePosition = hackerPosition[i - 1]; someoneIsArrested = true; //logger.info("Hacker " + i + " is arrested! PolicePosition: (" + policePosition[0] + ", " + policePosition[1] + ", " + policePosition[2] + ")"); break; } } } hackerPosition[i - 1] = hacker.HackerPosition(i); } if (hacker.Warning()) { policePosition = hacker.GetPolicePosition(); //logger.info("Warning! PolicePosition: (" + policePosition[0] + ", " + policePosition[1] + ", " + policePosition[2] + ")"); } //实时更新自己拥有的钥匙 myKey = hacker.haveKey(); if (!hacker.isMoving())//不在移动 { selfPosition = hacker.GetPosition(); int[] target = ChooseTarget(); track = FindWaySafe(selfPosition, target); if (track.Count > 0) { switch (track[0].direction) { case "U": hacker.MoveNorth(); break; case "D": hacker.MoveSouth(); break; case "L": hacker.MoveWest(); break; case "R": hacker.MoveEast(); break; } track.Remove(track[0]); } } }