Beispiel #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     Aa.Clear();
     Bb.Clear();
     Hh.Clear();
     rez.Clear();
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("------将字段转换为枚举值---------------");
            Bb zsGender = Bb.女;

            Console.WriteLine((int)zsGender);

            Console.WriteLine("------将枚举值转换为字段--------------");
            int myWorkDay = 4;

            Console.WriteLine((week)myWorkDay);

            Console.WriteLine("------将枚举转换为字符串--------------");
            week myWorkDay3 = week.周三;

            Console.WriteLine(myWorkDay3.ToString());
            Console.WriteLine(Convert.ToString(myWorkDay3));

            Console.WriteLine("------将字符串转换为枚举值--------------");
            week   myWorkDay4 = week.周四;
            string mystr2     = myWorkDay4.ToString();

            Console.WriteLine((week)Enum.Parse(typeof(week), mystr2));

            Console.ReadKey();
        }
Beispiel #3
0
 /// <summary>
 /// Convert this color to an hex string with format #AARRGGBB
 /// </summary>
 /// <returns>Hex string.</returns>
 public string ColorToHex()
 {
     return(String.Format("#{0}{1}{2}{3}"
                          , Ab.ToString("X").Length == 1 ? String.Format("0{0}", Ab.ToString("X")) : Ab.ToString("X")
                          , Rb.ToString("X").Length == 1 ? String.Format("0{0}", Rb.ToString("X")) : Rb.ToString("X")
                          , Gb.ToString("X").Length == 1 ? String.Format("0{0}", Gb.ToString("X")) : Gb.ToString("X")
                          , Bb.ToString("X").Length == 1 ? String.Format("0{0}", Bb.ToString("X")) : Bb.ToString("X")));
 }
        static void Main()
        {
            InheritanceToInterface obj = new InheritanceToInterface();
            Aa obj2 = (Aa)obj;
            Bb obj3 = (Bb)obj;

            obj2.Add();
            obj3.Add();
            Console.Read();
        }
Beispiel #5
0
    public static void DefendMother(Point defender, IEnumerable <Point> targets)
    {
        Bb.readBoard();
        if (!targets.Any() || !Bb.plantLookup.ContainsKey(defender))
        {
            return;
        }
        var mother          = Bb.ourMother.First();
        var plant           = defender.GetPlant();
        var nearestTarget   = targets.MinByValue(t => Trig.Distance(defender, t));
        var nearestDistance = Trig.Distance(defender, nearestTarget);

        switch (plant.Mutation)
        {
        case AI.ARALIA:
        case AI.CHOKER:
            if (plant.RadiatesLeft > 0)
            {
                if (plant.UprootsLeft > 0 && nearestDistance > plant.Range && nearestDistance <= plant.Range + Bb.GetUprootRange(plant.Mutation))
                {
                    var astar = Search(defender.Single(), Bb.GetUprootRange(plant.Mutation), nearestTarget, plant.Range);
                    if (astar.Path.Count() == 2)
                    {
                        var step = astar.Path.ElementAt(1);
                        plant.uproot(step.x, step.y);
                    }
                }
                if (Trig.Distance(plant.ToPoint(), nearestTarget) <= plant.Range)
                {
                    plant.radiate(nearestTarget.x, nearestTarget.y);
                }
            }
            if (plant.UprootsLeft > 0 && Trig.Distance(mother, defender) > 75)
            {
                Uproot(defender, mother, 75);
            }
            break;

        case AI.TITAN:
            if (plant.UprootsLeft > 0 && Trig.Distance(mother, defender) > 75)
            {
                Uproot(defender, mother, 75);
            }
            if (plant.UprootsLeft > 0)
            {
                var dest = Trig.CalcPointsInCircle(plant.ToUprootCircle()).Where(p => IsPassable(p)).MaxByValue(d => targets.Count(t => Trig.Distance(d, t) <= plant.Range));
                if (!dest.Equals(defender))
                {
                    plant.uproot(dest.x, dest.y);
                }
            }
            break;
        }
    }
Beispiel #6
0
    public static bool Uproot(Point mover, Point goal, int goalRange, bool avoidPools = true)
    {
        if (mover.GetPlant().UprootsLeft <= 0)
        {
            return(false);
        }
        Bb.readBoard();
        var plant = mover.GetPlant();
        var astar = Search(mover.Single(), Bb.GetUprootRange(plant), goal, goalRange);

        if (astar.Path.Count() > 1)
        {
            var step = astar.Path.ElementAt(1);
            plant.uproot(step.x, step.y);
            return(true);
        }
        return(false);
    }
