Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int laps, cpCount;
- // function that gives a score to the result of simulating moves
- float Evaluate(Pod* pods)
- {
- float score = 0;
- for (int p = 0; p < 4; p++)
- {
- int podCpsPassed = pods[p].lap*cpCount + pods[p].target->prev->id;
- int owner = p < 2 ? 1 : -1;
- //if (owner==1) {
- //score += (podCpsPassed * 50000 - dist(pods[p].target->loc, pods[p].loc)); // scoring race completion by all pods, multiplying enemy score by -1
- score += (podCpsPassed * 50000 - dist(pods[p].target->loc, pods[p].loc))*owner; // scoring race completion by all pods, multiplying enemy score by -1
- //}
- }
- //score += dist(pods[0].loc, pods[1].loc); // our pods love each other. they want to stay together
- return score;
- }
- int main()
- {
- char latestLap='a';
- int latestTargetId=-1;
- Pod podToStop;
- cin >> laps >> cpCount;
- Checkpoint cps[cpCount];
- for (int i = 0; i < cpCount; i++)
- {
- cps[i].id = i;
- cin >> cps[i].loc;
- cps[i].prev = &cps[(i + cpCount - 1) % cpCount];
- cps[i].next = &cps[(i + 1) % cpCount];
- }
- Pod pods[4];
- for (int i = 0; i < 4; i++) {
- pods[i].target = &cps[1];
- }
- for (int i = 2; i <=4; i++) {
- pods[i].boostUsed = true;
- }
- int podToStop_nextTargetId;// = podToStop.target->next->id;
- vec2d podToStop_nextTarget;// = podToStop.target->next->loc;
- while (1)
- {
- for (int i = 0; i < 4; i++)
- {
- int ncp = 0;
- cin >> pods[i].loc >> pods[i].vel >> pods[i].view.angle >> ncp;
- if (ncp == -1)
- {
- cout << "0 0 0\n0 0 0\nEnemy is dead!";
- exit(0);
- }
- while (ncp != pods[i].target->id)
- pods[i].ValidateCP();
- if (pods[i].view.angle != -1)
- pods[i].view.angle *= toRad;
- else pods[i].view.angle = getAbsoluteAngle(cps[1].loc - pods[i].loc);
- if ((int)pods[i].lap > (int)latestLap && i >= 2) {
- if (pods[i].target->id > latestTargetId || pods[i].target->id==0) {
- latestTargetId=pods[i].target->id;
- latestLap=pods[i].lap;
- podToStop=pods[i];
- }
- } else {
- if (i >= 2) {
- if (pods[i].target->id > latestTargetId || pods[i].target->id==0) {
- latestTargetId=pods[i].target->id;
- latestLap=pods[i].lap;
- podToStop=pods[i];
- }
- }
- }
- if (i >= 2) {
- cerr << "Target id: " << pods[i].target->id << endl;
- cerr << "Lap: " << (int)pods[i].lap << endl;
- }
- }
- cerr << "LatestTargetId: " << latestTargetId << endl;
- cerr << "LatestLap: " << (int)latestLap << endl;
- cerr << "PodToStop.targetId: " << podToStop.target->id << endl;
- cerr << "PodToStop.lap: " << (int)podToStop.lap << endl;
- GameMove bestMoves[2];
- float bestScore = -10000000000;
- for (int i = 0; i < 2000; i++)
- {
- Pod testPods[4];
- memcpy(testPods, pods, sizeof(pods));
- GameMove moves[2];
- for (int m = 0; m < 2; m++)
- //moves[m] = GameMove(frand(-36 * toRad, 36 * toRad), frand(-100, maxThrust+100));
- moves[m] = GameMove(frand(-45 * toRad, 45 * toRad), frand(-50, maxThrust+50));
- GameMove FirstTurnMoves[2];
- memcpy(FirstTurnMoves, moves, sizeof(FirstTurnMoves));
- for (int turn = 0; turn < 20; turn++)
- {
- testPods[0].Apply(moves[0]);
- testPods[1].Apply(moves[1]);
- testPods[2].Apply(testPods[2].GetMoveAction(testPods[2].target->loc - testPods[2].vel * 3, 100));
- testPods[3].Apply(testPods[3].GetMoveAction(testPods[3].target->loc - testPods[3].vel * 3, 100));
- play(testPods);
- for (int m = 0; m < 2; m++)
- moves[m] = GameMove(
- moves[m].angle + pow(frand(-3, 3), 3)*toRad,
- moves[m].thrust + pow(frand(-3, 9), 3)*6
- );
- }
- float score = Evaluate(testPods);
- if (score > bestScore)
- {
- bestScore = score;
- memcpy(bestMoves, FirstTurnMoves, sizeof(FirstTurnMoves));
- }
- }
- pods[0].PrintAction(bestMoves[0]);
- //pods[1].PrintAction(bestMoves[1]);
- /*if (!podToStop_nextTargetId && podToStop.target->next->id) {
- podToStop_nextTargetId = podToStop.target->next->id;
- }
- if (podToStop_nextTargetId != 0 ) {
- if (podToStop_nextTargetId == podToStop_nextTargetId+2) {
- }
- }*/
- cout << podToStop.target->next->loc << " 100" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement