string AI01::useRockfall_E(const Status& enemy) { string str; const auto ninjas = enemy.getNinjas(); const Stage stage(enemy.getStageDogStatus()); for (const auto ninja : ninjas) { int count = 0; for (const auto dir : directionPoint) { const Point p1 = ninja.point + dir; const Point p2 = ninja.point + dir + dir; if (stage.getState(p1) == Stage::State::Rock) { if (stage.getState(p2) != Stage::State::None) { count++; } } } if (count < 2) continue; for (const auto dir : directionPoint) { const Point p1 = ninja.point + dir; const Point p2 = ninja.point + dir + dir; if (stage.getState(p1) == Stage::State::None) { if (stage.getState(p2) != Stage::State::None) { str = "2 " + to_string(p1.y) + " " + to_string(p1.x); return str; } } else if (stage.getState(p1) == Stage::State::Rock) { if (stage.getState(p2) == Stage::State::None) { str = "2 " + to_string(p1.y) + " " + to_string(p1.x); return str; } } } } return str; }
string AI01::useAvatar_E(const Status& enemy) { string str; const auto ninjas = enemy.getNinjas(); const Stage stage(enemy.getStageDogStatus()); for (const auto ninja : ninjas) { int count = 0; int dogCount = 0, wallCount = 0, noneCount = 0; for (const auto& dir : directionPoint) { switch (stage.getState(ninja.point + dir)) { case Stage::State::Dog: dogCount++; break; case Stage::State::None: noneCount++; break; case Stage::State::Rock: case Stage::State::Wall: wallCount++; break; } } if (dogCount >= noneCount) { str = "6 " + to_string(ninja.point.y) + " " + to_string(ninja.point.x); } return ""; for (int i = -3; i < 4; i++) { for (int j = -3; j < 4; j++) { const Point p = ninja.point + Point(i, j); if (0 <= p.x && p.x < StageX) { if (0 <= p.y && p.y < StageY) { if (stage.getState(p) == Stage::State::Dog) count++; } } } } if (enemy.getNinjutsuNumber()[5] > 2) { if (count >= 2) { str = "6 " + to_string(ninja.point.y) + " " + to_string(ninja.point.x); return str; } } else { if (count >= 10) { str = "6 " + to_string(ninja.point.y) + " " + to_string(ninja.point.x); return str; } } } return str; }
void AI01::think(const Status& my, const Status& enemy) { setCost(my.getNinjutsuCost()); ninjutsuPoint = Point(-1, -1); array<vector<MoveCommand>, 2> move; Status status(my); for (int i = 0; i < 2; i++) { try { move[i] = dogEscape.getCommand2(i, status); int ninryoku = my.getNinryoku() - defenceSort[3].first; if (ninryoku > 0) { if (ninryoku >= Status::getNinjutsuCost(NinjutsuCommand::RotatinCut)) { const auto ninjas = my.getNinjas(); const Stage stage(my.getStageDogStatus()); int dogCount[2] = { 0 }; for (int j = 0; j < 2; j++) { for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { if (stage.getState(ninjas[j].point + Point(x, y)) == Stage::State::Dog) { dogCount[j]++; } } } } if (dogCount[i] >= dogCount[1 - i]) { if (dogCount[i] >= 3) { cerr << "回転斬!" << endl; ninjutsuFlag = true; ninjutsuString = "7 " + to_string(i); } } } else { useNinjutsuA(enemy, ninryoku); } } } catch (logic_error e) { if (!ninjutsuFlag) { try { move[i] = useNinjutsuD(my, status, e.what(), i); } catch (invalid_argument) { return; } } } if (move[i].empty()) { move[i] = soulFind.getCommand2(i, status); if (move[i].size() == 1) { Status nextStatus(status); auto soul = status.getSoulPoints(); auto stage = status.getStage(); const auto p = Stage::moveSimulation(status.getNinjas()[i].point, move[i][0], stage); for (auto it = soul.begin(); it != soul.end();) { if (p == *it) it = soul.erase(it); else ++it; } nextStatus.setSoulPoints(soul); auto m = soulFind.getCommand2(i, status); move[i].push_back(m[0]); } } Point p = status.getNinjas()[i].point; Stage stage = status.getStage(); auto soulPoints = status.getSoulPoints(); for (const auto& c : move[i]) { p = Stage::moveSimulation(p, status.getNinjas()[(i + 1) % 2].point, c, stage, status.getDogs()); for (auto it = soulPoints.begin(); it != soulPoints.end();) { if (p == *it) it = soulPoints.erase(it); else ++it; } } array<Character, 2> nextNinjas = status.getNinjas(); nextNinjas[i] = Character{ i, p }; if (ninjutsuFlag) { if (ninjutsuString[0] == '1')//落石 { auto arr = stage.getStage(); arr[ninjutsuPoint.x][ninjutsuPoint.y] = Stage::State::Rock; stage = Stage(arr); } else if (ninjutsuString[0] == '3')//雷撃 { auto arr = stage.getStage(); arr[ninjutsuPoint.x][ninjutsuPoint.y] = Stage::State::None; stage = Stage(arr); } else if (ninjutsuString[0] == '5')//自分身 { } else if (ninjutsuString[0] == '7')//回転斬 status.eraseDogs(status.getNinjas()[i].point); } status.setSoulPoints(soulPoints); status.setStage(stage); status.setNinjas(nextNinjas); } characterMove = move; }