Beispiel #7
0
 public Prices()
 {
     Type = Price.Close;
     Map  = new Dictionary <Price, List <double> >();
     foreach (Price type in Enum.GetValues(typeof(Price)))
     {
         Map[type] = new List <double>();
     }
     FastEma = new Ema(Const.DIRECTIONAL_FAST_EMA_LENGTH);
     SlowEma = new Ema(Const.DIRECTIONAL_SLOW_EMA_LENGTH);
     Bb      = new Bb(Const.BB_WIDTH, Const.BB_PERIOD);
     //Kc = new Kc(Const.BB_WIDTH, Const.BB_PERIOD);
     //Mc = new Mc(Const.BB_PERIOD);
     Macd       = new Macd(FastEma, SlowEma, Const.MACD_SIGNAL_LENGTH);
     Rsi        = new Rsi(Const.RSI_LENGTH);
     StochRsi   = new StochRsi(Rsi, Const.STOCH_RSI_LENGTH, Const.STOCH_RSI_D_LENGTH);
     Indicators = new List <IIndicator>
     {
         FastEma, SlowEma, Bb, /*Kc,*/ /*Mc,*/ Macd, Rsi, StochRsi
     };
 }
Beispiel #8
0
    /// <summary>
    /// This function is called each time it's your turn.
    /// </summary>
    /// <returns>Return true to end your turn, return false to ask the server for updated information.</returns>
    public override bool run()
    {
        if (turnNumber() >= 30)
        {
            ourTrash = () => new BitArray(Bb.OurReef).Or(Bb.NeutralReef);
        }
        missions.Clear();
        Bb.Update(this);
        manageSpecials();
        spawn();
        assignmissions();
        Executor.Execute(this, missions);

        /*
         * Executor.Execute(this, fishes.Where(f => f.Owner == playerID()).Select(f => new Mission[]
         *  {
         *      new Mission(f, Objective.getTrash, () => new BitArray(Bb.OurReef).Or(Bb.NeutralReef)),
         *      new Mission(f, Objective.dumpTrash, () => Bb.TheirReef)
         *  }.ToList()
         * ).ToList());*/
        return(true);
    }
Beispiel #9
0
    public static Point Spawn(int plantType, Point goal, int goalRange, bool avoidPools = true)
    {
        if (AI.me.Spores < AI.sporeCosts[plantType])
        {
            return(new Point(-1, -1));
        }

        var uprootRange          = Bb.GetUprootRange(plantType);
        var starts               = Bb.ourMother.Concat(Bb.ourSpawners);
        var goalEdge             = Trig.CalcInnerEdgeOfCircle(new Circle(goal, goalRange));
        var additionalNeighboors = goalEdge.Where(n => IsPassable(n)).ToHashSet();

        Func <Point, IEnumerable <Point> > getNeighboors = p =>
        {
            var stepSize = Bb.plantLookup.ContainsKey(p) ? p.GetPlant().Range : uprootRange;
            return(Trig.CalcInnerEdgeOfCircle(new Circle(p, stepSize))
                   .Concat(additionalNeighboors)
                   .Where(n => IsPassable(n, avoidPools) && Trig.IsInRange(p, n, stepSize)));
        };

        var astar = new Pather.AStar(
            starts,
            p => Trig.IsInRange(p, goal, goalRange) && IsPassable(p, avoidPools),
            (a, b) => 1,
            p => (int)Math.Ceiling(Trig.Distance(p, goal) / (double)uprootRange),
            getNeighboors);

        if (astar.Path.Count() > 1)
        {
            var p = astar.Path.ElementAt(1);
            AI.me.germinate(p.x, p.y, plantType);
            Bb.spawning.Add(p);
            return(p);
        }
        return(new Point(-1, -1));
    }
