Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include "math.h"
- using namespace std;
- struct Vector2f
- {
- Vector2f()
- : x(0)
- , y(0) {}
- Vector2f(float anX, float anY)
- : x (anX)
- , y (anY) {}
- float x;
- float y;
- // Returns the length of the vector
- float Length()
- {
- return sqrt(x * x + y * y);
- }
- // Normalizes the vector
- Vector2f Normalize()
- {
- Vector2f vector;
- float length = this->Length();
- if(length != 0)
- {
- vector.x = x/length;
- vector.y = y/length;
- }
- return vector;
- }
- };
- float Dot(const Vector2f& aFirst, const Vector2f& aSecond)
- {
- return (aFirst.x * aSecond.x) + (aFirst.y * aSecond.y);
- }
- class Wreck
- {
- public:
- Wreck(int aRadius, Vector2f aPosition, int anId, int aWaterAmount)
- : myRadius(aRadius)
- , myPosition(aPosition)
- , myId(anId)
- , myWaterAmount(aWaterAmount) {}
- const int myRadius;
- const Vector2f myPosition;
- const int myId;
- const int myWaterAmount;
- };
- class Vehicle
- {
- public:
- Vehicle(int aMass, int aRadius, Vector2f aPosition, Vector2f aVelocity, int aType, int aPlayerId)
- : myMass(aMass)
- , myRadius(aRadius)
- , myPosition(aPosition)
- , myVelocity(aVelocity)
- , myType(aType)
- , myPlayerId(aPlayerId) {}
- const int myMass;
- const int myRadius;
- const Vector2f myPosition;
- const Vector2f myVelocity;
- const int myType;
- const int myPlayerId;
- };
- class PlayerVehicle
- {
- public:
- PlayerVehicle(int aMass, int aRadius, Vector2f aPosition, Vector2f aVelocity, int aType)
- : myMass(aMass)
- , myRadius(aRadius)
- , myPosition(aPosition)
- , myVelocity(aVelocity)
- , myType(aType)
- , myTargetId(-1) {}
- void Update(
- const vector<Vehicle>& someEnemyVehicles,
- const vector<Wreck>& someWrecks,
- const vector<Vehicle>& someTankers,
- int aIdOnEnemyHighestScore,
- int aPlayerRage,
- const vector<PlayerVehicle> somePlayerVehicles)
- {
- Vector2f closestPosition;
- int closestLength = 100000;
- int closestRadius = 0;
- int speed = 300;
- Vector2f toClosest;
- if(myType == 0)
- {
- //if we have a target, continue towards it. If we cant find our target, find new
- int foundTarget = false;
- for(int i = 0; i < someWrecks.size(); ++i)
- {
- const Wreck& wreck = someWrecks[i];
- if(wreck.myId == myTargetId)
- {
- foundTarget = true;
- closestPosition = wreck.myPosition;
- closestPosition = wreck.myPosition;
- closestRadius = wreck.myRadius;
- myTargetId = wreck.myId;
- }
- }
- if(!foundTarget)
- {
- myTargetId = -1;
- int mostWaterAmount = 0;
- for(int i = 0; i < someWrecks.size(); ++i)
- {
- const Wreck& wreck = someWrecks[i];
- Vector2f toThis(wreck.myPosition.x - myPosition.x, wreck.myPosition.y - myPosition.y);
- const int lengthToThis = toThis.Length();
- //if(wreck.myWaterAmount > mostWaterAmount)
- if(lengthToThis < closestLength)
- {
- closestLength = lengthToThis;
- closestPosition = wreck.myPosition;
- closestRadius = wreck.myRadius;
- toClosest = toThis;
- myTargetId = wreck.myId;
- mostWaterAmount = wreck.myWaterAmount;
- }
- }
- //if(someWrecks.size() == 0)
- //{
- // const PlayerVehicle& destroyer = somePlayerVehicles[1];
- // closestPosition = destroyer.myPosition;
- //}
- }
- //cerr << "Closest Position: " << closestPosition.x << " " << closestPosition.y << endl;
- //cerr << "Length To Closest: " << closestLength << endl;
- //cerr << "Velocity Length: " << myVelocity.Length() << endl;
- Vector2f targetPosition = closestPosition;
- targetPosition.x = int(targetPosition.x - (myVelocity.x * 1.5f));
- targetPosition.y = int(targetPosition.y - (myVelocity.y * 1.5f));
- cout << targetPosition.x << " " << targetPosition.y << " " << speed << endl;
- }
- else if(myType == 1) //destroyer
- {
- for(int i = 0; i < someTankers.size(); ++i)
- {
- const Vehicle& tanker = someTankers[i];
- Vector2f fromMiddle(tanker.myPosition.x - 0, tanker.myPosition.y - 0);
- if(fromMiddle.Length() > 6000)
- continue;
- Vector2f toThis(tanker.myPosition.x - myPosition.x, tanker.myPosition.y - myPosition.y);
- const int lengthToThis = toThis.Length();
- if(lengthToThis < closestLength)
- {
- closestLength = lengthToThis;
- closestPosition = tanker.myPosition;
- closestRadius = tanker.myRadius;
- }
- }
- bool shouldGrenade = false;
- //if(someTankers.size() == 0)
- {
- for(int i = 0; i < someEnemyVehicles.size(); ++i)
- {
- const Vehicle& enemy = someEnemyVehicles[i];
- if(enemy.myType != 0)
- continue;
- if(enemy.myPlayerId != aIdOnEnemyHighestScore)
- continue;
- Vector2f toThis(enemy.myPosition.x - myPosition.x, enemy.myPosition.y - myPosition.y);
- const int lengthToThis = toThis.Length();
- if(lengthToThis < 2000)
- {
- closestPosition = enemy.myPosition;
- shouldGrenade = true;
- }
- }
- }
- if(shouldGrenade && aPlayerRage >= 60)
- cout << "SKILL " << closestPosition.x << " " << closestPosition.y << endl;
- else
- cout << closestPosition.x << " " << closestPosition.y << " " << speed << endl;
- }
- else if(myType == 2)
- {
- cerr << "amount of enemies for Doof:" << someEnemyVehicles.size() << endl;
- for(int i = 0; i < someEnemyVehicles.size(); ++i)
- {
- const Vehicle& enemy = someEnemyVehicles[i];
- if(enemy.myType != 0)
- continue;
- if(enemy.myPlayerId != aIdOnEnemyHighestScore)
- continue;
- Vector2f toThis(enemy.myPosition.x - myPosition.x, enemy.myPosition.y - myPosition.y);
- const int lengthToThis = toThis.Length();
- if(lengthToThis < closestLength)
- {
- closestLength = lengthToThis;
- closestPosition = enemy.myPosition;
- closestRadius = enemy.myRadius;
- }
- }
- cout << closestPosition.x << " " << closestPosition.y << " " << speed << endl;
- }
- //cerr << "Closest Position: " << closestPosition.x << " " << closestPosition.y << endl;
- //cerr << "Length To Closest: " << closestLength << endl;
- //cerr << "Closest radius: " << closestRadius << endl;
- //cerr << "Player Radius: " << myRadius << endl;
- //cerr << "Velocity Length: " << myVelocity.Length() << endl;
- }
- int myTargetId;
- int myMass;
- int myRadius;
- Vector2f myPosition;
- Vector2f myVelocity;
- int myType;
- };
- int main()
- {
- vector<PlayerVehicle> playerVehicles;
- vector<Vehicle> enemyVehicles;
- vector<Vehicle> tankers;
- vector<Wreck> wrecks;
- int isFirstFrame = true;
- while (1)
- {
- int myScore;
- cin >> myScore; cin.ignore();
- int enemyScore1;
- cin >> enemyScore1; cin.ignore();
- int enemyScore2;
- cin >> enemyScore2; cin.ignore();
- int myRage;
- cin >> myRage; cin.ignore();
- int enemyRage1;
- cin >> enemyRage1; cin.ignore();
- int enemyRage2;
- cin >> enemyRage2; cin.ignore();
- int unitCount;
- cin >> unitCount; cin.ignore();
- const int idOnHighestEnemyScore = enemyScore1 > enemyScore2 ? 1 : 2;
- for (int i = 0; i < unitCount; i++)
- {
- int unitId;
- int unitType;
- int player;
- float mass;
- int radius;
- Vector2f position;
- Vector2f velocity;
- int extra;
- int extra2;
- cin >> unitId >> unitType >> player >> mass >> radius >> position.x >> position.y >> velocity.x >> velocity.y >> extra >> extra2; cin.ignore();
- if(unitType <= 2)
- {
- if(player == 0)
- {
- if(isFirstFrame)
- {
- PlayerVehicle vehicle(mass, radius, position, velocity, unitType);
- playerVehicles.push_back(vehicle);
- }
- else
- {
- PlayerVehicle& vehicle = playerVehicles[unitId];
- vehicle.myMass = mass;
- vehicle.myRadius = radius;
- vehicle.myPosition = position;
- vehicle.myVelocity = velocity;
- }
- }
- else
- {
- Vehicle vehicle(mass, radius, position, velocity, unitType, player);
- enemyVehicles.push_back(vehicle);
- cerr << "enemy id: " << unitId << " type: " << unitType << " mass: " << mass << " radius: " << radius << " position: " << position.x << " " << position.y << endl;
- }
- }
- else if(unitType == 3)
- {
- Vehicle tanker(mass, radius, position, velocity, unitType, -1);
- tankers.push_back(tanker);
- }
- else if(unitType == 4)
- {
- Wreck wreck(radius, position, unitId, extra);
- wrecks.push_back(wreck);
- }
- }
- for(int j = 0; j < enemyVehicles.size(); ++j)
- cerr << enemyVehicles[j].myType << endl;
- for(int i = 0; i < playerVehicles.size(); ++i)
- playerVehicles[i].Update(enemyVehicles, wrecks, tankers, idOnHighestEnemyScore, myRage, playerVehicles);
- //playerVehicles.clear();
- enemyVehicles.clear();
- tankers.clear();
- wrecks.clear();
- if(isFirstFrame)
- isFirstFrame = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement