Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using PenguinGame;
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Linq;
- namespace MyBot {
- public class TutorialBot : ISkillzBot {
- //Public dictionary [[Can be called from anywhere in the code]]
- //between uniqueId (key) to our class for icebergs info (value)
- public Dictionary<int, OurIceberg> uniqueIdictionary;
- public class OurIceberg {
- public int[] numPenguinsInTurn;
- public Player[] ownerInTurn;
- public int level;
- public string type;
- public Player[] owner;
- public Game game;
- //Constructor initializes all icebergs should only to be called in the first round
- public OurIceberg(Iceberg icy, int farthestDistance, string type, Game game) {
- this.level = icy.Level;
- this.numPenguinsInTurn = new int[farthestDistance];
- this.numPenguinsInTurn[0] = icy.PenguinAmount;
- this.ownerInTurn = new Player[farthestDistance];
- this.ownerInTurn[0] = icy.Owner;
- this.type = type;
- this.game = game;
- }
- //Initializes Arrays
- public void InitializeArrays()
- {
- for (int i = 0; i < numPenguinsInTurn.Length; i++)
- {
- this.numPenguinsInTurn[i] = this.numPenguinsInTurn[0];
- if (this.ownerInTurn[0] != game.GetNeutral()) { this.numPenguinsInTurn[i] += i * this.level; }
- this.ownerInTurn[i] = this.ownerInTurn[0];
- }
- }
- }
- public void DoTurn (Game game) {
- if(game.Turn == 1) {
- uniqueIdictionary = new Dictionary<int, OurIceberg>();
- //Make iceberg arrays
- Iceberg[] ourIcebergs = game.GetMyIcebergs();
- Iceberg[] allIcebergs = game.GetAllIcebergs();
- //Sort arrays
- System.Array.Sort(allIcebergs, delegate (Iceberg x, Iceberg y) {
- return ourIcebergs[0].GetTurnsTillArrival(x).CompareTo(ourIcebergs[0].GetTurnsTillArrival(y));
- });
- int farthestDistance = ourIcebergs[0].GetTurnsTillArrival(allIcebergs[allIcebergs.Length-1]);
- for(int i=0;i< allIcebergs.Length;i++) {
- if(i <allIcebergs.Length/3) {
- uniqueIdictionary.Add(allIcebergs[i].UniqueId, new OurIceberg(allIcebergs[i],farthestDistance, "defence", game));
- }else if(i > (int)(allIcebergs.Length/1.5)) {
- uniqueIdictionary.Add(allIcebergs[i].UniqueId, new OurIceberg(allIcebergs[i],farthestDistance, "attack", game));
- }else {
- uniqueIdictionary.Add(allIcebergs[i].UniqueId, new OurIceberg(allIcebergs[i],farthestDistance, "middle", game));
- }
- }
- }else {
- //Go through all the Icebergs and update the info in the Dictionary.
- foreach(Iceberg icy in game.GetAllIcebergs())
- {
- uniqueIdictionary[icy.UniqueId].InitializeArrays();
- }
- //Go through all the Penguin Groups and update the info in the Dictionary.
- foreach(PenguinGroup pg in game.GetAllPenguinGroups()) {
- OurIceberg icy = uniqueIdictionary[pg.Destination.UniqueId];
- //IF owner of the arriving penguin group is in the same team as The
- //island it is going to, then it will reinforce the island.
- if(pg.Owner == icy.ownerInTurn[pg.TurnsTillArrival]) {
- for(int j = pg.TurnsTillArrival;j<icy.numPenguinsInTurn.Length;j++) {
- icy.numPenguinsInTurn[j] += pg.PenguinAmount;
- }
- //If not, then the penguin group will attack the island.
- } else {
- for(int j = pg.TurnsTillArrival;j<icy.numPenguinsInTurn.Length;j++) {
- icy.numPenguinsInTurn[j] -= pg.PenguinAmount;
- //Num of penguins in an island will never be negative,
- //so if it is negaive, we invert it.
- //when theres an negative ammount of penguins
- //in an island, there was a takeover in the turn of arrival of the pg.
- if(icy.numPenguinsInTurn[j] <0) {
- icy.numPenguinsInTurn[j] *= -1;
- if(j == pg.TurnsTillArrival) {
- for(int i=pg.TurnsTillArrival;i<icy.ownerInTurn.Length;i++) {
- icy.ownerInTurn[i] = pg.Owner;
- }
- }
- }
- }
- }
- }
- // Go over all of my icebergs.
- Iceberg[] myIcebergs = game.GetMyIcebergs();
- for(int i = 0;i<myIcebergs.Length;i++) {
- // The iceberg we are going over.
- Iceberg myIceberg = myIcebergs[i];
- // The amount of penguins in my iceberg.
- int myPenguinAmount = myIceberg.PenguinAmount;
- // Initializing the iceberg we want to send penguins to.
- Iceberg destination = null;
- // If there are any neutral icebergs.
- if (game.GetNeutralIcebergs().Length > 0)
- {
- // Target a neutral iceberg.
- destination = game.GetNeutralIcebergs()[0];
- }
- else
- {
- // Target an enemy iceberg.
- destination = game.GetEnemyIcebergs()[0];
- }
- // The amount of penguins the target has.
- int destinationPenguinAmount = destination.PenguinAmount;
- // If my iceberg has more penguins than the target iceberg.
- if (myPenguinAmount > destinationPenguinAmount)
- {
- // Send penguins to the target.
- // In order to take control of the iceberg we need to send one penguin more than is currently in the iceberg.
- System.Console.WriteLine(myIceberg + " sends "+ (destinationPenguinAmount + 1) + " penguins to " + destination);
- myIceberg.SendPenguins (destination, destinationPenguinAmount + 1);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement