Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.IO;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- /**
- * Grab Snaffles and try to throw them through the opponent's goal!
- * Move towards a Snaffle and use your team id to determine where you need to throw it.
- **/
- public class Snaffle
- {
- public double X;
- public double Y;
- public int Holder;
- public Snaffle(double x, double y, int holder)
- {
- X = x;
- Y = y;
- Holder = holder;
- }
- }
- public class Wizard
- {
- public double X;
- public double Y;
- public bool State;
- public int Number;
- public Wizard(double x, double y, bool state, int num)
- {
- X = x;
- Y = y;
- State = state;
- Number = num;
- }
- public double distance(Snaffle snaffle)
- {
- return Math.Sqrt((X - snaffle.X) * (X - snaffle.X) +
- (Y - snaffle.Y) * (Y - snaffle.Y));
- }
- }
- class Player
- {
- static void Main(string[] args)
- {
- var wizards = new List<Wizard>()
- {
- new Wizard(0,0,false,0),
- new Wizard(0,0,false,1)
- };
- var snaffles = new List<Snaffle>();
- for (var i = 0; i < 7; i++)
- snaffles.Add(new Snaffle(double.MaxValue, double.MaxValue, -1));
- string[] inputs;
- 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
- while (true)
- {
- inputs = Console.ReadLine().Split(' ');
- int myScore = int.Parse(inputs[0]);
- int myMagic = int.Parse(inputs[1]);
- inputs = Console.ReadLine().Split(' ');
- int opponentScore = int.Parse(inputs[0]);
- int opponentMagic = int.Parse(inputs[1]);
- int entities = int.Parse(Console.ReadLine()); // number of entities still in game
- for (var i=0; i<snaffles.Count; i++)
- snaffles[i].X = double.MaxValue;
- for (int i = 0; i < entities; i++)
- {
- inputs = Console.ReadLine().Split(' ');
- int entityId = int.Parse(inputs[0]); // entity identifier
- string entityType = inputs[1]; // "WIZARD", "OPPONENT_WIZARD" or "SNAFFLE" (or "BLUDGER" after first league)
- int x = int.Parse(inputs[2]); // position
- int y = int.Parse(inputs[3]); // position
- int vx = int.Parse(inputs[4]); // velocity
- int vy = int.Parse(inputs[5]); // velocity
- int state = int.Parse(inputs[6]); // 1 if the wizard is holding a Snaffle, 0 otherwise
- if (entityType == "WIZARD")
- {
- wizards[entityId].X = x;
- wizards[entityId].Y = y;
- wizards[entityId].State = Convert.ToBoolean(state);
- }
- if (entityType == "SNAFFLE")
- {
- snaffles[entityId - 4].X = x;
- snaffles[entityId - 4].Y = y;
- }
- }
- for (int i = 0; i < 2; i++)
- {
- if (wizards[i].State == false)
- {
- double minDistance = double.MaxValue;
- double x = 0;
- double y = 0;
- int index = -1;
- for (var j = 0; j < snaffles.Count; j++)
- {
- double newDistance = wizards[i].distance(snaffles[j]);
- if (newDistance < minDistance &&
- (snaffles[j].Holder == -1 || snaffles[j].Holder == wizards[i].Number))
- {
- minDistance = newDistance;
- x = snaffles[j].X;
- y = snaffles[j].Y;
- index = j;
- for (var k = 0; k < snaffles.Count; k++)
- {
- if (snaffles[k].Holder == wizards[i].Number)
- snaffles[k].Holder = -1;
- }
- }
- }
- snaffles[index].Holder = wizards[i].Number;
- Console.WriteLine("MOVE " + x + " " + y + " 150");
- }
- else
- {
- Console.WriteLine("THROW " + 15982 + " " + 3800 + " 500");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement