public void Update(Police police) { //logger.info("hacker0 Key:" + police.GetHackerKey(1)); if (!infoGot) { //获取地图尺寸 mapSize = police.GetMapInfo(); // 20 2 22 //获取地图 //foreach (int x in Range(mapSize[0])) for (int x = 0; x < mapSize[0]; ++x) { List <List <int?> > nextX = new List <List <int?> >(); //foreach (int y in Range(1, mapSize[1] + 1)) for (int y = 1; y < mapSize[1] + 1; ++y) { List <int?> nextY = new List <int?>(); //foreach (int z in Range(mapSize[2])) for (int z = 0; z < mapSize[2]; ++z) { nextY.Add(police.GetMapType(x, y, z)); } nextX.Add(nextY); } map.Add(nextX); } //获取钥匙位置 int[] temp = police.GetExitPosition(0); keysPosition.Add(temp); //foreach (int i in Range(1, 4)) for (int i = 1; i < 4; ++i) { //string sOut = "Key" + i + " "; keysPosition.Add(police.GetKeysPosition(i)); //sOut += keysPosition[i][0] + " " + keysPosition[i][1] + " " + keysPosition[i][2]; //logger.info(sOut); } //获取出口位置 //foreach (int i in Range(4)) for (int i = 0; i < 4; ++i) { //string sOut = "Exit" + i + " "; exitPosition.Add(police.GetExitPosition(i)); //sOut += exitPosition[i][0] + " " + exitPosition[i][1] + " " + exitPosition[i][2]; //logger.info(sOut); } //获取电梯位置 //foreach (int i in Range(1, 3)) for (int i = 1; i < 3; ++i) { //string sOut = "Elevator" + i + " "; List <int[]> elevatorTemp = new List <int[]>(); int[] ele = police.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)) for (int i = 1; i < 4; ++i) { hackerPosition.Add(police.HackerPosition(i)); List <string> movement = new List <string> { "UD", "LR", "UD", "LR", "UD" }; hackerMoment.Add(movement); HackerInfo newHackerInfo = new HackerInfo(); UpdateHackerInfo(newHackerInfo, i); hackerInfos.Add(newHackerInfo); } infoGot = true; //LOG /* * 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 = police.GetPosition(); } //foreach (int i in Range(1, 4)) for (int i = 1; i < 4; ++i) { int[] hackerPositionTemp = police.HackerPosition(i); if (hackerPositionTemp != null) { if (hackerPositionTemp[0] != hackerPosition[i - 1][0]) { hackerMoment[i - 1].Remove(hackerMoment[i - 1][0]); hackerMoment[i - 1].Add("LR"); } else if (hackerPositionTemp[2] != hackerPosition[i - 1][2]) { hackerMoment[i - 1].Remove(hackerMoment[i - 1][0]); hackerMoment[i - 1].Add("UD"); } } else { hackerAlive[i - 1] = false; } hackerPosition[i - 1] = police.HackerPosition(i); } if (!police.isMoving())//不在移动 { //foreach (int i in Range(1, 4)) for (int i = 1; i < 4; ++i) { hackerKey[i - 1] = police.GetHackerKey(i); //logger.info("A" + police.GetGameTime()); UpdateHackerInfo(hackerInfos[i - 1], i); //logger.info("B" + police.GetGameTime()); } /* * logger.info(police.GetGameTime() + "s SelfPos: (" + selfPosition[0] + ", " + selfPosition[1] + ", " + selfPosition[2] + ") " + "[HackerInfo] Target 1: " + hackerInfos[0].target + " 2: " + hackerInfos[1].target + " 3: " + hackerInfos[2].target + " Key 1: " + hackerInfos[0].hackerKey + " 2: " + hackerInfos[1].hackerKey + " 3: " + hackerInfos[2].hackerKey + " Pos 1: (" + hackerInfos[0].pos[0] + ", " + hackerInfos[0].pos[1] + ", " + hackerInfos[0].pos[2] + ") " + "2: (" + hackerInfos[1].pos[0] + ", " + hackerInfos[1].pos[1] + ", " + hackerInfos[1].pos[2] + ") " + "3: (" + hackerInfos[2].pos[0] + ", " + hackerInfos[2].pos[1] + ", " + hackerInfos[2].pos[2] + ") " + " ArrestPos 1: (" + hackerInfos[0].arrestPos[0] + ", " + hackerInfos[0].arrestPos[1] + ", " + hackerInfos[0].arrestPos[2] + ") " + "2: (" + hackerInfos[1].arrestPos[0] + ", " + hackerInfos[1].arrestPos[1] + ", " + hackerInfos[1].arrestPos[2] + ") " + "3: (" + hackerInfos[2].arrestPos[0] + ", " + hackerInfos[2].arrestPos[1] + ", " + hackerInfos[2].arrestPos[2] + ") "); */ selfPosition = police.GetPosition(); pointList = SearchNearestHacker(); if (hackerMoment[nearestHacker - 1].Count(s => s == "UD") > hackerMoment[nearestHacker - 1].Count(s => s == "LR")) { perferenceDirection = "LR"; } else { perferenceDirection = "UD"; } if (pointList.Count > 0) { track = FindWayWholeMap(selfPosition, pointList[0]); if (track.Count > 0) { switch (track[0].direction) { case "U": police.MoveNorth(); break; case "D": police.MoveSouth(); break; case "L": police.MoveWest(); break; case "R": police.MoveEast(); break; } track.Remove(track[0]); } } } }