/// <summary> /// Constructs a new projectile. /// </summary> /// <param name="world">The world that this projectile belongs to.</param> /// <param name="owner">The ship that fired this projectile, if any.</param> /// <param name="direction">The initial direction for this projectile.</param> public Projectile(World world, Gameplay.NanoBot owner, Vector2 direction) : base(world) { this.owner = owner; this.position = owner.Position; this.velocity = direction; }
//"Регистрация" нового бота в конвое public void AddBot(NanoBot bot) { if (this.State != ConvoyState.UnderConstruction) { return; } if ((bot is ConvoyDefender) && (MyDefender == null)) { MyDefender = (ConvoyDefender)bot; return; } if (bot is ConvoyContainer) { if (MyContainer[0] == null) { MyContainer[0] = (ConvoyContainer)bot; return; } if (MyContainer[1] == null) { MyContainer[1] = (ConvoyContainer)bot; return; } } }
/// <summary> /// Defines the interaction between the oxygen and a target actor /// when they touch. /// </summary> /// <param name="target">The actor that is touching this object.</param> /// <returns>True if the objects meaningfully interacted.</returns> public override bool Touch(Actor target) { // if the oxygen has touched a player, then damage it NanoBot player = target as NanoBot; if (player != null) { // calculate damage as a function of how much the two actor's // velocities were going towards one another Vector2 playerAsteroidVector = Vector2.Normalize(this.position - player.Position); float rammingSpeed = Vector2.Dot(playerAsteroidVector, player.Velocity) - Vector2.Dot(playerAsteroidVector, this.velocity); return(base.Touch(target)); } if ((target is South) == true || (target is Five) == true) { return(base.Touch(target)); } return(false); }
public string ResolvePart1(string[] inputs) { List <NanoBot> nanoBots = NanoBot.ListFromStrings(inputs); NanoBot bestNanoBot = nanoBots.OrderBy(nanoBot => nanoBot.Range).LastOrDefault(); int countInRange = nanoBots.Where(nanoBot => bestNanoBot.InRange(nanoBot)).Count(); return(countInRange.ToString()); }
/// <summary> /// Defines the interaction between the oxygen and a target actor /// when they touch. /// </summary> /// <param name="target">The actor that is touching this object.</param> /// <returns>True if the objects meaningfully interacted.</returns> public override bool Touch(Actor target) { // if the oxygen has touched a player, then damage it NanoBot player = target as NanoBot; if (player != null) { // calculate damage as a function of how much the two actor's // velocities were going towards one another Vector2 playerAsteroidVector = Vector2.Normalize(this.position - player.Position); float rammingSpeed = Vector2.Dot(playerAsteroidVector, player.Velocity) - Vector2.Dot(playerAsteroidVector, this.velocity); return(base.Touch(target)); } // if the Deuterium hits an Carbon, Bond them to make Methylene if ((target is Carbon) == true) { this.Die(this); target.Die(target); Vector2 newPosition = (target.Position + this.position) / 2; Vector2 newVelocity = (target.Velocity + this.velocity) / 2; Vector2 newDirection = (target.Direction + this.direction) / 2; world.BondMethylene(newPosition, newVelocity, newDirection); world.ParticleSystems.Add(new ParticleSystem(newPosition, newDirection, 36, 64f * world.ResVar, 128f * world.ResVar, 2f * world.ResVar, 0.05f * world.ResVar, world.CH2Color)); return(base.Touch(target)); } // if the Deuterium hits an Methylene, Bond them to make Methane if ((target is Methylene) == true) { this.Die(this); target.Die(target); Vector2 newPosition = (target.Position + this.position) / 2; Vector2 newVelocity = (target.Velocity + this.velocity) / 2; Vector2 newDirection = (target.Direction + this.direction) / 2; world.BondMethane(newPosition, newVelocity, newDirection); world.ParticleSystems.Add(new ParticleSystem(newPosition, newDirection, 36, 64f * world.ResVar, 128f * world.ResVar, 2f * world.ResVar, 0.05f * world.ResVar, world.CH2Color)); return(base.Touch(target)); } if ((target is South) == true || (target is Five) == true) { return(base.Touch(target)); } return(false); }
/// <summary> /// Constructs a new laser projectile. /// </summary> /// <param name="world">The world that this projectile belongs to.</param> /// <param name="owner">The ship that fired this projectile, if any.</param> /// <param name="direction">The initial direction for this projectile.</param> public SingleBeamProjectile(World world, NanoBot owner, Vector2 direction) : base(world, owner, direction) { this.radius = 0.5f; this.speed = 1000f; this.duration = 5f; this.damageAmount = 20f; this.damageOwner = false; this.mass = 2f; this.explodes = false; }
// Returns true if there is an Hoshimi point under the robot public bool overHoshimiPoint(NanoBot bot) { foreach (Entity hoshimiPoint in this._hoshimiEntities) { if (hoshimiPoint.Location.Equals(bot.Location)) { return(true); } } return(false); }
// Returns if there is an Empty Needle under the robot public bool overEmptyNeedle(NanoBot bot) { foreach (Point point in this._emptyNeedlePoints) { if (point.Equals(bot.Location)) { return(true); } } return(false); }
// Returns if there is an AZN point under the robot public bool overAZN(NanoBot bot) { foreach (Entity azn in this._aznEntities) { if (azn.Location.Equals(bot.Location)) { return(true); } } return(false); }
/// <summary> /// Constructs a new laser projectile. /// </summary> /// <param name="world">The world that this projectile belongs to.</param> /// <param name="owner">The ship that fired this projectile, if any.</param> /// <param name="direction">The initial direction for this projectile.</param> public HydrogenBoostProjectile(World world, NanoBot owner, Vector2 direction) : base(world, owner, direction) { this.life = 1f * world.ResVar; this.duration = 1f * world.ResVar; this.radius = 1f * world.ResVar; this.speed = 500f; this.damageAmount = 20f; this.damageOwner = false; this.mass = 4f; this.explodes = true; }
/// <summary> /// Defines the interaction between the oxygen and a target actor /// when they touch. /// </summary> /// <param name="target">The actor that is touching this object.</param> /// <returns>True if the objects meaningfully interacted.</returns> public override bool Touch(Actor target) { // if the oxygen has touched a player, then damage it NanoBot player = target as NanoBot; if (player != null) { // calculate damage as a function of how much the two actor's // velocities were going towards one another Vector2 playerAsteroidVector = Vector2.Normalize(this.position - player.Position); float rammingSpeed = Vector2.Dot(playerAsteroidVector, player.Velocity) - Vector2.Dot(playerAsteroidVector, this.velocity); if (player.positiveCharge == true) { player.Damage(this, this.mass * rammingSpeed * damageScalar * 2f); } else if (player.negativeCharge != true && player.positiveCharge != true) { player.Damage(this, this.mass * rammingSpeed * damageScalar); } return(base.Touch(target)); } if ((target is AtomicMoleBlastProjectile) == true) { target.Die(target); this.Die(this); world.ParticleSystems.Add(new ParticleSystem(this.position, this.direction, 36, 64f * world.ResVar, 128f * world.ResVar, 2f * world.ResVar, 0.05f * world.ResVar, world.CFC2Color)); return(base.Touch(target)); } if ((target is Ozone) == true) { target.Die(target); Vector2 newPosition = (target.Position + this.position) / 2; Vector2 newVelocity = (target.Velocity + this.velocity) / 2; Vector2 newDirection = (target.Direction + this.direction) / 2; world.UnbondOzone(newPosition, newVelocity, newDirection); world.ParticleSystems.Add(new ParticleSystem(target.Position, target.Direction, 36, 64f * world.ResVar, 128f * world.ResVar, 2f * world.ResVar, 0.05f * world.ResVar, world.O3Color)); this.world.AudioManager.PlayCue("asteroidTouch"); return(base.Touch(target)); } return(false); }
/// <summary> /// Constructs a new rocket projectile. /// </summary> /// <param name="world">The world that this projectile belongs to.</param> /// <param name="owner">The ship that fired this projectile, if any.</param> /// <param name="direction">The initial direction for this projectile.</param> public AtomicMoleBlastProjectile(World world, NanoBot owner, Vector2 direction) : base(world, owner, direction) { this.radius = 4f * world.ResVar; this.life = 0.65f * world.ResVar; this.duration = 0.65f * world.ResVar; this.mass = 4f; this.speed = 500f; this.damageAmount = 50f; this.damageOwner = false; this.damageRadius = 16f; this.explodes = true; this.polygon = VectorPolygon.CreateCircle(Vector2.Zero, 4f * world.ResVar, 20); this.color = Color.Gray; }
public List <Point> visibleEmptyNeedles(NanoBot bot) { List <Point> visibleEmptyNeedles = new List <Point>(); int robotScanDistance = bot.Scan + PH.Common.Utils.ScanLength; int squaredRobotScanDistance = robotScanDistance * robotScanDistance; foreach (Point emptyNeedlePoint in this._emptyNeedlePoints) { if (Utils.SquareDistance(bot.Location, emptyNeedlePoint) < squaredRobotScanDistance) { visibleEmptyNeedles.Add(emptyNeedlePoint); } } return(visibleEmptyNeedles); }
public List <Point> visibleNavigationPoints(NanoBot bot) { List <Point> visibleNavPoints = new List <Point>(); int robotScanDistance = bot.Scan + PH.Common.Utils.ScanLength; int squaredRobotScanDistance = robotScanDistance * robotScanDistance; foreach (Point nav in this._navigationPoints) { if (Utils.SquareDistance(bot.Location, nav) < squaredRobotScanDistance) { visibleNavPoints.Add(nav); } } return(visibleNavPoints); }
public List <Point> visibleAznPoints(NanoBot bot) { List <Point> visibleAznPoints = new List <Point>(); int robotScanDistance = bot.Scan + PH.Common.Utils.ScanLength; int squaredRobotScanDistance = robotScanDistance * robotScanDistance; foreach (Entity Azn in this._aznEntities) { if (Utils.SquareDistance(bot.Location, Azn.Location) < squaredRobotScanDistance) { visibleAznPoints.Add(Azn.Location); } } return(visibleAznPoints); }
/// <summary> /// Defines the interaction between the oxygen and a target actor /// when they touch. /// </summary> /// <param name="target">The actor that is touching this object.</param> /// <returns>True if the objects meaningfully interacted.</returns> public override bool Touch(Actor target) { // if the oxygen has touched a player, then damage it NanoBot player = target as NanoBot; if (player != null) { // calculate damage as a function of how much the two actor's // velocities were going towards one another Vector2 playerAsteroidVector = Vector2.Normalize(this.position - player.Position); float rammingSpeed = Vector2.Dot(playerAsteroidVector, player.Velocity) - Vector2.Dot(playerAsteroidVector, this.velocity); return(base.Touch(target)); } // if the nitrogen hit an nitrogen, Bond them N2 if ((target is Nitrogen) == true) { int N = 1; world.BondNitrogenTwo(this, target, N); return(base.Touch(target)); } // if the Nitrogen hit an Nitric Oxide, Bond them to N2O if ((target is NitricOxide) == true) { this.Die(this); target.Die(target); Vector2 newPosition = (target.Position + this.position) / 2; Vector2 newVelocity = (target.Velocity + this.velocity) / 2; Vector2 newDirection = (target.Direction + this.direction) / 2; world.BondNitrousOxide(newPosition, newVelocity, newDirection); world.ParticleSystems.Add(new ParticleSystem(newPosition, newDirection, 36, 64f * world.ResVar, 128f * world.ResVar, 2f * world.ResVar, 0.05f * world.ResVar, world.N2OColor)); return(base.Touch(target)); } if ((target is South) == true || (target is Five) == true) { return(base.Touch(target)); } return(false); }
public static NanoBot FromString(string strInput) { string[] parts = strInput.Split(new string[] { "pos=<", ",", ">, r=", }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 4) { return(null); } NanoBot nanoBot = new NanoBot { X = Convert.ToInt64(parts[0]), Y = Convert.ToInt64(parts[1]), Z = Convert.ToInt64(parts[2]), Range = Convert.ToInt64(parts[3]), }; return(nanoBot); }
/// <summary> /// Defines the interaction between the oxygen and a target actor /// when they touch. /// </summary> /// <param name="target">The actor that is touching this object.</param> /// <returns>True if the objects meaningfully interacted.</returns> public override bool Touch(Actor target) { // if the oxygen has touched a player, then damage it NanoBot player = target as NanoBot; if (player != null) { // calculate damage as a function of how much the two actor's // velocities were going towards one another Vector2 playerAsteroidVector = Vector2.Normalize(this.position - player.Position); float rammingSpeed = Vector2.Dot(playerAsteroidVector, player.Velocity) - Vector2.Dot(playerAsteroidVector, this.velocity); return(base.Touch(target)); } // if the Hydrogen hit an Hydrogen, Bond them 2H if ((target is Hydrogen) == true) { int H = 1; world.BondDeuterium(this, target, H); Vector2 pos = (this.position + target.Position) / 2; Vector2 vel = (this.velocity + target.Velocity) / 2; Vector2 dir = (this.direction + target.Direction) / 2; world.ParticleSystems.Add(new ParticleSystem(pos, dir, 18, 32f * world.ResVar, 64f * world.ResVar, 1.5f * world.ResVar, 0.05f * world.ResVar, world.HHColor)); return(base.Touch(target)); } if ((target is South) == true || (target is Five) == true) { return(base.Touch(target)); } return(false); }
private static List <NanoBot> GetNanobots() { List <NanoBot> nanobots = new List <NanoBot>(); try { using (StreamReader sr = new StreamReader(GetPath(23))) { while (!sr.EndOfStream) { string line = sr.ReadLine(); nanobots.Add(NanoBot.Parse(line)); } } } catch (Exception e) { throw e; } return(nanobots); }
public List <Point> visiblePierres(NanoBot bot) { List <Point> visibleNeuroControllers = new List <Point>(); if (this.OtherNanoBotsInfo == null) { return(visibleNeuroControllers); } int robotScanDistance = bot.Scan + PH.Common.Utils.ScanLength; int squaredVisionDistance = robotScanDistance * robotScanDistance; foreach (NanoBotInfo botInfo in this.OtherNanoBotsInfo) { int squaredBotDistance = Utils.SquareDistance(bot.Location, botInfo.Location); if (squaredBotDistance < squaredVisionDistance && botInfo.PlayerID == 0) { visibleNeuroControllers.Add(botInfo.Location); } } return(visibleNeuroControllers); }
// Returns true if there is an Hoshimi point under the robot public bool overHoshimiPoint(NanoBot bot) { foreach (Entity hoshimiPoint in this._hoshimiEntities) { if (hoshimiPoint.Location.Equals(bot.Location)) return true; } return false; }
// Returns if there is a Needle under the robot public bool overNeedle(NanoBot bot) { foreach (Point point in this._needlePoints) { if (point.Equals(bot.Location)) return true; } return false; }
public void logData(NanoBot bot, string text) { Debug.WriteLine("[" + this.CurrentTurn.ToString() + "] " + bot.InternalName + ": " + text); }
// Returns if there is an AZN point under the robot public bool overAZN(NanoBot bot) { foreach (Entity azn in this._aznEntities) { if (azn.Location.Equals(bot.Location)) return true; } return false; }
/// <summary> /// Constructs a new laser weapon. /// </summary> /// <param name="owner">The ship that owns this weapon.</param> public SingleBeamWeapon(NanoBot owner) : base(owner) { fireDelay = 0.5f; fireCueName = "laserBlaster"; }
public string ResolvePart2(string[] inputs) { List <NanoBot> nanoBots = NanoBot.ListFromStrings(inputs); long maxX = long.MinValue; long maxY = long.MinValue; long maxZ = long.MinValue; long minX = long.MaxValue; long minY = long.MaxValue; long minZ = long.MaxValue; foreach (NanoBot nanoBot in nanoBots) { if (nanoBot.X < minX) { minX = nanoBot.X; } if (nanoBot.X > maxX) { maxX = nanoBot.X; } if (nanoBot.Y < minY) { minY = nanoBot.Y; } if (nanoBot.Y > maxY) { maxY = nanoBot.Y; } if (nanoBot.Z < minZ) { minZ = nanoBot.Z; } if (nanoBot.Z > maxZ) { maxZ = nanoBot.Z; } } long sizeX = maxX - minX; long sizeY = maxY - minY; long sizeZ = maxZ - minZ; long scale = Math.Min(sizeX, Math.Min(sizeY, sizeZ)); do { scale /= 2; if (scale <= 0) { scale = 1; } long bestX = 0; long bestY = 0; long bestZ = 0; long bestCount = 0; for (long k = minZ; k <= maxZ; k += scale) { for (long j = minY; j <= maxY; j += scale) { for (long i = minX; i <= maxX; i += scale) { int count = 0; foreach (NanoBot nanoBot in nanoBots) { if (nanoBot.InRange(i, j, k, scale)) { count++; } } if (count > bestCount) { bestX = i; bestY = j; bestZ = k; bestCount = count; } } } } minX = bestX - scale; maxX = bestX + scale; minY = bestY - scale; maxY = bestY + scale; minZ = bestZ - scale; maxZ = bestZ + scale; if (scale == 1) { long distance = bestX + bestY + bestZ; return(distance.ToString()); } } while (true); }
public long ManhattanDistance(NanoBot other) { return(ManhattanDistance(other.X, other.Y, other.Z)); }
public bool InRange(NanoBot other) { long distance = ManhattanDistance(other); return(distance <= Range); }
/// <summary> /// Constructs a new laser weapon. /// </summary> /// <param name="owner">The ship that owns this weapon.</param> public HydrogenBoostWeapon(NanoBot owner) : base(owner) { fireDelay = 0.15f; fireCueName = "laserBlaster"; }
/// <summary> /// Constructs a new triple-laser weapon. /// </summary> /// <param name="owner">The ship that owns this weapon.</param> public HydrogenBoost(NanoBot owner) : base(owner) { }
public List<Point> visibleAznPoints(NanoBot bot) { List<Point> visibleAznPoints = new List<Point>(); int robotScanDistance = bot.Scan + PH.Common.Utils.ScanLength; int squaredRobotScanDistance = robotScanDistance * robotScanDistance; foreach (Entity Azn in this._aznEntities) { if (Utils.SquareDistance(bot.Location, Azn.Location) < squaredRobotScanDistance) visibleAznPoints.Add(Azn.Location); } return visibleAznPoints; }
public List<Point> visibleNavigationPoints(NanoBot bot) { List<Point> visibleNavPoints = new List<Point>(); int robotScanDistance = bot.Scan + PH.Common.Utils.ScanLength; int squaredRobotScanDistance = robotScanDistance * robotScanDistance; foreach (Point nav in this._navigationPoints) { if (Utils.SquareDistance(bot.Location, nav) < squaredRobotScanDistance) visibleNavPoints.Add(nav); } return visibleNavPoints; }
public bool IsInRange(NanoBot bot2) => (x, y, z).ManhattanDistance((bot2.x, bot2.y, bot2.z)) <= r;
//"�����������" ������ ���� � ������ public void AddBot(NanoBot bot) { if (this.State != ConvoyState.UnderConstruction) return; if ((bot is ConvoyDefender) && (MyDefender == null)) { MyDefender = (ConvoyDefender)bot; return; } if (bot is ConvoyContainer) { if (MyContainer[0] == null) { MyContainer[0] = (ConvoyContainer)bot; return; } if (MyContainer[1] == null) { MyContainer[1] = (ConvoyContainer)bot; return; } } }
public List<Point> visibleHoshimies(NanoBot bot) { List<Point> visibleHoshimies = new List<Point>(); int robotScanDistance = bot.Scan + PH.Common.Utils.ScanLength; int squaredRobotScanDistance = robotScanDistance * robotScanDistance; foreach (Point hoshimiPoint in this._hoshimiPoints) { if (Utils.SquareDistance(bot.Location, hoshimiPoint) < squaredRobotScanDistance) visibleHoshimies.Add(hoshimiPoint); } return visibleHoshimies; }
public override bool Equals(object obj) { NanoBot other = obj as NanoBot; return(other != null && (other.position.Equals(this.position) && other.radius == this.radius)); }
public List<Point> visiblePierres(NanoBot bot) { List<Point> visibleNeuroControllers = new List<Point>(); if (this.OtherNanoBotsInfo == null) return visibleNeuroControllers; int robotScanDistance = bot.Scan + PH.Common.Utils.ScanLength; int squaredVisionDistance = robotScanDistance * robotScanDistance; foreach (NanoBotInfo botInfo in this.OtherNanoBotsInfo) { int squaredBotDistance = Utils.SquareDistance(bot.Location, botInfo.Location); if (squaredBotDistance < squaredVisionDistance && botInfo.PlayerID == 0) visibleNeuroControllers.Add(botInfo.Location); } return visibleNeuroControllers; }
/// <summary> /// Constructs a new triple-laser weapon. /// </summary> /// <param name="owner">The ship that owns this weapon.</param> public AtomicMoleBlast(NanoBot owner) : base(owner) { }