Guest User

Untitled

a guest
Feb 15th, 2014
1,161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. QPointF TWorld::Rule1(size_t shipNum) {
  2.     QPointF massCenter;
  3.     size_t ships = 0;
  4.     for (int i = 0; i < Ships.size(); ++i) {
  5.         if (i != shipNum &&
  6.             Ships[i].PlayerId == Ships[shipNum].PlayerId &&
  7.             Ships[i].Target == Ships[shipNum].Target)
  8.         {
  9.             massCenter += Ships[i].Position;
  10.             ++ships;
  11.         }
  12.     }
  13.     if (!ships) {
  14.         return QPointF(0, 0);
  15.     }
  16.     massCenter /= ships;
  17.     return (massCenter - Ships[shipNum].Position) / 160;
  18. }
  19.  
  20. QPointF TWorld::Rule2(size_t shipNum) {
  21.     QPointF c(0, 0);
  22.     for (int i = 0; i < Ships.size(); ++i) {
  23.         if (i != shipNum) {
  24.             float distance = Distance(Ships[i].Position, Ships[shipNum].Position);
  25.             if (distance < 21) {
  26.                 QPointF direction = Ships[i].Position - Ships[shipNum].Position;
  27.                 Normalize(direction);
  28.                 direction *= (33 - distance);
  29.                 c -= direction;
  30.             }
  31.         }
  32.     }
  33.     return c / 35;
  34. }
  35.  
  36. QPointF TWorld::Rule3(size_t shipNum) {
  37.     QPointF massCenter;
  38.     size_t ships = 0;
  39.     for (int i = 0; i < Ships.size(); ++i) {
  40.         if (i != shipNum &&
  41.             Ships[i].PlayerId == Ships[shipNum].PlayerId &&
  42.             Ships[i].Target == Ships[shipNum].Target)
  43.         {
  44.             massCenter += Ships[i].Speed;
  45.             ++ships;
  46.         }
  47.     }
  48.     if (!ships) {
  49.         return QPointF(0, 0);
  50.     }
  51.     massCenter /= ships;
  52.     return (massCenter - Ships[shipNum].Speed) / 18;
  53. }
  54.  
  55. QPointF TWorld::Rule4(size_t shipNum) {
  56.     QPointF direction = Ships[shipNum].Target - Ships[shipNum].Position;
  57.     LimitSpeed(direction, 0.85);
  58.     return direction;
  59. }
  60.  
  61. QPointF TWorld::Rule5(size_t shipNum) {
  62.     QPointF c(0, 0);
  63.     for (int i = 0; i < Planets.size(); ++i) {
  64.         if (Ships[shipNum].Target != Planets[i].Position) {
  65.             float distance = Distance(Planets[i].Position, Ships[shipNum].Position);
  66.             if (distance < 10.0 + 1.4 * Planets[i].Radius) {
  67.                 QPointF direction = Planets[i].Position - Ships[shipNum].Position;
  68.                 Normalize(direction);
  69.                 direction *= (18.0 + 1.4 * Planets[i].Radius - distance);
  70.                 c -= direction;
  71.             }
  72.         }
  73.     }
  74.     return c / 8;
  75. }
RAW Paste Data