コード例 #1
0
        public override FighterControllerData MakeTurn(Fighter f, List <Fighter> units, string[] eth)
        {
            FighterControllerData data = new FighterControllerData();

            Write("Begin");
            if (f.Dead)
            {
                Write("0");
                return(data);
            }
            Write("1");
            Write(f.Location.X);
            Write(f.Location.Y);
            Write((int)(f.Angle * 180 / Math.PI));
            Write(f.HP);
            Write(f.Mana);
            Write(units.Count);
            for (int j = 0; j < units.Count; j++)
            {
                Write(units[j].Location.X);
                Write(units[j].Location.Y);
                Write(units[j].Team == f.Team ? 0 : 1);
                Write(units[j].Letter);
                Write(units[j].HP);
            }
            Write(eth.Length);
            for (int i = 0; i < eth.Length; i++)
            {
                Write(eth[i] == null ? "" : eth[i]);
            }
            p.StandardInput.Flush();
            //  Thread.Sleep(200);
            Console.WriteLine("Reading...");
            try
            {
                data.shot          = Read() == "1";
                data.shotPoint.X   = int.Parse(Read());
                data.shotPoint.Y   = int.Parse(Read());
                data.newLocation.X = int.Parse(Read());
                data.newLocation.Y = int.Parse(Read());
                data.newAngle      = double.Parse(Read()) * Math.PI / 180;
                data.msg           = Read();
            }
            catch
            {
                throw new Exception("Не могу разобрать ответ программы " + data);
            }

            if (data.shot)
            {
                data.shot = Rnd.Next(100) < f.Precision;
            }
            data.damage = f.Damage;
            return(data);
        }
コード例 #2
0
        protected override TurnActionInfo <Coordinate2D, Metric2D, int> OnTurn(SubMap <Coordinate2D, Metric2D, int> submap)
        {
            List <Fighter> lst = new List <Fighter>();

            //foreach(Cell<Coordinate2D, Metric2D, int> c in submap.Cells)
            foreach (Fighter f in submap.Objects)
            {
                if (f == this)
                {
                    continue;
                }
                if (back.CanSee(Location.X, Location.Y, f.Location.X, f.Location.Y, SightLength, Angle, SightAngle))
                {
                    lst.Add(f);
                }
            }
            //FighterControllerData move = controller.MakeTurn(this, lst, back.Eth[Team]);
            FighterControllerData move = controller.MakeTurn(this, lst, ether.Get <string[]>(Team.ToString()));

            TurnActionInfo <Coordinate2D, Metric2D, int> inf = new TurnActionInfo <Coordinate2D, Metric2D, int>();

            if (Dead)
            {
                DeadCountDown--;
                if (DeadCountDown == 0)
                {
                    Dead         = false;
                    inf.hasMoved = true;
                    inf.moveTo   = submap.ToLocal(new Coordinate2D(BirthLocation.X, BirthLocation.Y));
                }
            }
            else
            {
                if (move.shot)
                {
                    if (Mana >= ShotCost)
                    {
                        Mana -= ShotCost;
                        for (int dx = -Radius; dx <= Radius; dx++)
                        {
                            for (int dy = -Radius; dy <= Radius; dy++)
                            {
                                if (back.Inside(move.shotPoint.X + dx, move.shotPoint.Y + dy))
                                {
                                    Cell <Coordinate2D, Metric2D, int> cl =
                                        submap.GetCell(
                                            submap.ToLocal(new Coordinate2D(move.shotPoint.X + dx, move.shotPoint.Y + dy)));
                                    foreach (Fighter f in cl)
                                    {
                                        f.HP -= move.damage;
                                    }
                                }
                            }
                        }
                    }
                }

                if (back.CanGo(Location.X, Location.Y, move.newLocation.X, move.newLocation.Y, Speed))
                {
                    inf.hasMoved = true;
                    inf.moveTo   = submap.ToLocal(new Coordinate2D(move.newLocation.X, move.newLocation.Y));
                }
                else
                {
                    inf.hasMoved = false;
                }
                Angle   = move.newAngle;
                LastEth = move.msg;
            }

            return(inf);
        }