Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sauce's Rudolf AI
#1
This is a recently created AI by Sauce(一桶酱油), who is from the chinese community. I'm posting on his behalf.

This is a VERY tough "void id" AI for Rudolf, not unlike what YinYin had done with Crusher Davis.
It is not designed to dodge ranged attacks however, but good luck trying to take him down in melee combat.

Save the following code below as "5.as".
[Last Updated: 17 November 2019 - 11:18 (UST +8)]
    AI-Code:
//A Rudolf AI Created by Sauce.
//Thanks for Fonix's test and correction.
//It can't dodge balls or weapons......so just for practice!
 
//AI script begin.
void id() {
 
  left(0, 0);
  right(0, 0);
  up(0, 0);
  down(0, 0);
  D(0, 0);
  J(0, 0);
  A(0, 0);
 
  main();
}
 
//Main function.
void main() {
  int enemy = -1;
  bool fight = false;
  //Check enemy.
  for (int i = 0; i < 400; i++) {
    if (loadTarget(i) != -1 && target.num != self.num && target.team != self.team) {
      if (loadTarget(i) == 0 && target.team != self.team && target.hp > 0) {
        enemy = i;
        break;
      } else if (loadTarget(i) == 0 && target.team != self.team && target.hp <= 0)
        fight = true;
    }
  }
 
  int distancex = self.x - target.x;
  int distancey = self.y - target.y;
  int distancez = self.z - target.z;
 
  if (enemy != -1) {
    fight = true;
    loadTarget(enemy);
  }
 
  //Stage check.
  if (stage_clear)
    right(1, 0);
  if (self.clone == -1)
    clr();
  if (enemy != -1) {
    //Basic judgement.
    if (tinvincible() && target.hp > 0 && target.id != 4 && target.id != 5) {
      if (self.x >= bg_width * 3 / 4)
        left(1, 0);
      else if (self.x <= bg_width / 4)
        right(1, 0);
      else {
        if (distancex < 0)
          left(1, 0);
        else if (distancex >= 0)
          right(1, 0);
      }
    }
    if (self.state == 12 && tstuning())
      J(1, 0);
    //Walk and run.
    if (distancex >= 150)
      left(1, 0);
    else if (distancex <= -150)
      right(1, 0);
    if (distancez >= 5)
      up(1, 1);
    else if (distancez <= -5)
      down(1, 1);
    if (!tstuning() && !tdashing() && self.fall <= 60 && target.fall <= 30 && !tinvincible()) {
      if (self.x >= bg_width * 3 / 4 && abs(distancex) <= 60)
        left(1, 0);
      else if (self.x <= bg_width / 4 && abs(distancex) <= 60)
        right(1, 0);
      else if (self.x >= bg_width / 4 && self.x <= bg_width * 3 / 4) {
        if (distancex >= 150 || (distancex >= 0 && distancex <= 60))
          left(1, 0);
        else if (distancex <= -150 || (distancex <= 0 && distancex >= -60))
          right(1, 0);
        else if (distancex >= 60 && distancex <= 150)
          left(1, 0);
        else if (distancex <= -60 && distancex >= -150)
          right(1, 0);
      }
      if (distancex >= 60 && distancex <= 150)
        left(1, 0);
      else if (distancex <= -60 && distancex >= -150)
        right(1, 0);
    }
    //Defense,dodge and counterattack.
    if (abs(distancex) <= 250 && abs(distancez) <= 12 && (self.fall >= 30 || self.frame == 215 || tattacking()) && self.blink == 0) {
      if (abs(distancex) >= 170 && self.facing != target.facing && srunning()) {
        J(1, 0);
        A(1, 0);
      } else if (abs(distancex) <= 170) {
        if (self.facing == target.facing) {
          if (self.facing == true)
            right(1, 0);
          else
            left(1, 0);
        }
        D(1, 0);
      }
    }
    //Catch or super punch.
    if (tstuning() && abs(distancex) <= 200 && abs(distancez) <= 30) {
      if (distancex >= 10)
        left(1, 1);
      else if (distancex <= -10)
        right(1, 1);
      else
        A(1, 0);
      if (distancez >= 15)
        up(1, 1);
      else if (distancez <= -15)
        down(1, 1);
      if (target.fall <= 40 && abs(distancex) >= 80 && !(self.frame == 63 || self.frame == 67)) {
        A(1, 0);
        if (distancez >= 5)
          up(1, 0);
        else if (distancez <= -5)
          down(1, 0);
      }
    }
    //Punch.
    if (abs(distancex) <= 200 && abs(distancex) >= 50 && abs(distancez) <= 30 && abs(distancey) <= 40 && self.state <= 1 && !tfalling() && !tdashing() && !tinvincible() && self.fall <= 10) {
      if (distancex >= 0)
        left(1, 1);
      else
        right(1, 1);
      if (!tstuning() && !tfalling() && !trowing2()) {
        A(1, 0);
        if (distancez >= 5)
          up(1, 0);
        else if (distancez <= -5)
          down(1, 0);
      }
    }
    if ((self.frame == 63 || self.frame == 67) && !tstuning() && !tfalling() && !tdashing() && !trowing2() && !tinvincible() && (target.fall >= 15 || target.bdefend >= 10 || target.id == 4)) {
      A(1, 0);
      if (distancez >= 5)
        up(1, 0);
      else if (distancez <= -5)
        down(1, 0);
    }
    //Clone or disappear.
    if (self.mp >= 350 && (abs(distancez) >= 70 || abs(distancex) >= 300 || (target.state == 14 && target.hp > 0))) {
      if (rand(100) >= 80)
        DuJ();
      else
        DdJ();
    }
    //Catching.
    if (self.state == 9) {
      if (self.ctimer > 60) {
        left(0, 0);
        right(0, 0);
      }
      A(1, 0);
    }
    //Rowing2.
    if (abs(distancex) <= 80 && abs(distancez) <= 15 && !tfalling() && self.blink == 0)
      if (srunning() && target.id != 4)
        D(1, 0);
    //Prevent enemy rowing1.
    if (trowing1() && distancey <= 30) {
      if (abs(distancex) >= 100 && abs(distancex) <= 200 && abs(distancez) <= 30) {
        if (distancex >= 0)
          left(1, 0);
        else
          right(1, 0);
        A(1, 0);
      } else if (abs(distancex) <= 100 && abs(distancex) >= 50 && abs(distancez) <= 50) {
        if (distancex >= 0)
          DlA();
        else if (distancex <= 0)
          DrA();
      }
    }
    if (tfalling() && abs(target.x_velocity) == 13) {
      if (target.x_velocity > 0)
        right(1, 0);
      else
        left(1, 0);
      A(1, 0);
    }
    //Keep distance.
    if (trowing2()) {
      if (distancex >= 0)
        left(1, 0);
      else
        right(1, 0);
    }
    //Jump sword.
    if (target.id != 6 && self.frame >= 104 && self.frame <= 107 && abs(distancey) == 0 && abs(distancez) <= 12 && target.frame != 110 && !tinvincible()) {
      if (distancex >= 120 && distancex <= 150)
        DlJ();
      else if (distancex <= -120 && distancex >= -150)
        DrJ();
    }
    //Five punch.
    if ((self.frame != 110 || self.bdefend > 0) && abs(distancex) <= 120 && abs(distancex) >= 70 && abs(distancez) <= 30 && abs(distancey) <= 40 && self.mp >= 100 && self.fall == 0 && !trowing2() && !tfalling() && !tstuning() && !tdashing() && !tinvincible()) {
      if (distancex >= 0)
        DlA();
      else if (distancex <= 0)
        DrA();
    }
    if (self.frame == 289)
      if (!(tfalling() || tstuning() || tinvincible()) && distancez <= 40 && (target.fall >= 15 || target.bdefend >= 15))
        A(1, 0);
      else
        A(0, 0);
    //Dash attack and defense it.
    if (target.id != 6 && distancex >= 100 && distancex <= 180 && abs(distancez) <= 30 && abs(distancex) / abs(distancez) >= 4 && difficulty <= 0 && !tinvincible()) {
      if (!tstuning())
        left(1, 0);
      if (tdashing() && target.id != 4 && self.blink == 0)
        D(1, 0);
      else if (srunning()) {
        if (distancez >= 15)
          up(1, 0);
        else if (distancez <= -15)
          down(1, 0);
        if (!tattacking()) {
          J(1, 0);
          A(1, 0);
        } else
          D(1, 0);
      }
      if (self.frame == 215) {
        if (tdashing() && self.blink == 0)
          D(1, 0);
        left(1, 0);
        J(1, 0);
        A(1, 0);
      }
    } else if (target.id != 6 && distancex <= -100 && distancex >= -180 && abs(distancez) <= 30 && abs(distancex) / abs(distancez) >= 4 && difficulty <= 0 && !tinvincible()) {
      if (!tstuning())
        right(1, 0);
      if (tdashing() && target.id != 4 && self.blink == 0)
        D(1, 0);
      else if (srunning()) {
        if (distancez >= 15)
          up(1, 0);
        else if (distancez <= -15)
          down(1, 0);
        if (!tattacking()) {
          J(1, 0);
          A(1, 0);
        } else
          D(1, 0);
      }
      if (self.frame == 215) {
        if (tdashing() && self.blink == 0)
          D(1, 0);
        right(1, 0);
        J(1, 0);
        A(1, 0);
      }
    }
    //Countermeasure.
    if (target.id == 1) //Enemy is Deep.
    {
      if (target.frame == 310)
        A(1, 0);
      if ((self.state == 12 && target.frame >= 266 && target.frame <= 270) || (self.state == 12 && (target.frame == 295 || target.frame == 304)))
        J(1, 0);
    }
 
    if (target.id == 2) //Enemy is John.
    {
      if (self.state == 12 && ((target.frame >= 235 && target.frame <= 237) || (target.frame >= 290 && target.frame <= 295)))
        J(1, 0);
    }
 
    if (target.id == 4) //Enemy is Henry.
    {
      if (self.frame != 110 && self.state != 12 && !tstuning() && !trowing2() && !tinvincible() && abs(distancex) <= 160 && abs(distancex) >= 30 && self.mp >= 100) {
        if (distancex >= 0 && target.x_velocity <= 0)
          DlA();
        else if (distancex <= 0 && target.x_velocity >= 0)
          DrA();
      }
      if (self.state == 12 && target.frame >= 237 && target.frame <= 239)
        J(1, 0);
      if ((target.frame >= 60 && target.frame <= 62) && abs(distancex) <= 120 && abs(distancez) <= 30 && self.facing != target.facing && self.state <= 1)
        A(1, 0);
      else if (srunning() && abs(distancex) >= 100 && ((target.frame >= 63 && target.frame <= 64) || (target.frame >= 81 && target.frame <= 84) || (target.frame >= 239 && target.frame <= 242) || (target.frame >= 280 && target.frame <= 287)) && self.blink == 0)
        D(1, 0);
      if (target.frame >= 216 && target.frame <= 217 && abs(distancex) <= 60 && abs(distancex) >= 30) {
        if (target.x_velocity < 0)
          left(1, 0);
        else if (target.x_velocity > 0)
          right(1, 0);
        if (target.z_velocity > 0)
          up(1, 0);
        else if (target.z_velocity < 0)
          down(1, 0);
        else {
          up(0, 0);
          down(0, 0);
        }
      }
      if (!tinvincible() && !trowing2() && srunning() && abs(distancex) <= 80 && abs(distancez) <= 12) {
        if (distancey >= 10)
          J(1, 0);
        A(1, 0);
      }
      if (!sattacking() && !srunning() && !tstuning() && self.state != 12) {
        if (distancex >= 120)
          left(1, 0);
        else if (distancex <= -120)
          right(1, 0);
        if (abs(distancex) >= 150 && self.blink == 0) {
          if (distancez <= -20)
            up(1, 0);
          else if (distancez >= 20)
            down(1, 0);
          else if (self.frame != 215) {
            if (self.z >= bg_zwidth1 + ((bg_zwidth2 - bg_zwidth1) / 2))
              up(1, 0);
            else
              down(1, 0);
          }
        }
      }
      if (tinvincible() && target.hp > 0) {
        if (distancex >= 0)
          left(1, 0);
        else
          right(1, 0);
        if (distancez <= 0)
          up(1, 0);
        else
          down(1, 0);
      }
    }
 
    if (target.id == 5) //Enemy is Rudolf.
    {
      if (((target.frame >= 80 && target.frame <= 84) || target.frame == 118 || (target.frame >= 60 && target.frame <= 66) || (target.frame >= 273 && target.frame <= 275) || (target.frame >= 285 && target.frame <= 289)) && abs(distancez) < 30 && self.facing != target.facing && self.blink == 0)
        D(1, 0);
      if ((target.frame >= 74 && target.frame <= 77) || (target.frame >= 86 && target.frame <= 89) && self.state == 12)
        J(1, 0);
    }
 
  }
 
  if (target.id == 6) //Enemy is Louis.
  {
    if (abs(distancex) >= 30 && abs(distancex) <= 100 && abs(distancez) <= 80 && (target.state == 5 || (target.frame >= 90 && target.frame <= 99)) && self.blink == 0)
      D(1, 0);
    if (target.frame >= 247 && target.frame <= 258 && abs(distancex) <= 100 && distancez <= 30 && self.blink == 0) {
      D(1, 0);
      if (self.facing == true && target.facing == false)
        left(1, 1);
      else if (self.facing == false && target.facing == true)
        right(1, 1);
    }
  }
 
  if (target.id == 7) //Enemy is Firen.
  {
    if (target.frame >= 285 && target.frame <= 289 && abs(distancex) <= 60 && abs(distancez) <= 50 && self.blink == 0)
      D(1, 0);
  }
 
  if (target.id == 8) //Enemy is Freeze.
  {
    if (abs(distancex) <= 200 && ((target.frame >= 250 && target.frame <= 252) || (target.frame >= 260 && target.frame <= 268)) && self.facing != target.facing && srunning()) {
      J(1, 0);
      A(1, 0);
    }
  }
 
  if (target.id == 9) //Enemy is Dennis.
  {
    if (target.frame >= 284 && target.frame <= 287 && abs(distancex) <= 100 && distancez <= 30 && self.blink == 0) {
      D(1, 0);
      if (self.facing == true && target.facing == false)
        left(1, 1);
      else if (self.facing == false && target.facing == true)
        right(1, 1);
    }
  }
 
  if (target.id == 10) //Enemy is Woody.
  {
    if (self.facing != target.facing && abs(distancex) <= 100 && (target.frame >= 250 && target.frame <= 257) && self.blink == 0)
      D(1, 0);
    if (self.state == 12 && ((target.frame >= 70 && target.frame <= 72) || (target.frame >= 90 && target.frame <= 91) || (target.frame >= 250 && target.frame <= 254)))
      J(1, 0);
  }
 
  if (target.id == 11) //Enemy is Davis.
  {
    if (target.frame == 274)
      A(1, 0);
    if (target.frame >= 277 && target.frame <= 280)
      D(0, 0);
    if ((target.frame >= 73 && target.frame <= 75) || (target.frame >= 290 && target.frame <= 293) || (target.frame >= 300 && target.frame <= 303)) {
      if (self.state == 12 && abs(distancex) <= 70 && abs(distancez) <= 20)
        J(1, 0);
      else if (self.state <= 2 && abs(distancex) <= 70 && abs(distancez) <= 12 && self.blink == 0)
        D(1, 0);
    }
  }
//Output.
if (self.clone == -1) {
  if (enemy != -1 && self.hp > 0 && fight)
    print(
      "\n" +
      "Enemy is coming!" + "\n" +
      "\n"
      "Information:" + "\n" +
      "\n"
      "Self position:" + self.x + "\n"
      "Self hp:" + self.hp + "\n"
      "Self mp:" + self.mp + "\n"
      "Self state:" + self.state + "\n"
      "Self fall:" + self.fall + "\n"
      "Self frame:" + self.frame + "\n"
      "Self x_velocity:" + self.x_velocity + "\n"
      "Self y_velocity:" + self.y_velocity + "\n"
      "Self z_velocity:" + self.z_velocity + "\n" +
      "\n"
      "Distancex:" + distancex + "\n"
      "Distancey:" + distancey + "\n"
      "Distancez:" + distancez + "\n" +
      "\n"
      "Enemy position:" + target.x + "\n"
      "Enemy hp:" + target.hp + "\n"
      "Enemy mp:" + target.mp + "\n"
      "Enemy state:" + target.state + "\n"
      "Enemy fall:" + target.fall + "\n"
      "Enemy frame:" + target.frame + "\n"
      "Enemy x_velocity:" + target.x_velocity + "\n"
      "Enemy y_velocity:" + target.y_velocity + "\n"
      "Enemy z_velocity:" + target.z_velocity + "\n"
    );
  else if (self.hp <= 0 && fight)
    print("\n" +
      "I'm a deadman now!"
    );
  else if (enemy == -1 && fight)
    print("\n" +
      "No more enemy!" + "\n" +
      "\n"
      "I win,HAHA!"
    );
  else if (mode == 0 && !fight)
    print("\n" +
      "Let's start it!" + "\n" +
      "\n"
      "I will try my best!"
    );
  if (mode == 1 && !fight && (current_stage % 10 != 4) && stage_clear)
    print("\n" +
      "Let's go beat them!"
    );
  else if ((current_stage % 10 == 4) && stage_clear)
    print("\n" +
      "We clear the stage!" + "\n" +
      "\n"
      "Unbelievable!"
    );
}
}
 
