GitLab Commit is coming up on August 3-4. Learn how to innovate together using GitLab, the DevOps platform. Register for free: gitlabcommitvirtual2021.com

Commit 8a1e108d authored by Rob Van Keilegom's avatar Rob Van Keilegom
Browse files

v5.0

parent 9beba02c
......@@ -3,9 +3,7 @@
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
/**
* Shoot enemies before they collect all the incriminating data!
* The closer you are to an enemy, the more damage you do but don't get too close or you'll get killed.
......@@ -13,7 +11,6 @@ using namespace std;
int main()
{
// game loop
while (1) {
......@@ -27,25 +24,30 @@ int main()
int data[dataCount][3];
for (int i = 0; i < dataCount; i++) {
cin >> data[i][0] >> data[i][1] >> data[i][2]; cin.ignore();
int dataId = data[i][0];
int dataX = data[i][1];
int dataY = data[i][2];
}
int enemyCount;
cin >> enemyCount; cin.ignore();
int enemies[enemyCount][5];
int enemies[enemyCount][7];
// ID, X, Y, LIFE, DISTANCE, CLOSEST DATA POINT, DISTANCE TO CLOSEST DATAPOINT
int priorityEnemy = -1;
int closestEnemy = -1;
int secondClosestEnemy = -1;
bool move = false;
bool movingToData = false;
int wolffX;
int wolffY;
int closestEnemyData[4]; //ENEMYID, DATAID, DISTANCE, DISTANCETOWOLFF
closestEnemyData[0] = -1;
int secondClosestEnemyData[4];
secondClosestEnemyData[0] = -1;
for (int i = 0; i < enemyCount; i++) {
cin >> enemies[i][0] >> enemies[i][1] >> enemies[i][2] >> enemies[i][3]; cin.ignore();
int distance = sqrt(pow((enemies[i][1] - x), 2) + pow((enemies[i][2] - y), 2)); //distance from wolff to enemy
......@@ -63,6 +65,22 @@ int main()
priorityEnemy = i;
}
for (int j = 0; j < dataCount; j++) {
int distanceToData = sqrt(pow((enemies[i][1] - data[j][1]), 2) + pow((enemies[i][2] - data[j][2]), 2));
if (distanceToData < closestEnemyData[2] || closestEnemyData[0] == -1) {
if (closestEnemyData[0] != -1) {
secondClosestEnemyData[0] = closestEnemyData[0];
secondClosestEnemyData[1] = closestEnemyData[1];
secondClosestEnemyData[2] = closestEnemyData[2];
secondClosestEnemyData[3] = closestEnemyData[3];
}
closestEnemyData[0] = i;
closestEnemyData[1] = j;
closestEnemyData[2] = distanceToData;
closestEnemyData[3] = sqrt(pow((data[j][1] - x), 2) + pow((data[j][2] - y), 2));
}
}
/*
cerr << "enemyId = " << enemies[i][0] << endl;
cerr << "enemyX = " << enemies[i][1] << endl;
......@@ -71,11 +89,22 @@ int main()
cerr << "distance =" << enemies[i][4] << endl;
*/
}
/*
cerr << " x = " << x << endl;
cerr << " y = " << y << endl;
cerr << " closest enemy = " << closestEnemy << endl;
*/
if (enemies[closestEnemy][4] > 4501) {
if ((closestEnemyData[2] + 1500) < secondClosestEnemyData[2] && closestEnemyData[3] > 4001) {
movingToData = true;
} else if (closestEnemyData[3] < 4501) {
closestEnemy = closestEnemyData[0];
}
}
/*
cerr << " closestEnemyData = " << closestEnemyData[2] << endl;
cerr << " secondClosestEnemyData = " << secondClosestEnemyData[2] << endl;
cerr << " x = " << x << endl;
cerr << " y = " << y << endl;
cerr << " closest enemy = " << closestEnemy << endl;
*/
int damageDealt = 125000 / (pow(enemies[closestEnemy][4], 1.2));
if (enemies[closestEnemy][4] < 2501) { // if enemy is too close
move = true;
......@@ -85,22 +114,35 @@ int main()
int yDiff = sqrt(pow((enemies[closestEnemy][2] - y), 2));
if (secondClosestEnemy != -1) {
cerr << " moving away from 2 enemies" << endl;
wolffX = x - (((enemies[closestEnemy][1] + enemies[secondClosestEnemy][1]) / 2) - x);
wolffY = y - (((enemies[closestEnemy][2] + enemies[secondClosestEnemy][2]) / 2) - y);
}
cerr << closestEnemy << " " << secondClosestEnemy << endl;
cerr << "closeste = " << enemies[closestEnemy][1] << " " << enemies[closestEnemy][2] << endl;
cerr << "secclose = " << enemies[secondClosestEnemy][1] << " " << enemies[secondClosestEnemy][2] << endl;
cerr << "wolff = " << wolffX << " " << wolffY << endl;
//cerr << closestEnemy << " " << secondClosestEnemy << endl;
//cerr << "closeste = " << enemies[closestEnemy][1] << " " << enemies[closestEnemy][2] << endl;
//cerr << "secclose = " << enemies[secondClosestEnemy][1] << " " << enemies[secondClosestEnemy][2] << endl;
//cerr << "wolff = " << wolffX << " " << wolffY << endl;
// if cornered
if (x < 2000) {
cerr << "got cornered on left";
if ( y < 2000) {
cerr << "top, moving out" << endl;
if (xDiff < yDiff) {
wolffX = x + 2000;
} else {
wolffY = y + 2000;
}
} else if (y > 7000) {
cerr << "bottom, moving out" << endl;
if (xDiff < yDiff) {
wolffX = x + 2000;
} else {
......@@ -108,13 +150,22 @@ int main()
}
}
} else if (x > 14000) {
cerr << "got cornered on left";
if ( y < 2000) {
cerr << "top, moving out" << endl;
if (xDiff < yDiff) {
wolffX = x - 2000;
} else {
wolffY = y + 2000;
}
} else if (y > 7000) {
cerr << "bottom, moving out" << endl;
if (xDiff < yDiff) {
wolffX = x - 2000;
} else {
......@@ -122,21 +173,41 @@ int main()
}
}
}
} else if (damageDealt < (enemies[closestEnemy][3] / 2.4) && priorityEnemy == -1 && enemies[closestEnemy][4] > 4501) {
} else if ((damageDealt < (enemies[closestEnemy][3] / 2.5) && priorityEnemy == -1 && enemies[closestEnemy][4] > 4501) || (movingToData && priorityEnemy == -1)) {
move = true;
cerr << "moving closer ";
int moveToX;
int moveToY;
if (movingToData) {
cerr << " to data point" << endl;
moveToX = data[closestEnemyData[1]][1];
moveToY = data[closestEnemyData[1]][2];
cerr << moveToX << " " << moveToY << endl;
cerr << enemies[closestEnemyData[0]][1] << " " << enemies[closestEnemyData[0]][2] << endl;
} else {
cerr << " to enemy" << endl;
moveToX = enemies[closestEnemy][1];
moveToY = enemies[closestEnemy][2];
}
if (enemies[closestEnemy][1] < x) {
wolffX = enemies[closestEnemy][1] - 2000;
wolffX = moveToX - 1000;
} else {
wolffX = enemies[closestEnemy][1] + 2000;
wolffX = moveToX + 1000;
}
if (enemies[closestEnemy][2] < y) {
wolffY = enemies[closestEnemy][2] - 2000;
wolffY = moveToY - 1000;
} else {
wolffY = enemies[closestEnemy][2] + 2000;
wolffY = moveToY + 1000;
}
} else if (priorityEnemy >= 0) {
closestEnemy = priorityEnemy;
}
}
/*
shootEnemy = priorityEnemy;
......@@ -153,7 +224,6 @@ int main()
// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
//cout << "MOVE 8000 4500" << endl; // MOVE x y or SHOOT id
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment