Britbot
SpecialOps.cs
Go to the documentation of this file.
00001 using System.Collections.Generic;
00002 using System.Linq;
00003 using Pirates;
00004 
00005 namespace Britbot
00006 {
00010     internal static class SpecialOps
00011     {
00015         public static void DoCloak(Dictionary<Pirate,Direction> moves)
00016         {
00017             Group g = null;
00018 
00019             //the group that contains the cloaked pirate if one exists
00020             if(Bot.Game.GetMyCloaked() != null)
00021                 //sorry for this horrible lambda, stuff went quite complex and I didn't have the time 
00022                 // to restore the original function. This lambda finds the group with the cloaked pirate
00023                 g = Commander.Groups.First(commGroup => commGroup.Pirates.ToList()
00024                     .ConvertAll(p => Bot.Game.GetMyPirate(p))
00025                     .Any(pirate => Bot.Game.GetMyCloaked().Id == pirate.Id));
00026 
00027             // if a pirate is cloaked and close enough to its target, reveal it
00028             if ((g != null) && (g.DistanceFromTarget <= Magic.CloakRange))
00029                 moves[Bot.Game.GetMyCloaked()] = Direction.REVEAL;
00030 
00031             // if no pirate is cloaked and we can cloak one
00032             if (Bot.Game.CanCloak())
00033             {
00034                 //All the single pirate groups that can be cloaked
00035                 IEnumerable<Group> ones = Commander.Groups.Where(p => p.Pirates.Count == 1);
00036 
00037                 //if there are any 1 pirate groups
00038                 if (ones.Count() != 0)
00039                 {
00040                     //the minimum distance from a target of one of the groups
00041                     int minDistance = ones.Min(group => @group.DistanceFromTarget);
00042 
00043                     //finds the group that the minimal distance belongs to and cloaks it
00044                     foreach (Group tc in ones)
00045                     {
00046                         if ((tc.DistanceFromTarget == minDistance)&&(minDistance>Magic.CloakRange))
00047                             moves[Bot.Game.GetMyPirate(tc.Pirates.First())] = Direction.CLOAK;
00048                     }
00049                 }
00050             }
00051         }
00052     }
00053 }