Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.21 KB | None | 0 0
  1. using PenguinGame;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections;
  5. using System.Linq;
  6.  
  7. namespace MyBot {
  8.  
  9.     public class TutorialBot : ISkillzBot {
  10.        
  11.        
  12.         //Public dictionary [[Can be called from anywhere in the code]]
  13.         //between uniqueId (key) to our class for icebergs info (value)
  14.         public Dictionary<int, OurIceberg> uniqueIdictionary;
  15.        
  16.         public class OurIceberg {
  17.             public int[] numPenguinsInTurn;
  18.             public Player[] ownerInTurn;
  19.             public int level;
  20.             public string type;
  21.             public Player[] owner;
  22.             public Game game;
  23.            
  24.            
  25.             //Constructor initializes all icebergs should only to be called in the first round
  26.             public OurIceberg(Iceberg icy, int farthestDistance, string type, Game game) {
  27.                 this.level = icy.Level;
  28.                 this.numPenguinsInTurn = new int[farthestDistance];
  29.                 this.numPenguinsInTurn[0] = icy.PenguinAmount;
  30.                 this.ownerInTurn = new Player[farthestDistance];
  31.                 this.ownerInTurn[0] = icy.Owner;
  32.                 this.type = type;
  33.                 this.game = game;
  34.             }
  35.            
  36.             //Initializes Arrays
  37.             public void InitializeArrays()
  38.             {
  39.                 for (int i = 0; i < numPenguinsInTurn.Length; i++)
  40.                 {
  41.                     this.numPenguinsInTurn[i] = this.numPenguinsInTurn[0];
  42.                     if (this.ownerInTurn[0] != game.GetNeutral()) { this.numPenguinsInTurn[i] += i * this.level; }
  43.                     this.ownerInTurn[i] = this.ownerInTurn[0];
  44.                 }
  45.             }
  46.         }
  47.        
  48.         public void DoTurn (Game game) {
  49.            
  50.             if(game.Turn == 1) {
  51.                
  52.                 uniqueIdictionary = new Dictionary<int, OurIceberg>();
  53.                
  54.                 //Make iceberg arrays
  55.                 Iceberg[] ourIcebergs = game.GetMyIcebergs();
  56.                 Iceberg[] allIcebergs = game.GetAllIcebergs();
  57.                
  58.                 //Sort arrays
  59.                 System.Array.Sort(allIcebergs, delegate (Iceberg x, Iceberg y) {
  60.                     return ourIcebergs[0].GetTurnsTillArrival(x).CompareTo(ourIcebergs[0].GetTurnsTillArrival(y));
  61.                 });
  62.                 int farthestDistance = ourIcebergs[0].GetTurnsTillArrival(allIcebergs[allIcebergs.Length-1]);
  63.                
  64.                 for(int i=0;i< allIcebergs.Length;i++) {
  65.                     if(i <allIcebergs.Length/3) {
  66.                         uniqueIdictionary.Add(allIcebergs[i].UniqueId, new OurIceberg(allIcebergs[i],farthestDistance, "defence", game));
  67.                     }else if(i > (int)(allIcebergs.Length/1.5)) {
  68.                         uniqueIdictionary.Add(allIcebergs[i].UniqueId, new OurIceberg(allIcebergs[i],farthestDistance, "attack", game));                        
  69.                     }else {
  70.                         uniqueIdictionary.Add(allIcebergs[i].UniqueId, new OurIceberg(allIcebergs[i],farthestDistance, "middle", game));                        
  71.                     }
  72.                 }
  73.             }else {
  74.                 //Go through all the Icebergs and update the info in the Dictionary.
  75.                 foreach(Iceberg icy in game.GetAllIcebergs())
  76.                 {
  77.                     uniqueIdictionary[icy.UniqueId].InitializeArrays();
  78.                 }
  79.                
  80.                 //Go through all the Penguin Groups and update the info in the Dictionary.
  81.                 foreach(PenguinGroup pg in game.GetAllPenguinGroups()) {            
  82.                     OurIceberg icy = uniqueIdictionary[pg.Destination.UniqueId];
  83.                    
  84.                     //IF owner of the arriving penguin group is in the same team as The
  85.                     //island it is going to, then it will reinforce the island.
  86.                     if(pg.Owner == icy.ownerInTurn[pg.TurnsTillArrival]) {
  87.                         for(int j = pg.TurnsTillArrival;j<icy.numPenguinsInTurn.Length;j++) {
  88.                             icy.numPenguinsInTurn[j] += pg.PenguinAmount;
  89.                         }
  90.                        
  91.                     //If not, then the penguin group will attack the island.    
  92.                     } else {
  93.                         for(int j = pg.TurnsTillArrival;j<icy.numPenguinsInTurn.Length;j++) {
  94.                             icy.numPenguinsInTurn[j] -= pg.PenguinAmount;
  95.                            
  96.                             //Num of penguins in an island will never be negative,
  97.                             //so if it is negaive, we invert it.
  98.                             //when theres an negative ammount of penguins
  99.                             //in an island, there was a takeover in the turn of arrival of the pg.
  100.                             if(icy.numPenguinsInTurn[j] <0) {
  101.                                 icy.numPenguinsInTurn[j] *= -1;
  102.                                 if(j == pg.TurnsTillArrival) {
  103.                                     for(int i=pg.TurnsTillArrival;i<icy.ownerInTurn.Length;i++) {
  104.                                         icy.ownerInTurn[i] = pg.Owner;
  105.                                     }
  106.                                 }
  107.                             }                        
  108.                         }
  109.                     }
  110.                 }
  111.                
  112.                 // Go over all of my icebergs.
  113.                 Iceberg[] myIcebergs = game.GetMyIcebergs();
  114.                 for(int i = 0;i<myIcebergs.Length;i++) {
  115.                     // The iceberg we are going over.
  116.                     Iceberg myIceberg = myIcebergs[i];
  117.                    
  118.                     // The amount of penguins in my iceberg.
  119.                     int myPenguinAmount = myIceberg.PenguinAmount;
  120.    
  121.                     // Initializing the iceberg we want to send penguins to.
  122.                     Iceberg destination = null;
  123.    
  124.                     // If there are any neutral icebergs.
  125.                     if (game.GetNeutralIcebergs().Length > 0)
  126.                     {
  127.                         // Target a neutral iceberg.
  128.                         destination = game.GetNeutralIcebergs()[0];
  129.                     }
  130.                     else
  131.                     {
  132.                         // Target an enemy iceberg.
  133.                         destination = game.GetEnemyIcebergs()[0];
  134.                     }
  135.    
  136.                     // The amount of penguins the target has.
  137.                     int destinationPenguinAmount = destination.PenguinAmount;
  138.                     // If my iceberg has more penguins than the target iceberg.
  139.                     if (myPenguinAmount > destinationPenguinAmount)
  140.                     {
  141.                         // Send penguins to the target.
  142.                         // In order to take control of the iceberg we need to send one penguin more than is currently in the iceberg.
  143.                         System.Console.WriteLine(myIceberg + " sends "+ (destinationPenguinAmount + 1) + " penguins to " + destination);
  144.                         myIceberg.SendPenguins (destination, destinationPenguinAmount + 1);
  145.                     }
  146.                 }
  147.             }
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement