Advertisement
ZeroByter

CodinGame Puzzle Code #1

Jun 1st, 2018
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. // game loop
  2. while (true)
  3. {
  4.     //...
  5.  
  6.     //target other enemy factories - offensive
  7.     foreach (Factory factory in Factory.FriendlyFactories.Values)
  8.     {
  9.         Factory targetFactory = Link.GetTargetFactory(factory);
  10.  
  11.         if(targetFactory != null)
  12.         {
  13.             if (targetFactory.owner == -1 && !BombTargetedFactories.Contains(targetFactory) && Bomb.TurnsUntilBombHitsFactory(targetFactory) == -1) //here we check if the targetFactory is owned by the enemy, if we haven't targeted it already this turn, AND if we have targeted already in previous turns
  14.             {
  15.                 BombTargetedFactories.Add(targetFactory);
  16.                 new Action(factory.id, targetFactory.id); //launch bomb on enemy factories only
  17.             }
  18.  
  19.             if(factory.production == 0)
  20.             {
  21.                 new Action(factory.id, targetFactory.id, targetFactory.finalNumberOfCyborgs + 1); //launch ships to target factory
  22.             }
  23.             else if(factory.production < 2)
  24.             {
  25.                 new Action(factory);
  26.             }
  27.             else
  28.             {
  29.                 new Action(factory.id, targetFactory.id, targetFactory.finalNumberOfCyborgs + 1); //launch ships to target factory here too
  30.             }
  31.         }
  32.     }
  33.    
  34.     if(Action.Actions.Count() == 0){
  35.         Console.WriteLine("WAIT");
  36.     }else{
  37.         StringBuilder builder = new StringBuilder();
  38.         foreach(Action action in Action.Actions){
  39.             builder.Append(action.ToString());
  40.         }
  41.         builder.Length--;
  42.         Console.WriteLine(builder);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement