Jump to content

Scripting Organization Topic! <3


Amethyst

Recommended Posts

  • Replies 78
  • Created
  • Last Reply

Top Posters In This Topic

Code-heavy, but definitely possible.

Stall will be pretty hard to work out...

I mean, you can just score the hazards higher and then assume non-shuffling, non-hazard, non-toxic stuff to be bad so the loop sends teh AI into switching.

But stall is very prediction reliant. I mean, I can't think of any way to make that work the way the AI decision-making is setup :/

Link to comment
Share on other sites

Stall will be pretty hard to work out...

I mean, you can just score the hazards higher and then assume non-shuffling, non-hazard, non-toxic stuff to be bad so the loop sends teh AI into switching.

But stall is very prediction reliant. I mean, I can't think of any way to make that work the way the AI decision-making is setup :/

Baby steps, and even when I say that, split that into even smaller steps, to the point where we're basically playing QWOP through code.

Link to comment
Share on other sites

Good news everyone! Changed the way I was making the EV checker and managed to add it to the already-existing IV checker.

And it works too! yaaaaay

Stall will be pretty hard to work out...

I mean, you can just score the hazards higher and then assume non-shuffling, non-hazard, non-toxic stuff to be bad so the loop sends teh AI into switching.

But stall is very prediction reliant. I mean, I can't think of any way to make that work the way the AI decision-making is setup :/

Like I said, making custom stall AI is very code heavy. Consider an AI that plays chess -- it has to think many moves in advance and use many different strategies and such, making 'predictions' is possible for it. In Pokemon, you have to consider that any Pokemon could be using any move in it's learnset and any using possible combination of them. It's definitely harder to predict and takes a ton of checks but isn't impossible. Thankfully we wouldn't have to make an AI of crazy high caliber and could make assumptions in several situations (ie limiting learnsets we consider in checks to 'viable' moves, considering various 'optimal' sets for certain Pokemon [ex. Garchomp/Scizor are likely physical attackers whereas Alakazam or Reuniclus are usually specially based]).

Baby steps, and even when I say that, split that into even smaller steps, to the point where we're basically playing QWOP through code.

Yeah, it's likely that early AI code will be cluuuunky. Luckily for us, we have existing AI to make a foundation on and while we'd need much code, I think it's doable.

Nothing too excessive, though. Maybe just something that lets them know when to set up and when not to set up (e.g using Swords Dance with 10% HP left)

Er.. I dunno about 'too excessive'. I suppose the person with the final say on that is ... Ame eeeep

NOW BACK TO YOUR REGULARLY SCHEDULED CODE DUMP:

JudgeStats has been converted to accommodate for IVs OR EVs via a second input variable (where 0->IV and 1->EV)