//I am running.
bool srunning() {
  return self.state == 2;
}
//I am attacking.
bool sattacking() {
  return self.frame >= 59 && self.frame <= 94;
}
//Enemy is invincible.
bool tinvincible() {
  return target.state == 14 || target.blink > 0;
}
//Enemy is stuning.
bool tstuning() {
  return target.state == 16;
}
//Enemy is falling.
bool tfalling() {
  return target.state == 12;
}
//Enemy is attacking.
bool tattacking() {
  return (target.frame >= 70 && target.frame <= 73) || (target.frame >= 80 && target.frame <= 88 && abs(target.y) <= 60);
}
//Enemy is dashing.
bool tdashing() {
  return target.state == 5 || (target.frame >= 90 && target.frame <= 99);
}
//Enemy is rowing1.
bool trowing1() {
  return (target.frame >= 100 && target.frame <= 101) || (target.frame >= 108 && target.frame <= 109);
}
//Enemy is rowing2.
bool trowing2() {
  return target.frame >= 102 && target.frame <= 107;
}
[Image: uMSShyX.png]
~Spy_The_Man1993~
Steiner v3.00 (outdated), Challenge Stage v1.51
Luigi's Easier Data-Editor, A-Man's Sprite Mirrorer
Working on the LF2 Rebalance mod.
Avatar styled by: prince_freeza
Reply
Thanks given by: letoangt , phantim




Users browsing this thread: 1 Guest(s)