Beispiel #10
0
 /// <summary>
 /// This function is called once, before your first turn.
 /// </summary>
 public override void init()
 {
     Bb.init(this);
     OrderedOurCoveSet = new List <Tile>(Bb.OurCoveSet);
     OrderedOurCoveSet.Sort(new CoveComparer(new Point(Bb.MaxX / 2, Bb.MaxY / 2)));
 }
    /// <summary>
    /// Update the position of all droids
    /// </summary>
    /// <param name="droids"></param>
    public void update(Droid[] droids, Tile[] tiles)
    {
        ourHangers = new Bb(mapWidth, mapHeight);
        theirHangers = new Bb(mapWidth, mapHeight);
        ourMovables = new Bb(mapWidth, mapHeight);
        theirMovables = new Bb(mapWidth, mapHeight);
        ourImmovables = new Bb(mapWidth, mapHeight);
        theirImmovables = new Bb(mapWidth, mapHeight);
        notAttackedByEnemy = new Bb(mapWidth, mapHeight);
        walkable = new Bb(mapWidth, mapHeight);
        attackTargets = new Bb(mapWidth, mapHeight);
        hackTargets = new Bb(mapWidth, mapHeight);
        ourHalf = new Bb(mapWidth, mapHeight);
        theirHalf = new Bb(mapWidth, mapHeight);
        ourUnitsLowArmor = new Bb(mapWidth, mapHeight);
        for (int i = 0; i < mapWidth; i++)
        {
            for (int j = 0; j < mapHeight; j++)
            {
                if (i < 20)
                {
                    ourHalf.setValueAtSpot(i, j);
                }
                else
                {
                    theirHalf.setValueAtSpot(i, j);
                }
            }
        }
        if (ourID == 1)
        {
            ourHalf.board = ourHalf.board.Not();
            theirHalf.board = theirHalf.board.Not();
        }
        for (int i = 0; i < droids.Length; i++)
        {
            Droid current = droids[i];
            switch (current.Variant)
            {
                case (int)Unit.CLAW:
                case (int)Unit.ARCHER:
                case (int)Unit.REPAIRER:
                case (int)Unit.HACKER:
                case (int)Unit.TERMINATOR:
                    if (current.HealthLeft > 0)
                    {
                        if (current.Owner == ourID)
                        {
                            ourMovables.setValueAtSpot(current.X, current.Y);
                            if (current.HackedTurnsLeft > 0)
                            {
                                attackTargets.setValueAtSpot(current.X, current.Y);
                                hackTargets.setValueAtSpot(current.X, current.Y);
                            }
                            else if(current.Armor < current.MaxArmor)
                            {
                                ourUnitsLowArmor.setValueAtSpot(current.X, current.Y);
                            }
                        }
                        else
                        {
                            theirMovables.setValueAtSpot(current.X, current.Y);
                            if (current.HackedTurnsLeft <= 0)
                            {
                                attackTargets.setValueAtSpot(current.X, current.Y);
                                hackTargets.setValueAtSpot(current.X, current.Y);
                            }
                        }
                    }
                    break;
                case (int)Unit.TURRET:
                case (int)Unit.WALL:
                    if (current.HealthLeft > 0)
                    {
                        if (current.Owner == ourID)
                            ourImmovables.setValueAtSpot(current.X, current.Y);
                        else
                        {
                            theirImmovables.setValueAtSpot(current.X, current.Y);
                            attackTargets.setValueAtSpot(current.X, current.Y);
                        }
                    }
                    break;
                case (int)Unit.HANGAR:
                    if (current.HealthLeft > 0)
                    {
                        if (current.Owner == ourID)
                            ourHangers.setValueAtSpot(current.X, current.Y);
                        else
                        {
                            theirHangers.setValueAtSpot(current.X, current.Y);
                            attackTargets.setValueAtSpot(current.X, current.Y);
                        }
                    }
                    break;
            }
            if (current.Owner != ourID)
            {
                Queue<Point> frontier = new Queue<Point>();
                HashSet<Point> explored = new HashSet<Point>();
                frontier.Enqueue(new Point(current.X, current.Y));
                explored.Add(new Point(current.X, current.Y));
                int depth = 0;
                while (frontier.Count > 0 && depth < current.MaxMovement + current.Range)
                {
                    depth++;
                    Point point = frontier.Dequeue();

                    for (int j = -1; j < 2; j += 2)
                    {
                        Point pX = new Point(point.X + j, point.Y);
                        if (pX.X >= 0 && pX.X < mapWidth)
                        {
                            if (!explored.Contains(pX))
                            {
                                explored.Add(pX);
                                frontier.Enqueue(new Point(pX.X, pX.Y));
                                notAttackedByEnemy.setValueAtSpot(pX.X, pX.Y);
                            }
                        }

                        Point pY = new Point(point.X, point.Y + j);
                        if (pY.Y >= 0 && pY.Y < mapHeight)
                        {
                            if (!explored.Contains(pY))
                            {
                                explored.Add(pY);
                                frontier.Enqueue(new Point(pY.X, pY.Y));
                                notAttackedByEnemy.setValueAtSpot(pY.X, pY.Y);
                            }
                        }
                    }
                }
            }
        }

        notAttackedByEnemy.board.Not();
        walkable.board.Or(ourHangers.board).Or(theirHangers.board).Or(ourMovables.board).Or(theirMovables.board).Or(ourImmovables.board).Or(theirImmovables.board);
        foreach (Tile t in tiles)
        {
            if (t.TurnsUntilAssembled == 1)
            {
                walkable.setValueAtSpot(t.X, t.Y);
            }
        }
        walkable.board.Not();
    }
    public override bool run()
    {
        BoardState boardState = new BoardState(droids, tiles, mapWidth(), mapHeight(), playerID());

          Console.WriteLine("Turn Number: " + turnNumber().ToString());

          // Find rightmost enemy turret and spawn terminator
          // If this is our first turn
          if (turnNumber() < 2)
          {
          int x1 = 10;
          int y1 = 0;
          int x2 = 10;
          int y2 = 0;
          bool foundSpot = false;
          bool foundSecondSpot = false;
          for (int i = 0; i < droids.Length; i++)
          {
              if (droids[i].Variant == (int)Unit.TURRET)
              {
                  if (droids[i].Owner != playerID())
                  {
                      if (getTile(droids[i].X, droids[i].Y).TurnsUntilAssembled == 0)
                      {
                          if (playerID() == 0)
                          {
                              if (droids[i].X > x1)
                              {
                                  foundSpot = true;
                                  x1 = droids[i].X;
                                  y1 = droids[i].Y;
                              }
                              else if (droids[i].X > x2)
                              {
                                  foundSecondSpot = true;
                                  x2 = droids[i].X;
                                  y2 = droids[i].Y;
                              }
                          }
                          else
                          {
                              if (droids[i].X < x1)
                              {
                                  foundSpot = true;
                                  x1 = droids[i].X;
                                  y1 = droids[i].Y;
                              }
                              else if (droids[i].X < x2)
                              {
                                  foundSecondSpot = true;
                                  x2 = droids[i].X;
                                  y2 = droids[i].Y;
                              }
                          }
                      }
                  }
              }
          }
          if (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost && foundSpot)
          {
              players[playerID()].orbitalDrop(x1, y1, (int)Unit.TERMINATOR);
          }
          if (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost && foundSecondSpot)
          {
              players[playerID()].orbitalDrop(x2, y2, (int)Unit.TERMINATOR);
          }
          }

          // Find and spawn claws on enemy turrets
          // also count how many of each type we have
          int terminators = 0, claws = 0, archers = 0, hackers = 0, repair = 0;
          for (int i = 0; i < droids.Length; i++)
          {
          if (droids[i].Variant == (int)Unit.TURRET)
          {
              if (droids[i].Owner != playerID())
              {
                  if (getTile(droids[i].X, droids[i].Y).TurnsUntilAssembled == 0)
                  {
                      if (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.CLAW].Cost)
                      {
                          players[playerID()].orbitalDrop(droids[i].X, droids[i].Y, (int)Unit.CLAW);
                      }
                  }
              }
          }
          else
          {
              if (droids[i].Owner == playerID())
              {
                  switch (droids[i].Variant)
                  {
                      case (int)Unit.TERMINATOR:
                          terminators++;
                          break;
                      case (int)Unit.CLAW:
                          claws++;
                          break;
                      case (int)Unit.ARCHER:
                          archers++;
                          break;
                      case (int)Unit.HACKER:
                          hackers++;
                          break;
                      case (int)Unit.REPAIRER:
                          repair++;
                          break;
                  }
              }
          }
          }

          // DETECT WALLS
          int numUnits = 0;
          int colWithWall = -1;
          for (int i = 15; i < 25; i++)
          {
          int tempCount = 0;
          for (int j = 0; j < 20; j++)
          {
              if (boardState.theirMovables.getValueFromSpot(i, j) && !(getTile(i, j).TurnsUntilAssembled > 0))
                  tempCount++;
          }
          if (tempCount > numUnits)
          {
              numUnits = tempCount;
              colWithWall = i;
          }
          }
          // SPAWN CLAWS ON WALLS
          if (numUnits > 5)
          {
          for (int i = 0; i < 20; i++)
          {
              if (getTile(colWithWall, i).TurnsUntilAssembled == 0 && boardState.theirMovables.getValueFromSpot(colWithWall, i))
              {
                  if (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.CLAW].Cost)
                  {
                      players[playerID()].orbitalDrop(colWithWall, i, (int)Unit.CLAW);
                  }
              }
          }
          }

          Func<Point, bool> isWalkable = delegate(Point p)
          {
          return boardState.walkable.getValueFromSpot(p.X, p.Y);
          };

          // Search for best spawn location
          int bestRow = 0;
          Bb middleRows = new Bb(mapWidth(), mapHeight());
          HashSet<int> badRows = new HashSet<int>();
          for (int i = 19; i < 21; i++)
          {
          for (int j = 0; j < mapHeight(); j++)
          {
              middleRows.setValueAtSpot(i, j);
          }
          }
          bool foundRow = false;
          int curCol = (playerID() == 0) ? 0 : mapWidth() - 1;
          Func<Point, bool> middleTarget = spot =>
          {
          return middleRows.getValueFromSpot(spot.X, spot.Y);
          };
          Bb spawnWalkable = new Bb(mapWidth(), mapHeight());
          spawnWalkable.board = spawnWalkable.board.Or(boardState.walkable.board);
          spawnWalkable.board = spawnWalkable.board.Or(boardState.ourMovables.board);
          spawnWalkable.board = spawnWalkable.board.Or(boardState.theirMovables.board);
          int searches = 0;
          Func<Point, bool> spawnWalkableFunc = spot =>
          {
          return spawnWalkable.getValueFromSpot(spot.X, spot.Y);
          };
          while (!foundRow && searches < 15)
          {
          int shortest = 50;
          searches++;
          for (int i = 0; i < mapHeight(); i++)
          {
              if (getTile(curCol, i).TurnsUntilAssembled == 0)
              {
                  IEnumerable<Point> path = Searcher.findPath(new Point(curCol, i), middleTarget, spawnWalkableFunc);
                  int temp = -1;
                  foreach (Point p in path)
                  {
                      temp++;
                  }
                  if (temp != -1 && temp < shortest)
                  {
                      shortest = temp;
                      bestRow = i;
                      foundRow = true;
                  }
                  else if (temp == -1)
                  {
                      badRows.Add(i);
                  }
              }
          }
          if (!foundRow)
          {
              curCol = playerID() == 0 ? curCol + 1 : curCol - 1;
              badRows.Clear();
              if (curCol < 0 || curCol >= mapWidth())
              {
                  curCol = (playerID() == 0) ? 0 : mapWidth() - 1;
                  break;
              }
          }
          }
          if (searches >= 5)
          {
          curCol = playerID() == 0 ? curCol + 1 : curCol - 1;
          badRows.Clear();
          bestRow = 0;
          }
          // want 1 terminator and hacker per 2 archers and 3 claws
          bool spawnClaws = terminators > claws && turnNumber() < 250;
          bool spawnArch = 2 * terminators > archers && !spawnClaws;
          bool spawnHack = terminators > hackers && turnNumber() > 25 && !spawnArch;
          bool spawnRepair = .5 * terminators > repair && turnNumber() > 75 && !spawnHack;

          int cost = 10;
          int unitID = 0;
          bool doomDrop = false;
          if (spawnClaws)
          {
          unitID = (int)Unit.CLAW;
          cost = modelVariants[(int)Unit.CLAW].Cost;
          }
          else if (spawnArch)
          {
          unitID = (int)Unit.ARCHER;
          cost = modelVariants[(int)Unit.ARCHER].Cost;
          }
          else if (spawnHack)
          {
          unitID = (int)Unit.HACKER;
          cost = modelVariants[(int)Unit.HACKER].Cost;
          }
          else if (spawnRepair)
          {
          unitID = (int)Unit.REPAIRER;
          cost = modelVariants[(int)Unit.REPAIRER].Cost;
          }
          else
          {
          Random rand = new Random();
          if (rand.Next() % 3 == 0 && 500 - turnNumber() > 90)
          {
              // DOOM DROP TERMINATORS
              doomDrop = true;
          }
          unitID = (int)Unit.TERMINATOR;
          cost = modelVariants[(int)Unit.TERMINATOR].Cost;
          }

          Bb myUnits = new Bb(mapWidth(), mapHeight());
          myUnits.board = myUnits.board.Or(boardState.ourHangers.board);
          myUnits.board = myUnits.board.Or(boardState.ourImmovables.board);
          myUnits.board = myUnits.board.Or(boardState.ourMovables.board);
          int iter = bestRow;
          int rowsChecked = 0;
          if (doomDrop)
          {
          // Search for walls
          bool foundAWall = true;
          while (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost && foundAWall)
          {
              bool foundWallThisIter = false;
              for (int i = 0; i < droids.Length; i++)
              {
                  if (droids[i].Owner != playerID())
                  {
                      if (droids[i].Variant == (int)Unit.WALL)
                      {
                          if (getTile(droids[i].X, droids[i].Y).TurnsUntilAssembled == 0)
                          {
                              if (playerID() == 0)
                              {
                                  if (droids[i].X > 20)
                                  {
                                      players[playerID()].orbitalDrop(droids[i].X, droids[i].Y, (int)Unit.TERMINATOR);
                                      foundWallThisIter = true;
                                  }
                              }
                              else
                              {
                                  if (droids[i].X < 20)
                                  {
                                      players[playerID()].orbitalDrop(droids[i].X, droids[i].Y, (int)Unit.TERMINATOR);
                                      foundWallThisIter = true;
                                  }
                              }
                          }
                      }
                  }
              }
              if (!foundWallThisIter)
                  foundAWall = false;
          }
          if (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost)
          {
              // search for unreachable squares
              int theirFirstCol = mapWidth() - 1;
              if (playerID() == 1)
                  theirFirstCol = 0;
              int doomSearchIter = 0;
              bool blockedSpotFound = false;
              HashSet<int> rowsToSpawn = new HashSet<int>();
              while (doomSearchIter < 12 && !blockedSpotFound)
              {
                  for (int i = 0; i < mapHeight(); i++)
                  {
                      if (!(getTile(theirFirstCol, i).TurnsUntilAssembled > 0))
                      {
                          IEnumerable<Point> path = Searcher.findPath(new Point(theirFirstCol, i), middleTarget, spawnWalkableFunc);
                          int temp = -1;
                          foreach (Point p in path)
                          {
                              temp++;
                          }
                          if (temp == -1)
                          {
                              rowsToSpawn.Add(i);
                          }
                      }
                  }
                  if (rowsToSpawn.Count > 0)
                  {
                      blockedSpotFound = true;
                  }
                  else
                  {
                      doomSearchIter++;
                      if (playerID() == 0)
                      {
                          theirFirstCol--;
                      }
                      else
                      {
                          theirFirstCol++;
                      }
                  }
              }
              Console.WriteLine("Doom drop search spot done");
              if (doomSearchIter >= 7)
              {
                  doomSearchIter = 0;
              }
              int anotherIter = 0;
              while (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost && rowsToSpawn.Count > 0 && anotherIter < 2)
              {
                  int chooseRow = rowsToSpawn.GetEnumerator().Current;
                  players[playerID()].orbitalDrop(theirFirstCol, chooseRow, (int)Unit.TERMINATOR);
                  rowsToSpawn.Remove(chooseRow);
                  anotherIter++;
              }
              Console.WriteLine("Best spots have been tried");
              if (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost)
              {
                  theirFirstCol = mapWidth() - 1;
                  if (playerID() == 1)
                      theirFirstCol = 0;
                  for (int i = 0; i < mapHeight() && players[playerID()].ScrapAmount >= modelVariants[(int)Unit.TERMINATOR].Cost; i++)
                  {
                      if (!(getTile(theirFirstCol, i).TurnsUntilAssembled > 0))
                      {
                          if (!boardState.theirHangers.getValueFromSpot(theirFirstCol, i))
                          {
                              players[playerID()].orbitalDrop(theirFirstCol, i, (int)Unit.TERMINATOR);
                          }
                      }
                  }
              }
          }
          }
          else
          {
          while (rowsChecked < mapHeight())
          {
              // Not a bad row
              if (!badRows.Contains(iter))
              {
                  // enough scrap
                  if (players[playerID()].ScrapAmount >= cost)
                  {
                      // nothing spawning here
                      if (getTile(curCol, iter).TurnsUntilAssembled == 0)
                      {
                          if (!myUnits.getValueFromSpot(curCol, iter))
                          {
                              // spawn it
                              players[playerID()].orbitalDrop(curCol, iter, unitID);
                          }
                      }
                  }
                  iter++;
                  if (iter >= mapHeight())
                      iter = 0;
              }
              rowsChecked++;
          }
          }

          // ATTACK
          Func<Point, bool> isAttackable = delegate(Point p)
          {
          return boardState.theirHangers.getValueFromSpot(p.X, p.Y) || boardState.hackTargets.getValueFromSpot(p.X, p.Y);
          };
          Func<Point, bool> nope = delegate(Point p)
          {
          return false;
          };
          for (int i = 0; i < droids.Length; i++)
          {
          //if you have control of the droid
          if ((droids[i].Owner == playerID() && droids[i].HackedTurnsLeft <= 0) ||
              (droids[i].Owner != playerID() && droids[i].HackedTurnsLeft > 0))
          {
              //if there are any attacks left
              if (droids[i].AttacksLeft > 0)
              {
                  if (droids[i].Variant == (int)Unit.REPAIRER)
                  {
                      Bb targets = new Bb(boardState.ourHangers.width, boardState.ourHangers.height);
                      targets.board = targets.board.Or(boardState.ourHangers.board);
                      targets.board = targets.board.Or(boardState.ourMovables.board);
                      targets.board = targets.board.Or(boardState.ourImmovables.board);
                      Func<Point, bool> target = spot =>
                      {
                          return targets.getValueFromSpot(spot.X, spot.Y);
                      };
                      CIA.runMission(new Mission(MissionTypes.attackInRange, droids[i], target, isWalkable, nope));
                  }
                  else
                  {
                      Func<Point, bool> hackerTarget = spot =>
                      {
                          return boardState.hackTargets.getValueFromSpot(spot.X, spot.Y);
                      };
                      Func<Point, bool> target = spot =>
                      {
                          return boardState.attackTargets.getValueFromSpot(spot.X, spot.Y);
                      };

                      if (droids[i].Variant != (int)Unit.HACKER)
                      {
                          CIA.runMission(new Mission(MissionTypes.attackInRange, droids[i], target, isWalkable, nope));
                      }
                      else
                      {
                          CIA.runMission(new Mission(MissionTypes.attackInRange, droids[i], hackerTarget, isWalkable, nope));
                      }
                  }
                  boardState.update(droids, tiles);
              }
          }
          }

          Func<Point, bool> isEnemyHangar = delegate(Point p)
          {
          return boardState.theirHangers.getValueFromSpot(p.X, p.Y);
          };
          Func<Point, bool> isNotAttacked = delegate(Point p)
          {
          return boardState.notAttackedByEnemy.getValueFromSpot(p.X, p.Y);
          };
          Func<Point, bool> isGoalHacker = delegate(Point p)
          {
          return boardState.hackTargets.getValueFromSpot(p.X, p.Y);
          };

          for (int i = 0; i < droids.Length; i++)
          {
          if (droids[i].MovementLeft > 0 && ((droids[i].Owner == playerID() && droids[i].HackedTurnsLeft == 0) || (droids[i].Owner != playerID() && droids[i].HackedTurnsLeft > 0)))
          {
              if (droids[i].HealthLeft < .3 * droids[i].MaxHealth)
              {
                  Bb spotsOnOurSide = new Bb(mapWidth(), mapHeight());
                  spotsOnOurSide.board = spotsOnOurSide.board.Or(boardState.ourHalf.board);
                  if (droids[i].Variant == (int)Unit.REPAIRER)
                  {
                      Bb ourUnitsOurSide = new Bb(mapWidth(), mapHeight());
                      ourUnitsOurSide.board = ourUnitsOurSide.board.Or(boardState.ourHalf.board);
                      ourUnitsOurSide.board = ourUnitsOurSide.board.And(boardState.ourMovables.board);
                      Func<Point, bool> healTarget = spot =>
                      {
                          return ourUnitsOurSide.getValueFromSpot(spot.X, spot.Y);
                      };
                      CIA.runMission(new Mission(MissionTypes.goTo, droids[i], healTarget, isWalkable, nope));
                      spotsOnOurSide.board = spotsOnOurSide.board.And(boardState.walkable.board);
                      Func<Point, bool> runAway = spot =>
                      {
                          return spotsOnOurSide.getValueFromSpot(spot.X, spot.Y);
                      };
                      CIA.runMission(new Mission(MissionTypes.goTo, droids[i], runAway, isWalkable, isAttackable));
                  }
                  else
                  {
                      Bb theirUnitsOurSide = new Bb(mapWidth(), mapHeight());
                      theirUnitsOurSide.board = theirUnitsOurSide.board.Or(boardState.ourHalf.board);
                      theirUnitsOurSide.board = theirUnitsOurSide.board.And(boardState.theirMovables.board);
                      Func<Point, bool> attackOurSide = spot =>
                      {
                          return theirUnitsOurSide.getValueFromSpot(spot.X, spot.Y);
                      };
                      CIA.runMission(new Mission(MissionTypes.goTo, droids[i], attackOurSide, isWalkable, isAttackable));
                      spotsOnOurSide.board = spotsOnOurSide.board.And(boardState.walkable.board);
                      Func<Point, bool> runAway = spot =>
                      {
                          return spotsOnOurSide.getValueFromSpot(spot.X, spot.Y);
                      };
                      CIA.runMission(new Mission(MissionTypes.goTo, droids[i], runAway, isWalkable, isAttackable));
                  }
              }
              else
              {
                  if (!(droids[i].Variant == (int)Unit.HACKER))
                  {
                      if (droids[i].Variant == (int)Unit.REPAIRER)
                      {
                          Func<Point, bool> healTarget = spot =>
                          {
                              return boardState.ourUnitsLowArmor.getValueFromSpot(spot.X, spot.Y);
                          };
                          CIA.runMission(new Mission(MissionTypes.goTo, droids[i], healTarget, isWalkable, nope));
                      }
                      else if (droids[i].Variant == (int)Unit.TERMINATOR)
                      {
                          if (!CIA.runMission(new Mission(MissionTypes.goTo, droids[i], isEnemyHangar, isWalkable, isAttackable)))
                          {
                              CIA.runMission(new Mission(MissionTypes.goTo, droids[i], isGoalHacker, isWalkable, isAttackable));
                          }
                      }
                      else
                      {
                          if (!CIA.runMission(new Mission(MissionTypes.goTo, droids[i], isGoalHacker, isWalkable, isAttackable)))
                          {
                              CIA.runMission(new Mission(MissionTypes.goTo, droids[i], isEnemyHangar, isWalkable, isAttackable));
                          }
                      }
                  }
                  else
                  {
                      CIA.runMission(new Mission(MissionTypes.goTo, droids[i], isGoalHacker, isWalkable, isAttackable));
                  }
              }
              boardState.update(droids, tiles);
          }
          }

          // ATTACK again
          for (int i = 0; i < droids.Length; i++)
          {
          //if you have control of the droid
          if ((droids[i].Owner == playerID() && droids[i].HackedTurnsLeft <= 0) ||
              (droids[i].Owner != playerID() && droids[i].HackedTurnsLeft > 0))
          {
              //if there are any attacks left
              if (droids[i].AttacksLeft > 0)
              {
                  if (droids[i].Variant == (int)Unit.REPAIRER)
                  {
                      Bb targets = new Bb(boardState.ourHangers.width, boardState.ourHangers.height);
                      targets.board = targets.board.Or(boardState.ourHangers.board);
                      targets.board = targets.board.Or(boardState.ourMovables.board);
                      targets.board = targets.board.Or(boardState.ourImmovables.board);
                      Func<Point, bool> target = spot =>
                      {
                          return targets.getValueFromSpot(spot.X, spot.Y);
                      };
                      CIA.runMission(new Mission(MissionTypes.attackInRange, droids[i], target, isWalkable, nope));
                  }
                  else
                  {
                      Func<Point, bool> hackerTarget = spot =>
                      {
                          return boardState.hackTargets.getValueFromSpot(spot.X, spot.Y);
                      };
                      Func<Point, bool> target = spot =>
                      {
                          return boardState.attackTargets.getValueFromSpot(spot.X, spot.Y);
                      };
                      if (droids[i].Variant != (int)Unit.HACKER)
                      {
                          CIA.runMission(new Mission(MissionTypes.attackInRange, droids[i], target, isWalkable, nope));
                      }
                      else
                      {
                          CIA.runMission(new Mission(MissionTypes.attackInRange, droids[i], hackerTarget, isWalkable, nope));
                      }
                  }
                  boardState.update(droids, tiles);
              }
          }
          }

          #region Old Spawn Code
          //for (int i = 0; i < mapHeight(); i++)
          //{
          //    //make sure you own enough scrap
          //    if (players[playerID()].ScrapAmount >= modelVariants[(int)Unit.CLAW].Cost)
          //    {
          //        //make sure nothing is spawning there
          //        if (getTile((mapWidth() - 1) * playerID(), i).TurnsUntilAssembled == 0)
          //        {
          //            //make sure there isn't a hangar there
          //            if (!boardState.ourHangers.getValueFromSpot((mapWidth() - 1) * playerID(), i))
          //            {
          //                //spawn the claw
          //                players[playerID()].orbitalDrop((mapWidth() - 1) * playerID(), i, (int)Unit.CLAW);
          //            }
          //        }
          //    }
          //}
          #endregion

          return true;
    }
        static void Main(string[] args)
        {
            string A, B, C, D, E, F, G, H;
            string Aa, Bb, Cc, Dd, Ee, Ff, Gg, Hh, Ii, Jj, Kk, Ll, Mm, Nn, Oo;

            String[] ArrStr = new String[7];

            A = "Rizky Khapidsyah";
            B = "Nama Saya : ";
            C = A.Insert(0, B);
            D = " itu siapa?";
            E = A.Insert(16, D);
            F = "Ini Adalah: ";
            G = "Hari Rabu";
            H = G.Replace("Rabu", "Jum'at");

            ArrStr[0] = "Senin";
            ArrStr[1] = "Selasa";
            ArrStr[2] = "Rabu";
            ArrStr[3] = "Kamis";
            ArrStr[4] = "Jum'at";
            ArrStr[5] = "Sabtu";
            ArrStr[6] = "Minggu";

            /* Saya Sengaja tidak menggunakan variabel array untuk bagian ini (Aa, Bb, Cc dst..), agar kebih mudah dipahami.
             * Namun lebih disarankan menggunakan array dan statement for jika bekerja di lingkungan komersil
             */

            Aa = ", ";
            Bb = ".";
            Cc = Bb.Insert(0, ArrStr[6]);
            Dd = Cc.Insert(0, Aa);
            Ee = Dd.Insert(0, ArrStr[5]);
            Ff = Ee.Insert(0, Aa);
            Gg = Ff.Insert(0, ArrStr[4]);
            Hh = Gg.Insert(0, Aa);
            Ii = Hh.Insert(0, ArrStr[3]);
            Jj = Ii.Insert(0, Aa);
            Kk = Jj.Insert(0, ArrStr[2]);
            Ll = Kk.Insert(0, Aa);
            Mm = Ll.Insert(0, ArrStr[1]);
            Nn = Mm.Insert(0, Aa);
            Oo = Nn.Insert(0, ArrStr[0]);

            Console.WriteLine(A);
            Console.WriteLine(A.Length);
            Console.WriteLine(A.IndexOf('p'));
            Console.WriteLine(A[9]);
            Console.WriteLine(C);
            Console.WriteLine(E);
            Console.WriteLine(Oo);
            Console.WriteLine(F, G);
            Console.WriteLine(H);

            if (!H.Contains("Kamis"))
            {
                Console.WriteLine("Tidak Ditemukan Hari: Kamis");
            }
            else
            {
                Console.WriteLine("Ditemukan Hari: Kamis");
            }

            H = H.Remove(2);
            Console.WriteLine(H);

            Console.ReadLine();
        }
 public Aa(Bb b)
 {
 }