# Stats Judge(s)
def pbJudgeStats(pkmn,switch)

  if switch == 0 # If it's the IV Judge, collect IVs
    health = pkmn.iv[PBStats::HP]
    attack = pkmn.iv[PBStats::ATTACK]
    defense = pkmn.iv[PBStats::DEFENSE]
    speed = pkmn.iv[PBStats::SPEED]
    spatk = pkmn.iv[PBStats::SPATK]
    spdef = pkmn.iv[PBStats::SPDEF]
  elsif switch == 1 # If it's the EV Judge, collect EVs
    health = pkmn.ev[PBStats::HP]
    attack = pkmn.ev[PBStats::ATTACK]
    defense = pkmn.ev[PBStats::DEFENSE]
    speed = pkmn.ev[PBStats::SPEED]
    spatk = pkmn.ev[PBStats::SPATK]
    spdef = pkmn.ev[PBStats::SPDEF]
  end
  
  # Sum the values of the IVs/EVs
  potential=0
  potential=health + attack + defense + speed + spatk + spdef
  
  # Determine the potential from the sum of the IVs/EVs
  # First comes the IVs
  if switch == 0
    if potential >= 0 && potential <= 90
      overall = "decent. A persistent trainer may be able to bring the best out of this Pokemon."
    elsif potential >= 91 && potential <= 120
      overall = "above average. With proper training, this Pokemon can be an excellent teammate."
    elsif potential >= 121 && potential <= 150
      overall = "relatively superior! I am certain that this Pokemon can easily excel!"
    elsif potential >= 151 && potential <= 186
      overall = "outstanding! This Pokemon has top marks across the board!"
    end
  end
  # EVs are next
  if switch == 1
    if potential >= 0 && potential <= 125
      overall = "average. There is much more training ahead of you."
    elsif potential >= 126 && potential <= 250
      overall = "hearty. Your Pokemon shows signs of solid improvement, keep it up."
    elsif potential >= 251 && potential <= 376
      overall = "robust. There is still room to grow, but your efforts continue to impress."
    elsif potential >= 377 && potential <= 509
      overall = "excellent! This Pokemon is truly a hard worker and it shows with near perfect growth."
    elsif potential == 510
      overall = "incredible!! Clearly this Pokemon's growth is at its peak!"
    end
  end
  
  # Determine the Pokemon's best IV or EV
  # (uses the same method as the characteristic determinant)
  
  bestiv=0
  bestev=0
  tiebreaker=pkmn.personalID%6

  if switch == 0 # Checking for best IV
    for i in 0...6
      if pkmn.iv[i] == pkmn.iv[bestiv]
       bestiv = i if i >= tiebreaker && bestiv < tiebreaker
      elsif pkmn.iv[i] > pkmn.iv[bestiv]
       bestiv=i
      end
    end
  end
  if switch == 1 # Checking for best EV
    for j in 0...6
     if pkmn.ev[j] == pkmn.ev[bestev]
      bestev = j if j >= tiebreaker && bestev < tiebreaker
     elsif pkmn.ev[j] > pkmn.ev[bestev]
      bestev=j
     end
    end 
  end

  # Determine the Pokemon's best IV/EV's statname
  statname = ""
  # Best IV statname
  if switch == 0
    if bestiv == 0
      statname = "Hit Points"
    elsif bestiv == 1 
      statname = "Attack"
    elsif bestiv == 2 
      statname = "Defense"
    elsif bestiv == 3
      statname = "Speed"
    elsif bestiv == 4
      statname = "Special Attack"
    elsif bestiv == 5
      statname = "Special Defense"
    end
  end
  # Best EV statname
  if switch == 1
    if bestev == 0
      statname = "Hit Points"
    elsif bestev == 1 
      statname = "Attack"
    elsif bestev == 2 
      statname = "Defense"
    elsif bestev == 3
      statname = "Speed"
    elsif bestev == 4
      statname = "Special Attack"
    elsif bestev == 5
      statname = "Special Defense"
    end
  end
  
  # Determine the Pokemon's best stat 'weight'
  if switch == 0
    if pkmn.iv[bestiv] >= 0 && pkmn.iv[bestiv] <= 15
      statweight = "relatively good."
    elsif pkmn.iv[bestiv] >= 16 && pkmn.iv[bestiv] <= 25
      statweight = "very good."
    elsif pkmn.iv[bestiv] >= 26 && pkmn.iv[bestiv] <= 30 
      statweight = "fantastic!"
    elsif pkmn.iv[bestiv] == 31
      statweight = "flawless!"
    end
  end
  if switch == 1
    if pkmn.ev[bestev] >= 0 && pkmn.ev[bestev] <= 63
      statweight = "average."
    elsif pkmn.ev[bestev] >= 64 && pkmn.ev[bestev] <= 127
      statweight = "relatively good."
    elsif pkmn.ev[bestev] >= 128 && pkmn.ev[bestev] <= 191
      statweight = "very good."
    elsif pkmn.ev[bestev] >= 192 && pkmn.ev[bestev] <= 254
      statweight = "fantastic!"
    elsif pkmn.ev[bestev] == 255
      statweight = "flawless!"
    end
  end
  
  ret = [overall,statname,statweight]
  
  return ret

end
I realize that it almost doubles the lines of code, but I can assure you that it works and works smooothly.

back to the code for now for me!

Edited by Blind Guardian
Link to comment
Share on other sites

