#include <iostream> #include <cstdlib> #include <ctime> #include <set> #include…
- User
#include #include #include #include #include #include #include <bits/stdc++.h> #include "hlt.hpp" #include "networking.hpp"
using namespace std;
vector<vector> wasMoved;
void initWasMoved(hlt::GameMap &presentMap) { wasMoved = vector<vector>(presentMap.width, vector(presentMap.height, false)); }
void clearWasMoved() { for (unsigned short a = 0; a < wasMoved.size(); a++) { for (unsigned short b = 0; b < wasMoved[a].size(); b++) { wasMoved[a][b] = false; } } }
bool isAtBorder(hlt::GameMap &presentMap, hlt::Location location, unsigned char myID) { if (presentMap.getSite(location).owner == myID) { return false; } for (unsigned char direction = 1; direction < 5; direction++) { hlt::Location neighbor = presentMap.getLocation(location, direction); if (presentMap.getSite(neighbor).owner == myID) { return true; } } return false; }
bool compareLocations(hlt::Location a, hlt::Location b) { return a.x == b.x && a.y == b.y; }
unsigned char getDirection(hlt::GameMap& presentMap, hlt::Location& loc1, hlt::Location& loc2) { if (loc1.x == loc2.x) { if (loc1.y < loc2.y) { return SOUTH; } else { return NORTH; } } else { if (loc1.x < loc2.x) { return EAST; } else { return WEST; } } }
double getScore(hlt::GameMap &presentMap, hlt::Location loc) { return 5 * presentMap.getSite(loc).production - 0.7 * presentMap.getSite(loc).strength + 50; }
int calculateStrengthAfter(hlt::GameMap &presentMap, hlt::Location loc, int steps) { return presentMap.getSite(loc).strength + steps * presentMap.getSite(loc).production; }
vectorhlt::Move getLocsAround(hlt::GameMap &presentMap, hlt::Location loc, unsigned char myID, int steps) { vectorhlt::Move locs; hlt::Move moves[] = { {presentMap.getLocation(loc, NORTH), SOUTH}, {presentMap.getLocation(loc, SOUTH), NORTH}, {presentMap.getLocation(loc, WEST), EAST}, {presentMap.getLocation(loc, EAST), WEST} };
for (auto move : moves) { hlt::Location loc = move.loc; if (presentMap.getSite(loc).owner == myID && !wasMoved[loc.x][loc.y]) { locs.push_back(move); } } sort(locs.begin(), locs.end(), [&](hlt::Move a, hlt::Move b) { return calculateStrengthAfter(presentMap, b.loc, steps) < calculateStrengthAfter(presentMap, a.loc, steps); }); return locs;}
void setWasMoved(hlt::GameMap &presentMap, vectorhlt::Move moves) { for (auto move : moves) { wasMoved[move.loc.x][move.loc.y] = true; } }
vectorhlt::Move tryToTakeOver(hlt::GameMap &presentMap, hlt::Location loc, unsigned char myID, int steps) { vectorhlt::Move moves; vector locs = getLocsAround(presentMap, loc, myID, steps);
- Assistant