Exemple #1
0
    public void Play()
    {
        // reset target pellet if pellet not target not exist anymore
        foreach (Pac pa in GetMyPacs().Where(p => p.Action.HasAction).ToList())
        {
            if (!Grid.Map[(int)pa.Action.TargetPosition.X, (int)pa.Action.TargetPosition.Y].HasPellet)
            {
                pa.Action = new Action();
            }
        }

        // IF there is BIG pellets, go get them
        List <Pellet> bigPellets = Pellets.Where(p => p.Value == 10).ToList();

        foreach (Pellet pe in bigPellets)
        {
            Pac pa = GetMyPacs().OrderBy(p => p.Distance(pe)).First();
            if (!pa.Action.HasAction || pe.Distance(pa) < pa.Distance(pa.Action.TargetPosition))
            {
                pa.Move(pe);
            }
        }

        // Else set the nearest not targeted pellet
        foreach (Pac p in GetMyPacs())
        {
//		if (!p.Action.HasAction)
            if (!p.Action.HasAction || (p.Action.TargetEntity is Pellet pel && pel.Value == 1))
            {
                List <Pellet> AlreadyTargeted = GetMyPacs().Select(e => e.Action.TargetEntity).Where(e => e != null).Cast <Pellet>().ToList();

                p.Move(GetVisiblePelletsNearest(p).Except(AlreadyTargeted).FirstOrDefault());

                ///  PROBABLY BETTER WITHOUT WHEN SEVERAL PAC
                if (!p.Action.HasAction)
                {
                    p.Move(GetVisiblePelletsNearest(p).FirstOrDefault());
                }
            }
            // If can't see pellets go where we never go
            if (!p.Action.HasAction)
            {
                List <Entity> AlreadyTargeted = GetMyPacs().Where(e => e.Id != p.Id).Select(e => e.Action.TargetEntity).ToList();

                var target = Grid.Map.Cast <Cell>().Where(e => e.HasPellet).Select(e => e.Inside).Cast <Pellet>()
                             .Except(AlreadyTargeted).OrderBy(e => p.Distance(e.Position)).FirstOrDefault();
                if (target != null)
                {
                    p.Move(target.Position);
                }
            }
        }

        // If speed, be sure to target the second nearest pellet from the first one
        foreach (Pac p in GetMyPacs().FindAll(p => p.SpeedTurnsLeft > 0))
        {
            if (p.Distance(p.Action.TargetPosition) <= 1)
            {
                p.Move(SPEED_GetNearestPelletFromPellet(p.Action.TargetPosition));
            }
        }


        // If can speed, Override and speed
        GetMyPacs().FindAll(p => p.AbilityCooldown == 0).ForEach(p => p.Speed());

        //Say Hi
        foreach (Pac p in GetMyPacs())
        {
            if (GetOpponentPacs().Any(o => this.IsDirectPath(p, o)))
            {
                p.Label = "Hi !";
            }
        }



        if (GetMyPacs().First().Positions.Count() > 2)
        {
            List <Pac> blockedPacs =
                GetMyPacs().Where(e => e.Positions.Last() == e.Positions.TakeLast(2).First() &&
                                  e.PreviousAction.IsMove).ToList();

            Debug(blockedPacs.Count() + "");
            foreach (Pac p in blockedPacs.ToList())
            {
                Debug("Pac " + p.Id + "Blocked");
                blockedPacs.Remove(p);

                List <Pac> otherBlockedNear = blockedPacs.FindAll(e => e.Distance(p) < 1.5);

                otherBlockedNear.ForEach(e => e.Action = new Action(e.Position));
                //blockedPacs.RemoveRange(otherBlockedNear);
            }
        }



        // foreach (Pac p in GetMyPacs())
        // {
        //  p.Label = p.Type.ToString();
        // }


        // foreach (Pac p in GetMyPacs())
        // {
        //  // if (p.Positions.Count() < 3)
        //  //  continue;
        //  List<Vector2> lastPos = p.Positions.TakeLast(3).ToList();

        //  // Debug(lastPos.First().ToString());
        //  // Debug(lastPos.Last().ToString());
        //  Debug( "HERE " + lastPos.Count().ToString());
        //  // Debug(p.Positions.Count().ToString());
        //  if (lastPos.Count() == 3 && p.PreviousAction.Type != eAction.Switch
        //  &&  lastPos.First() == lastPos.Last()
        //  &&  lastPos.First() == lastPos.Skip(1).First()
        //  )
        //      p.SwitchClockwise();
        // }

        this.ExecuteActions();
    }
Exemple #2
0
    public void Play()
    {
        // reset target pellet if pellet not target not exist anymore
        foreach (Pac pa in GetMyPacs().Where(p => p.Action.HasAction).ToList())
        {
            if (!Grid.Map[(int)pa.Action.TargetPosition.X, (int)pa.Action.TargetPosition.Y].HasPellet)
            {
                pa.Action = new Action();
            }
        }

        // IF there is BIG pellets, go get them
        List <Pellet> bigPellets = Pellets.Where(p => p.Value == 10).ToList();

        foreach (Pellet pe in bigPellets)
        {
            Pac pa = GetMyPacs().OrderBy(p => p.Distance(pe)).First();
            if (!pa.Action.HasAction || pe.Distance(pa) < pa.Distance(pa.Action.TargetPosition))
            {
                pa.Move(pe);
            }
        }

        // Else set the nearest not targeted pellet
        foreach (Pac p in GetMyPacs())
        {
            if (!p.Action.HasAction)
            {
                List <Pellet> AlreadyTargeted = GetMyPacs().Select(e => e.Action.TargetEntity).Where(e => e != null).Cast <Pellet>().ToList();

                p.Move(GetVisiblePelletsNearest(p).Except(AlreadyTargeted).FirstOrDefault());

                ///  PROBABLY BETTER WITHOUT WHEN SEVERAL PAC
                if (!p.Action.HasAction)
                {
                    p.Move(GetVisiblePelletsNearest(p).FirstOrDefault());
                }
            }
            // If can't see pellets go where we never go
            if (!p.Action.HasAction)
            {
                List <Entity> AlreadyTargeted = GetMyPacs().Where(e => e.Id != p.Id).Select(e => e.Action.TargetEntity).ToList();

                var target = Grid.Map.Cast <Cell>().Where(e => e.HasPellet).Select(e => e.Inside).Cast <Pellet>()
                             .Except(AlreadyTargeted).OrderBy(e => p.Distance(e.Position)).FirstOrDefault();
                if (target != null)
                {
                    p.Move(target.Position);
                }
            }
        }

        // If speed, be sure to target the second nearest pellet from the first one
        foreach (Pac p in GetMyPacs().FindAll(p => p.SpeedTurnsLeft > 0))
        {
            if (p.Distance(p.Action.TargetPosition) <= 1)
            {
                p.Move(SPEED_GetNearestPelletFromPellet(p.Action.TargetPosition));
            }
        }


        // If can speed, Override and speed
        GetMyPacs().FindAll(p => p.AbilityCooldown == 0).ForEach(p => p.Speed());

        //Say Hi
        foreach (Pac p in GetMyPacs())
        {
            if (GetOpponentPacs().Any(o => this.IsDirectPath(p, o)))
            {
                p.Label = "Hi !";
            }
        }

        this.ExecuteActions();
    }