Beispiel #15
0
 // -----------------------------------
 // Constructor, persisting state for instance methods
 // -----------------------------------
 public Solver(ref Bb map)
 {
     this.map = map;
 }
Beispiel #16
0
 public override int GetHashCode()
 {
     return(Bb.GetOffset(x, y));
 }
        //偏差指数评价
        private void button2_Click(object sender, EventArgs e)
        {
            double Br, Bg, Bb;//三通道偏差指数

            double r, g, b;

            r = g = b = 0;
            Bitmap map2 = (Bitmap)img2;

            for (int i = 0; i < newBitmap.Width; i++)
            {
                for (int j = 0; j < newBitmap.Height; j++)
                {
                    Color pixel1 = newBitmap.GetPixel(i, j);
                    Color piexl2 = map2.GetPixel(i, j);

                    r += Math.Abs(pixel1.R - piexl2.R) * 1.0 / piexl2.R;
                    g += Math.Abs(pixel1.G - piexl2.G) * 1.0 / piexl2.G;
                    b += Math.Abs(pixel1.B - piexl2.B) * 1.0 / piexl2.B;
                }
            }

            Br = r / (newBitmap.Width * newBitmap.Height);
            Bg = g / (newBitmap.Width * newBitmap.Height);
            Bb = b / (newBitmap.Width * newBitmap.Height);

            MessageBox.Show("融合图三通道偏差指数" + "\r\n" + "Br:" + Br.ToString() + "   " + "Bg:" + Bg.ToString() + "   " + "Bb:" + Bb.ToString());
        }