コード例 #1
0
ファイル: MathewWarenski.cpp プロジェクト: ksundberg/CS1400
lionheart::Action lionheart::MathewWarenski::playInFortDefend(
    Unit const &u, SituationReport report, Plan p)
{
  auto dir = setdefdir(u, report);
  if (dir != u.getFacing())
    return turn(dir);
  if (p.hasAttack())
  {
    return p.attackEnemy();
  }
  return Action();
}
コード例 #2
0
ファイル: BrandonSmith.cpp プロジェクト: Gnomehax/CS1400
// function for game play
lionheart::Action lionheart::BrandonSmith::recommendAction(
  Unit const& u, SituationReport report, Plan p)
{
  ++numberofturns;
  auto loc = u.getLocation();
  find_kings(report);
  if (akingloc.col < 15) west = true;
  if (akingloc.col > 15) west = false;
  defpos(u, report);
  setdefdir(u, report);
  auto row = loc.row;
  auto col = loc.col;
  auto drow = defloc.row;
  auto dcol = defloc.col;

  if (u.getId() ==
      44) // give king bodyguard and prevents draw with non attacking armies
  {
    if (p.hasAttack()) return p.attackEnemy();
    if ((p.movesToAllyCrown() > 2) && (p.movesToEnemy() < 2))
      return p.moveToEnemy();
    if (p.movesToAllyCrown() > 2) return p.moveToAllyCrown();
  }

  if (u.getType() == CROWN) // rules for the king
  {
    if (p.hasAttack())
    {
      return p.attackEnemy();
    }
    if (mykingstupid(report))
    {
      if (west)
      {
        defloc.row = 14;
        defloc.col = 4;
        if ((row != 14) || (col != 4))
        {
          return p.moveToLocation(14, 4);
        }
      }
      if (!west)
      {
        defloc.row = 14;
        defloc.col = 25;
        if ((row != 14) || (col != 25))
        {
          return p.moveToLocation(14, 25);
        }
      }
    }

    if ((safe(row, col, report)) && (numberofturns < 300))
    {
      return turn(defdir);
    }

    if ((!safe(row, col, report)) || (enemyinthebox(report)))
    {
      ++whattodo;
      switch (whattodo)
      {
      case 0:
      case 1:
      case 2:
      case 3:
        if ((west) &&
            (report.things[19][3].type == lionheart::SituationReport::ALLY))
        {
          return p.moveToLocation(19, 2);
        }
        if ((west) &&
            (report.things[10][3].type == lionheart::SituationReport::ALLY))
        {
          return p.moveToLocation(10, 2);
        }
        if ((west))
        {
          return p.moveToLocation(19, 2);
        }
        if ((!west) &&
            (report.things[19][26].type == lionheart::SituationReport::ALLY))
        {
          return p.moveToLocation(19, 27);
        }
        if ((!west) &&
            (report.things[10][26].type == lionheart::SituationReport::ALLY))
        {
          return p.moveToLocation(10, 27);
        }
        if (!west)
        {
          return p.moveToLocation(19, 27);
        }
        break;
      case 4:
        if (akingloc.row > 15)
        {
          if (p.hasAttack())
            return p.attackEnemy();
          else
            return lionheart::turn(lionheart::Direction::NORTH);
        }

        else if (p.hasAttack())
          return p.attackEnemy();
        else
          return lionheart::turn(lionheart::Direction::SOUTH);
        break;
      case 5:
      case 6:
      case 7:
        if (safe(row, col, report))
        {
          return wait();
        }
        else
          return p.attackEnemy();
        break;
      }
    }
    if (safe(row, col, report))
    {
      return wait();
    }
    else
      return p.attackEnemy();
  }
  if ((numberofturns / 30) <
      10) // tells everyone what direction to face for defense;
  {
    if ((u.getFacing()) != defdir)
      return turn(defdir);
    else
      return wait();
  }

  if ((numberofturns / 30) <
      50) // this will stall in defense for half the game then attack
  {
    if (p.hasAttack()) return p.attackEnemy();
    if (enemyinthebox(report))
    {
      return p.attackEnemy();
    }
    if ((u.getId() == 39) || (u.getId() == 40))
    {
      if (p.movesToEnemy() < 3) return p.moveToEnemy();
      if ((row != drow) || (col != dcol)) return p.moveToLocation(drow, dcol);
      if ((u.getFacing()) != defdir)
        return turn(defdir);
      else
        return wait();
    }
    if ((u.getType() == KNIGHT) && (p.movesToEnemy() < 2))
      return p.moveToEnemy();
    if ((u.getType() != KNIGHT) && (p.movesToEnemy() < 5))
      return p.moveToEnemy();
    if ((row != drow) || (col != dcol)) return p.moveToLocation(drow, dcol);
    if ((u.getFacing()) != defdir)
      return turn(defdir);
    else
      return wait();
  }

  if (u.getType() == ARCHER) // sends archers around the fort if they can shoot
                             // over the wall and kill the king
  {
    return shootoverwall(u, report, p);
  }

  // tells everyone to attack
  if (p.hasAttack()) return p.attackEnemy();
  if (enemyinthebox(report)) return p.attackEnemy();
  if (p.movesToEnemyCrown() < 2)
    return p.moveToEnemyCrown();
  else
    return p.attackEnemy();
}