Ejemplo n.º 1
0
    private Coordinate getMovementCoordinate(Game game, Unit unit, List<Coordinate> possibleMovementCoordinates)
    {
      List<Coordinate> coords = possibleMovementCoordinates;

      while (coords.Count != 0)
      {
        int n = dice(coords.Count);


        Coordinate c = coords[n - 1];
        //Console.WriteLine( "     "+".. trying to move to "+c+" =>"+ game.getUnit( c ));
        if (game.getUnit(c) == null)
          return c;
        else
          coords.Remove(c);
      }
      return null;
    }
Ejemplo n.º 2
0
    protected override void ProcessGame(Game detailed)
    {
      Console.WriteLine();
      Console.WriteLine("Game: " + detailed.Name + " (" + detailed.Id + ")");
      Console.WriteLine("  Getting Map info: " + detailed.MapId);
      WeewarMap wmap = eliza.GetMap(detailed.MapId);
      //Console.WriteLine(  "  Getting Map info: "+wmap.Terrains);
      Faction f = detailed.GetFactionByPlayerName(eliza.User);
      Console.WriteLine("  .. moving my dudes. ");
      foreach (Unit unit in f.Units)
      {
        Console.WriteLine("-----------------------------------------------------------------------------");
        Console.WriteLine("     " + unit.Type + "(" + unit.Quantity + ") on " + unit.Coordinate);

        // repair if quantity below 5
        if (!unit.Finished && unit.Quantity < 5)
        {
          String m = eliza.Repair(detailed.Id, unit.Coordinate);
          Console.WriteLine("     " + ".. repairing => " + m);
          unit.Finished = true;
          continue;
        }

        //
        // request movement coordinates
        List<Coordinate> possibleMovementCoordinates = eliza.GetMovementCoords(detailed.Id, unit.Coordinate, unit.Type);
        Util.Shuffle(possibleMovementCoordinates);
        possibleMovementCoordinates.Insert(0, unit.Coordinate);

        // check if there is a capturable base in range
        if (!unit.Finished && unit.CanCapture())
        {
          Coordinate c = MatchFreeBase(possibleMovementCoordinates, wmap, detailed, f);
          if (c != null)
          {
            String m = eliza.MoveAttackCapture(detailed.Id, unit.Coordinate, c, null, true);
            unit.Coordinate = c;
            Console.WriteLine("     " + ".. moving to " + c + " and capturing =>" + m);
            unit.Finished = true;
          }
        }
        List<Coordinate> targets = getTargets(detailed, wmap, f);
        int minDistance = MinDistance(unit.Coordinate, targets);

        int n = 5;

        if (minDistance <= 5 && !unit.Finished)
        {

          // Different moving spots that will be evaluated
          // check for possible attack targets from one of the targets
          for (int i = 0; i < n && i < possibleMovementCoordinates.Count; i++)
          {
            Coordinate c = possibleMovementCoordinates[i];
            Console.WriteLine("     " + ".. checking movement Option :" + c + " ");
            Coordinate a = getAttackCoordinate(detailed, unit, c);
            Console.WriteLine("     " + "..  attack coord :" + a + " ");
            if (a != null && detailed.getUnit(c) == null)
            {
              String m = eliza.MoveAttackCapture(detailed.Id, unit.Coordinate, c, a, false);
              Console.WriteLine("     " + ".. moving to " + c + " attacking " + a + " =>" + m);
              if (c != null)
                unit.Coordinate = c;
              unit.Finished = true;
              break;
            }
          }
        }

        if (!unit.Finished && possibleMovementCoordinates.Count > 1)
        {
          List<Coordinate> cities = getEnemyCities(detailed, wmap, f);
          AStarSearch s = new AStarSearch();
          s.SetStartAndGoalStates(new SticksNode(wmap, unit), new SticksNode(wmap, cities[0], unit));
          SearchState searchState;
          do
          {
            searchState = s.SearchStep();
          }
          while (searchState == SearchState.Searching);
          if (searchState == SearchState.Succeeded)
          {
          }

          Util.Shuffle(targets);
          Util.Shuffle(cities);
          possibleMovementCoordinates.RemoveAt(0);

          while (possibleMovementCoordinates.Count > 5) possibleMovementCoordinates.RemoveAt(5);
          while (cities.Count > 3) cities.RemoveAt(3);
          while (targets.Count > 3) targets.RemoveAt(3);

          bool cnt = true;
          while (cnt)
          {
            Console.WriteLine("     " + ".. possible movement options: " + Coordinate.ToString(possibleMovementCoordinates));
            Console.WriteLine("     " + ".. possible Targets: " + Coordinate.ToString(targets));
            Coordinate c;

            if (unit.Type == UnitType.Trooper)
              c = getClosest(possibleMovementCoordinates, cities);
            else
            {
              c = getClosest(possibleMovementCoordinates, targets);
              if (c.Equals(unit.Coordinate) && targets.Count == 0 && possibleMovementCoordinates.Count > 1)
                c = possibleMovementCoordinates[1];
            }

            if (!c.Equals(unit.Coordinate) && detailed.getUnit(c) == null)
            {
              String m = eliza.MoveAttackCapture(detailed.Id, unit.Coordinate, c, null, false);
              Console.WriteLine("     " + ".. moving to " + c + " =>" + m);
              unit.Coordinate = c;
              cnt = false;
            }
            else
              possibleMovementCoordinates.Remove(c);
            cnt = cnt && possibleMovementCoordinates.Count > 0;
          }
        }

        //Thread.sleep( 300 );
      }

      if (f.Units.Count * 3 < (detailed.GetUnitCount() * 2) || f.Units.Count < 15)
      {
        Console.WriteLine("     Terrains :" + Terrain.ToString(f.Terrains));
        if (f.Credits > 75)
        {
          foreach (Terrain terrain in f.Terrains)
          {
            Console.WriteLine("     " + terrain.Type + " on " + terrain.Coordinate + " finished:" + terrain.Finished + " unit: " + (detailed.getUnit(terrain.Coordinate) != null));
            if (!terrain.Finished && detailed.getUnit(terrain.Coordinate) == null)
            {
              Console.WriteLine("     " + terrain.Type + " on " + terrain.Coordinate);
              List<UnitType> options = buildOptions[terrain.Type];
              UnitType buildType;
              do
              {
                int nd = dice(options.Count);
                buildType = options[nd - 1];
              } while (f.Credits < Unit.GetCost(buildType));
              String x = eliza.Build(detailed.Id, terrain.Coordinate, buildType);
              Console.WriteLine("     .... building " + buildType + " " + x);
              f.Credits = (f.Credits - Unit.GetCost(buildType));
            }
          }
        }
      }
      if (eliza.EndTurn(detailed.Id))
        Console.WriteLine(" .. finished turn.");
      else
        Console.WriteLine(" .. failed to finish turn [" + eliza.GetLastResult() + "]");
    }
Ejemplo n.º 3
0
 private Coordinate getAttackCoordinate(Game game, Unit unit, Coordinate from)
 {
   List<Coordinate> coords = eliza.GetAttackCoords(game.Id, from, unit.Type);
   if (coords.Count > 0)
   {
     int n = dice(coords.Count);
     return coords[n - 1];
   }
   return null;
 }
Ejemplo n.º 4
0
 private List<Coordinate> getEnemyCities(Game game, WeewarMap wmap, Faction myFaction)
 {
   List<Coordinate> targets = new List<Coordinate>();
   List<Terrain> bases = wmap.getTerrainsByType(TerrainType.Base);
   foreach (Terrain ter in bases)
     if (game.getTerrainOwner(ter.Coordinate) != myFaction)
       targets.Add(ter.Coordinate);
   return targets;
 }
Ejemplo n.º 5
0
    private Coordinate MatchFreeBase(List<Coordinate> coords, WeewarMap wmap, Game g, Faction myFaction)
    {

      //Console.WriteLine("Coords:"+coords );
      foreach (Coordinate c in coords)
      {
        Terrain t = wmap.get(c);
        //Console.WriteLine("type :"+t.Type );
        Faction owner = g.getTerrainOwner(c);
        if (t.Type == TerrainType.Base && (owner == null || owner != myFaction) && g.getUnit(c) == null)
          return c;
      }
      return null;
    }
Ejemplo n.º 6
0
 protected override bool IdleGame(Game game)
 {
   Console.Write(".");
   return base.IdleGame(game);
 }
Ejemplo n.º 7
0
 private List<Coordinate> getTargets(Game game, WeewarMap wmap, Faction myFaction)
 {
   List<Coordinate> targets = new List<Coordinate>();
   foreach (Faction faction in game.Factions)
   {
     if (faction == myFaction)
       continue;
     foreach (Unit otherUnit in faction.Units)
       targets.Add(otherUnit.Coordinate);
   }
   return targets;
 }
Ejemplo n.º 8
0
 protected override void AcceptInvite(Game game)
 {
   Console.WriteLine("  .. accepting invitation");
   base.AcceptInvite(game);
 }
Ejemplo n.º 9
0
    private Game parseGame(XmlElement gameEle)
    {
      Game g = new Game();
      String att = gameEle.GetAttribute("inNeedOfAttention");
      g.IsInNeedOfAttention = att == "true";
      g.Name = gameEle.SelectSingleNode("name").InnerText;
      g.Id = Int32.Parse(gameEle.SelectSingleNode("id").InnerText);
      XmlNode map = gameEle.SelectSingleNode("map");

      if (map != null && map.InnerText != null)
        g.MapId = Int32.Parse(map.InnerText);
      g.Link = gameEle.SelectSingleNode("url").InnerText;
      g.RequiresAnInviteAccept = g.Link.Contains("join");
      if (gameEle.SelectSingleNode("factions") != null)
      {
        XmlNodeList factions = gameEle.SelectNodes("factions/faction");
        foreach (XmlElement faction in factions)
        {
          Faction f = new Faction();
          g.Factions.Add(f);
          f.PlayerName = faction.GetAttribute("playerName");
          f.State = faction.GetAttribute("state");
          if (!String.IsNullOrEmpty(faction.GetAttribute("credits")))
            f.Credits = Int32.Parse(faction.GetAttribute("credits"));
          foreach (XmlElement unit in faction.SelectNodes("unit"))
          {
            Unit u = new Unit();
            u.Coordinate = new Coordinate(Int32.Parse(unit.GetAttribute("x")), Int32.Parse(unit.GetAttribute("y")));
            u.Type = Unit.ToType(unit.GetAttribute("type"));
            u.Finished = "true" == unit.GetAttribute("finished");
            u.Quantity = Int32.Parse(unit.GetAttribute("quantity"));
            f.Units.Add(u);
          }
          foreach (XmlElement unit in faction.SelectNodes("terrain"))
          {
            Terrain t = new Terrain();
            t.Coordinate = new Coordinate(Int32.Parse(unit.GetAttribute("x")), Int32.Parse(unit.GetAttribute("y")));
            t.Type = Terrain.ToType(unit.GetAttribute("type"));
            t.Finished = "true" == unit.GetAttribute("finished");
            f.Terrains.Add(t);
          }
        }
      }
      return g;
    }
Ejemplo n.º 10
0
 protected virtual void ProcessGame(Game detailed)
 {
 }
Ejemplo n.º 11
0
 protected virtual bool IdleGame(Game game)
 {
   return true;
 }
Ejemplo n.º 12
0
 protected virtual void AcceptInvite(Game game)
 {
   eliza.AcceptInvite(game.Id);
 }