Not to mention that AI is literally a completely separate and individual field on its own, I don't specialize in AI (I'm looking to specialize in data structures and algorithms, so I'm already at a disadvantage in practice for these codes) so what I pump out may turn up as nothing but a logic circuit.

I don't mean to be a parrot for Blind G (Biggy G, BG, BlinG), but it's entirely possible, it's just that creating a working non-generic AI is on a completely different ball game

Link to comment
Share on other sites

Not to mention that AI is literally a completely separate and individual field on its own, I don't specialize in AI (I'm looking to specialize in data structures and algorithms, so I'm already at a disadvantage in practice for these codes) so what I pump out may turn up as nothing but a logic circuit.

I don't mean to be a parrot for Blind G (Biggy G, BG, BlinG), but it's entirely possible, it's just that creating a working non-generic AI is on a completely different ball game

While AI is considered its own field, it builds off of both data structures and algorithms in their own rights so.. there's that. Don't sell yourself short, huh?

Besides, if we work on it together we can patch each other's gaps and whatnot. It'll be a thing (a future thing, but still a thing nonetheless).

Did I ever mention how much I enjoy your names for me? No? Okay..

Link to comment
Share on other sites

That video does seem like an improvement. The HP bar is still pretty slow, though---what could be the cause, and can it be rectified?

Again, nothing much I can do about the HP, they animate it by HP and scale it horizontally so that it fits in the HP bar.

You'll notice the bar drop considerably fast vs low leveled pokemon because there are less HP bars to animate, compared to high level pokemon with HP bars near or above 100.

Link to comment
Share on other sites

So it's like Gen 4 where I can use Close Combat on a Blissey, go make a cup of tea, come back and the HP bar would still be going down :D

Yeah, I would much more prefer how Pokemon Showdown does it and makes it a constant 100 bars

And do the % thing while they keep actual HP values being kept track in the back

Link to comment
Share on other sites

Since bugfixing is a very real possibility now, I'd like to report a bug.

So apparently, using Sunny Day before a Pokémon Selfdestructs, then switching to another person STILL makes Sunny Day get used.

Case save file provided. Look for the Scientist close to the Grand Hall.

Game.rxdata

Link to comment
Share on other sites

He proposed a simple solution that should work (he basically added a flag disallowing to cancel your action if you used an item).

I didn't test any of that, but on papper it looks like it should work just fine.

On paper, yes

but it won't work, and that's because each pokemon's command phase is independent from others, so even if I set the flag true for the first pokemon, it doesn't mean it's also true for the second.

I will have to access the variables involving double battles and possibly utilize some sort of global variable.

Link to comment
Share on other sites

Scratch that, I propose creating battle move equivalents of HP restoring items. the pbRegisterItem method is seriously flawed when used in battle.

The item identifier will be used to indicate the battle move used with priority of 6 (As it SHOULD be in the first place)

The logic for healing is already coded in moves like Rest.

The logic used for coding the battle phase can be copied to using items as well

My issue is that I might have trouble with the fact that now it's considered a move, it wouldn't necessarily USE the item, meaning it'll fix its double battle abuse, but rather if you go into battle with 1 full restore, you're basically set for the battle.

I might have to just call pbRegisterItem to a pokemon of nil reference (but idk if that will give me an error)

Edited by Woobowiz
Link to comment
Share on other sites

Actually, shouldn't items have a priority of 7?

This is a minor nitpick, but there are priority 6 moves.

Ofc it wouldn't matter, since those are protect and such, and they'll fail if you use an item.

But still, the item should always come before Protect, so it should have a higher priority than any move (even if this is a theoretical issue more than anything).

Well, I don't know if Protect and Detect and such actually have the priority of 6 in Essentials... they're listed as such on Smogon, I believe.

Anyway, I'll have to reread the item issue. Reworking the whole class sounds rather daunting though.

(Couldn't you just use the item quantity as PP? Well, not good because then Pokémon centers would recharge your items. You might as well add som sort of "quantity" on the move class and use it exclusively for the items... I'll leave you to that; you have it way too developed in your head already x) )

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...