Advertisement
coockie27

MyBot

Feb 25th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.54 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8. /**
  9.  * Grab Snaffles and try to throw them through the opponent's goal!
  10.  * Move towards a Snaffle and use your team id to determine where you need to throw it.
  11.  **/
  12.  
  13. public class Snaffle
  14. {
  15.     public double X;
  16.     public double Y;
  17.     public int Holder;
  18.     public Snaffle(double x, double y, int holder)
  19.     {
  20.         X = x;
  21.         Y = y;
  22.         Holder = holder;
  23.     }
  24. }
  25. public class Wizard
  26. {
  27.     public double X;
  28.     public double Y;
  29.     public bool State;
  30.     public int Number;
  31.     public Wizard(double x, double y, bool state, int num)
  32.     {
  33.         X = x;
  34.         Y = y;
  35.         State = state;
  36.         Number = num;
  37.     }
  38.     public double distance(Snaffle snaffle)
  39.     {
  40.         return Math.Sqrt((X - snaffle.X) * (X - snaffle.X) +
  41.                          (Y - snaffle.Y) * (Y - snaffle.Y));
  42.     }
  43. }
  44. class Player
  45. {
  46.     static void Main(string[] args)
  47.     {
  48.         var wizards = new List<Wizard>()
  49.         {
  50.             new Wizard(0,0,false,0),
  51.             new Wizard(0,0,false,1)
  52.         };
  53.         var snaffles = new List<Snaffle>();
  54.         for (var i = 0; i < 7; i++)
  55.             snaffles.Add(new Snaffle(double.MaxValue, double.MaxValue, -1));
  56.  
  57.         string[] inputs;
  58.         int myTeamId = int.Parse(Console.ReadLine()); // if 0 you need to score on the right of the map, if 1 you need to score on the left
  59.         while (true)
  60.         {
  61.             inputs = Console.ReadLine().Split(' ');
  62.             int myScore = int.Parse(inputs[0]);
  63.             int myMagic = int.Parse(inputs[1]);
  64.             inputs = Console.ReadLine().Split(' ');
  65.             int opponentScore = int.Parse(inputs[0]);
  66.             int opponentMagic = int.Parse(inputs[1]);
  67.             int entities = int.Parse(Console.ReadLine()); // number of entities still in game
  68.             for (var i=0; i<snaffles.Count; i++)
  69.                 snaffles[i].X = double.MaxValue;
  70.             for (int i = 0; i < entities; i++)
  71.             {
  72.                 inputs = Console.ReadLine().Split(' ');
  73.                 int entityId = int.Parse(inputs[0]); // entity identifier
  74.                 string entityType = inputs[1]; // "WIZARD", "OPPONENT_WIZARD" or "SNAFFLE" (or "BLUDGER" after first league)
  75.                 int x = int.Parse(inputs[2]); // position
  76.                 int y = int.Parse(inputs[3]); // position
  77.                 int vx = int.Parse(inputs[4]); // velocity
  78.                 int vy = int.Parse(inputs[5]); // velocity
  79.                 int state = int.Parse(inputs[6]); // 1 if the wizard is holding a Snaffle, 0 otherwise
  80.  
  81.                 if (entityType == "WIZARD")
  82.                 {
  83.                     wizards[entityId].X = x;
  84.                     wizards[entityId].Y = y;
  85.                     wizards[entityId].State = Convert.ToBoolean(state);
  86.                 }
  87.                 if (entityType == "SNAFFLE")
  88.                 {
  89.                     snaffles[entityId - 4].X = x;
  90.                     snaffles[entityId - 4].Y = y;
  91.                 }
  92.             }
  93.             for (int i = 0; i < 2; i++)
  94.             {
  95.                 if (wizards[i].State == false)
  96.                 {
  97.                     double minDistance = double.MaxValue;
  98.                     double x = 0;
  99.                     double y = 0;
  100.                     int index = -1;
  101.                     for (var j = 0; j < snaffles.Count; j++)
  102.                     {
  103.                         double newDistance = wizards[i].distance(snaffles[j]);
  104.                         if (newDistance < minDistance &&
  105.                            (snaffles[j].Holder == -1 || snaffles[j].Holder == wizards[i].Number))
  106.                         {
  107.                             minDistance = newDistance;
  108.                             x = snaffles[j].X;
  109.                             y = snaffles[j].Y;
  110.                             index = j;
  111.                             for (var k = 0; k < snaffles.Count; k++)
  112.                             {
  113.                                 if (snaffles[k].Holder == wizards[i].Number)
  114.                                     snaffles[k].Holder = -1;
  115.                             }
  116.                         }
  117.                     }
  118.                     snaffles[index].Holder = wizards[i].Number;
  119.                     Console.WriteLine("MOVE " + x + " " + y + " 150");
  120.                 }
  121.                 else
  122.                 {
  123.                     Console.WriteLine("THROW " + 15982 + " " + 3800 + " 500");
  124.                 }
  125.             }
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement