magic
  • magic
  • Member Topic Starter
2013-11-01T23:07:11Z
http://www.datafilehost.com/d/49bf2706 
********CURRENT VERSION********
*****Is no longer messing up*******

Hello, I'm magic. I lost internet access, so basically I could only play the AI on yugiohPRO.

This lead to me trying to improve the AI, which I can honestly say I did.

The thing is, all I did was modify seberian's code.

The things I have done is fix things like dragossack destroying itself on turn one, and more complicated
things like making sure big eye always steals an opposing big eye, and also that the computer attempts to play around draccossack correctly.

I have also added in code for many traditional staple cards such as pot of greed, raigeki, and duster.

Anyway, I intend to post my AI folder on to this site, because the AI duels much better with my modifications.

At this time I don't exactly know how to do that.

Anyway when ever the code gets posted anyone is free to use it in any way. I'm sure my code is a little sloppy and redundant, but it doesn't have to look pretty to work.

I'd also like to help collaborate on future versions of the AI. For instance I've already got code that allows the AI to use system down even if it plays necrovalley, there's honestly no reason not to grandfather in every snippet of code ever created for this (I assume to be open source) project.

--for i= #cards do
----if cards(i).id == card(id)
-----AI.Chat("I'm not joking, I really did alter the code, and I don't crash the program")
-----return 1
----else
-----return 0
----end
--end
Snarky
2013-11-02T07:29:24Z
Hey.

I am definitely interested in trying out your modifications. Just upload the script files to a file hoster of your choosing (Dropbox  comes to mind).

magic
  • magic
  • Member Topic Starter
2013-11-20T16:58:44Z
Hey guys... I'm not dead. I just still don't have internet at my house. I can only get online at my girl's house, and once again I forgot to flash drive my AI folder.

Hopefully I will get some files up this week.

Here's a quick list of what I have done.

1. Altered SelectCard.LUA to always attack tokens if a dracossack is on the field

2. Programmed a special script to pick the maximum number of targets if the AI is summoning chimeratech fotress dragon (This also involves messing with SelectInitCommand to set the GlobalSSID (currently this script can crash the program if the computer is using YOUR cyber dragon and yours alone to do the fusion, it's an easy but not-ideal fix, I could just have it always select the max targets, but that is not ideal in many situations).

3. I have Effect Veiler & Maxx "C" working correctly against some decks. For instance, effect veiler only activates under some very specific circumstances: If the players controls an ATK POS summon monk -->> activate veiler, also it is set to vieler any XYZ except Master of blades and Maestroke. Maxx "C" can currently only play against machine decks with machina fortress and redox, if either the summoning conditions for fortress or redox are met, activate maxx C (Only on Player's turn). This also involved putting both cads on the normal summon blacklist so the computer wont summon them.

4. I actually have the computer programmed to summon effect veiler if they control a LVL 7, and the player is susceptible to a crimson blader lock. (i.e - if they control a monster that can be destroyed by battle, and have no backrow... In essence, my AI can blader lock the player on purpose)

5. I have altered the battle program to suicide monsters instead of not doing that. This is because I have programmed the computer to ram Tidal into Big eye... I have written several special scripts to deal with certain monsters such as an unprotected dracossack / Big Eye / stardust dragon

6. I have written several functions that let the AI see into the player's hand / deck. I know this is cheating, but the AI is so stupid, if you want a good duel, you need to let it be psychic. It honestly makes it play much better, and seeing the opponents hand is one of the only ways to get Maxx C to work.

7. I have completely programmed the AI to utilize The magical scientist / dark strike fighter FTK, utilizing either plague or glow-up as the tuner.

8. Init command has been massively altered towards the top of the file.... If the AI plays any deck thinners or searchers, it plays cards that should be payed before pot of greed, before pot of greed. It now thins the deck before trying to draw.

9. Pot of duality has been givin a select card code to work with gravekeeper's. Trying to grab necrovalley / royal tribute.

10. As an example of my AI being psychic..... It is programmed to get out a turn 1 master of blades if the player has effect veiler.
else.... it goes for draccosack on a clear field.

11. I finally wrote this script, which I will simply recreate:


-- Counts the total attack of all AI's monsters

function AITotalATK()
local AIMON = Get.AImonsterZones()
local TOTATK = 0
for i=1, #AIMON do
if AIMON[i] ~= false then
TOTATK = TOTATK + AIMON[i].atk
end
end
end

the above counts the attack of all AI mons.

Then.... we compare that result with AI.GetOppLp(2) and.... if total attack is greater than the players LP, and it's main phase 1.... stop all actions and goto the battle phase.

12. Along those line, I have the AI programmed to Ring it's strongest monster if it's strongest monster's attack is greater than the Opp's LP.

13. I have several lines of script that deal only with decks I've made. For instance if the player controls a machine and the AI controls cyber dragon, it tries to special cyber dragon and fortress dragon BEFORE activating anything else such as heavy / darkhole / pot of greed.

I've done a lot of more stuff but I have to run.... I will upload my crap eventually, and if noting else my select card code needs to be looked at, since draccossack can be targeted by anything, and you usually don't want to if he has a token, my work-around for that that also works in every other situation, is worth a look to say the least.

Also when sebrian releases his next code, I'ma simply inject all my code up into that... So think of me as his un-official assistant.

I'll be in touch
Skaviory
2013-11-20T17:32:36Z
What a long yet helpful post! I am really looking forward to your codes. Could we at least have a glimpse of them? Well, since AI[Exia], Sebrian has also made a lot of modifications to his AI files. Merging yours with his might somehow cause conflict.
magic
  • magic
  • Member Topic Starter
2013-11-25T17:47:26Z
I expect it to be a nightmare getting my code to work with Sebrian's new code... From what I gather, he's re-done a lot of the AI helper functions, many of which are used in SelectInitCommand & select Card.

As for some code anyone can just pop into their AI folder with no bad result:

If you want the AI to play sixth sense correctly (always picking five or six) simply copy Sebrian's code for card trooper, and apply that to all instances where the AI has to pick a number (instead of using the random math function), this will cause the AI to pick the highests (or last) number on the list, always, after it picks 6, even if you don't use a DO loop, it should call SelectNumber again and then pick the next highest number (5)....

Also, this might actually help Sebrian / anyone else working on draccosack:

Dracossack's tokens are listed under their alias ONLY!

If you try to do any code involving draco-tokens, you must use the Alias insead of the card ID.

The alias is 31533705.


Also, if someone's reading this that working on the official AI.... you have torrential & darkhole programmed wrong.
You have it set up to wait until the player controls TWO more monsters than the AI... To make the computer pay better... make that ONE.
Currently the computer will hold darkhole & not activate torrential until it can get a + 2... For this stupid AI... any + 1 is fine, and waiting for the +2 will prolly get yer AI killed unless it's playing battle fader / swift scarecrow.

Also.... this tip is for those that can't code at all!

When making your decks, unless there's code to make something else happen:
The AI will summon monsters out of your extra deck in the order that they are in the deck creation screen. From right to left.
Meaning if you have Leviar to the right of zenmaines, it will always summon leviar first.

Just remember not to sort your deck and you'll be able to control how the AI plays a little more.

And this tip is for for developers!

I could not find out how to use the AI puzzle mode to test potential situations... So what I do is simply sort my deck by hand, and then duel the AI while telling yugiohPRO to not shuffle the decks... This is a very easy way to see how the AI plays certain hands.

I very well might get my AI folder up today!

I will also include my deck folder. If you play against my unlimited format dragon deck, you'll get to see how well the AI pays dracossack, since it can get one or two out every turn.
magic
  • magic
  • Member Topic Starter
2013-11-25T19:32:49Z
Here it is!

http://www1.datafilehost.com/d/6dad6398 

(For Your safety & my reputation, please run the RAR through a virus checker, it should be clean, but it's best to be safe)
Snarky
2013-11-26T02:35:00Z
It certainly talks a lot xD
RaiZZZ19
2013-11-26T09:49:35Z
Very good work Magic. Hope to see more of your work with Sebrian and Snarky too. Keep it up!
Kidd D
2013-11-26T09:55:12Z
Honestly the Ai tends to do dumb things in a battle wheres it could have easily defeated me some times but hasn't.
RaiZZZ19
2013-11-26T10:07:14Z
Originally Posted by: Kidd D 

Honestly the Ai tends to do dumb things in a battle wheres it could have easily defeated me some times but hasn't.



Really? Haven't tried it yet though.

magic
  • magic
  • Member Topic Starter
2013-11-26T20:01:31Z
I'm not claiming perfection, I just added a few things that make the AI handle dracossack & big eye better.

Anyway, I'm gonna continue to work on the stuff. There's truly much to do.

And the AI talks a lot because I don't really use the debugger at all! Instead of using a print command I use AI.Chat(), so I don't have to switch between windows.

By making the AI talk all the time, I know what part of the code it's reading if/when the program crashes.

Anyway, I guess I'm gonna try to download sebrian's new code, I thought it came packaged with the latest update but apparently I was wrong!

Also if anyone has anything they want implemented just post it here, as long as it doesn't conflict with more important code, I can add in support for it (but It will take time, till I get my internet back on). Also... If ya can't tell, I like to work on competitive cards, so if you want support for character decks (Think goblin attack force + final attack orders), well...
Skaviory
2013-11-27T04:53:44Z
Originally Posted by: magic 


Anyway, I guess I'm gonna try to download sebrian's new code, I thought it came packaged with the latest update but apparently I was wrong!



Well, if you ever need Sebrian's "latest" AI script, you can find it in the following post: AI BETA Collection .
Also, it is advised that you read the change note for each build first in order to know the exact progress.

Kidd D
2013-11-27T06:54:42Z
Originally Posted by: RaiZZZ19 

Originally Posted by: Kidd D 

Honestly the Ai tends to do dumb things in a battle wheres it could have easily defeated me some times but hasn't.



Really? Haven't tried it yet though.



Yeah it does, but it might depend though. It can use the Dark World deck as if it was meant for the deck or something. That deck can be monstrous in the hands of the AI, but when you give it a deck such as Frognarchs, it acts as if it does not know how to use it. Like summoning Raiza with no other monsters on the field; sending Raiza back to the hand, leaving the Ai wide open.

Theres other things, but it rarely does this with the Dark World deck but it does when it brings out that xyz Scorpion looking thing.
magic
  • magic
  • Member Topic Starter
2013-11-27T15:49:06Z
The reason the AI plays darkworld so well I almost all Thanks to sebrian's code.

Getting the AI to play monarchs correctly is a pretty easy fix which I guess I will do myself. (And by correctly I mean not incredibly stupidly).


  -------------------------------------------------------
  -- Tribute summoning logic
  -------------------------------------------------------   
   for i=1,#cards.summonable_cards do	  
	   CalculatePossibleSummonAttack(cards.summonable_cards)
	   if cards.summonable_cards[i].level >= 5 and NormalSummonBlacklist(cards.summonable_cards[i].id) == 0 and 
	   (AIMonCountLowerLevelAndAttack(cards.summonable_cards[i].level,cards.summonable_cards[i].attack) + GlobalAdditionalTributeCount) >= AIMonGetTributeCountByLevel(cards.summonable_cards[i].level) then
        if cards.summonable_cards[i].type ~= TYPE_MONSTER + TYPE_EFFECT + TYPE_FLIP and 
           (cards.summonable_cards[i].attack >= GetOppMonstersHighestAPosATK() and cards.summonable_cards[i].attack > HighestATKMonsterAPosDEF()) or 
		   CanChangeOutcome(cards, cards.summonable_cards, cards.activatable_cards) == 1 then   
		  GlobalActivatedCardLevel = cards.summonable_cards[i].level
          GlobalActivatedCardAttack = cards.summonable_cards[i].attack
		  GlobalSummonedCardID = cards.summonable_cards[i].id
		  GlobalSummonedThisTurn = GlobalSummonedThisTurn+1
		  GlobalAdditionalTributeCount = GlobalAdditionalTributeCount-1
		  return COMMAND_SUMMON,i
        end
      end
    end
	
   for i=1,#cards.summonable_cards do
       CalculatePossibleSummonAttack(cards.summonable_cards)
	   if cards.summonable_cards[i].level >= 5 and NormalSummonBlacklist(cards.summonable_cards[i].id) == 0 and
	   AIMonCountLowerLevelAndAttack(cards.summonable_cards[i].level,cards.summonable_cards[i].attack) >= AIMonGetTributeCountByLevel(cards.summonable_cards[i].level) then
         if cards.summonable_cards[i].type == TYPE_MONSTER + TYPE_EFFECT + TYPE_FLIP or 
           (cards.summonable_cards[i].attack < GetAIMonstersHighestATK() and cards.summonable_cards[i].defense >= GetAIMonstersHighestATK()) and 
		   CanChangeOutcome(cards, cards.summonable_cards, cards.activatable_cards) == 0 then   
		  GlobalActivatedCardLevel = cards.summonable_cards[i].level
          GlobalActivatedCardAttack = cards.summonable_cards[i].attack
		  GlobalSummonedCardID = cards.summonable_cards[i].id
		  GlobalSummonedThisTurn = GlobalSummonedThisTurn+1
		  GlobalAdditionalTributeCount = GlobalAdditionalTributeCount-1
		  return COMMAND_SET_MONSTER,i
        end
      end   
	end 

-----------------------------------------


after looking at that, the quickest fix I see is to add any monarch that could harm the AI (if played stupidly) to the summon blacklist, and then jump up in SelectInit and hard code the summons in card by card.

So only summon Raiza if the Opp has a card, and I believe Sebrian has already taken care of Zaborg.

That's what's so daunting about this whole task... 90% of the AI stupidity comes from the parts where it says "Activate / summon anything else here for now"... That means if we don't specifically tell the AI NOT to do something, it will do it. That means we need a line of code logic for basically every single card in the game in order to get the AI playing the best it can.

I guess I'll be working on that.
Cursedragon
2013-12-12T04:51:54Z
Your ai talk too much , its annoying [:angry:]
magic
  • magic
  • Member Topic Starter
2013-12-12T11:11:48Z
Well, I'm gonna have another massive update tomorrow.

The main things I've done is add support for atlantean mermails, found a way for the computer to play around maxx C, and just continued tweaking various things involving dracossack, also it talks much less.

I also have done a massive improvement on my "Go for game" code, which now takes into account the opponents monsters.

This new update plays mermails so well It's almost ready to start beating humans using an advanced deck.
It also crimson blader locks the opponent on purpose in decks using lvl 7's and effect veiler.

also.... if anyone really wants to stop the AI from talking, just open my select init file, and find/replace "AI.Chat" with "print" or if that's too hard "--" that will also work.

and finally I have started cataloging all of the code I have written myself. This will come in quite handy when I need to stick it into future updates, or if some of you simply want to add my code into yours.

I shall upload it in about 6 hours, I need some sleep.

Also - I know it's returning the incorrect amount of targets for xyz summons right now, but the core program is enforcing the correct count so that's not big on my list of things to do right now
magic
  • magic
  • Member Topic Starter
2013-12-12T19:24:14Z
Cursedragon
2013-12-12T20:25:47Z
i have a script error with ai lua, the ai doesn't attack.
magic
  • magic
  • Member Topic Starter
2013-12-17T00:09:12Z
well, you need my entire AI folder to make it work, i've edited almost every file i the folder.

another update soon, I have worked out some kinks with maxx C that needed addressing
dkates
2013-12-18T01:46:04Z
I was getting frequent cases of the script throwing an error with line 69 of SelectInitCommand (attempting to do arithmetic on a global variable), after which the AI would stop doing anything except what game mechanics and opposing effects forced it to do. I'm trying it with that line commented out, and so far, it doesn't seem to be a problem.

I'm still seeing examples of bone-headed play, though. I'll list some, mostly general cases, below. Sorry, I don't currently have any screenshots or anything.

- The biggest one is a tendency to Normal Summon (or Special Summon in Attack Position) monsters that have no business being Normal Summoned (Watapon, Big Shield Gardna, Copycat when the opponent has no monsters, that kind of thing). Big Shield Gardna is actually the most hilarious, since the AI practically refuses to ever put it in defense, when that's the whole point of the card.
- One you'd probably have to specifically code for, but I did see the AI use Premature Burial on a Gearfried the Iron Knight. (I gave it a Joey Character deck I'd built; it actually plays it competently enough, other than that.) You'd probably have to essentially code it as "Never target your own Gearfried the Iron Knight with equips, unless it's Blast with Chain/Smoke Grenade of the Thief"
- Like seberian's AI, there's a pronounced tendency to "jump the gun" on activating cards, especially ones that are Spell Speed 2.
- Occasional cases of attacking the wrong target. I'll need to gather some specific examples, but at least once, I've seen it attack an Attack Position monster that was bigger than the attacker, with no reason to do so.
- Another one also seen in seberian's AI -- when activating Thunder Dragon (I had the AI using a Kaiba deck I'd built), it will always get just one, even when it could get two. (It will then activate the new one.)
- Occasional cases of destroying its own cards when it doesn't have to (e.g. with Ryko). The simple fix, I'd think (given that I don't really know how the code works) would be to have the code say "never target your own cards with destroy effects"; this could later be updated to account for cases where you would actually want to do that (say, destroying your own Geartown/Limiter Overload/Yubel/whatever).

EDIT: Well, I think I know why the AI only ever gets one Thunder Dragon. My hint came when I saw multiple cases of the AI using a card that would require it to pick multiple targets for something, and triggering an error by only picking one. (Things like Lava Golem, Dimension Fusion, and so on.) Once the AI code starts picking the right number of targets in the general case of things that need (or can have) more than one, it'll probably always get two Thunder Dragon if it can. Too bad I don't know nearly enough to actually write that code.

EDIT 2: OK, I have no idea what could cause this one, but I swear this happened a few minutes ago. (Didn't take a screenshot. D'oh!) I give this AI the AI Dark World deck, AI goes first. Activates Gates of Dark World, Normal Summons Broww, ends. OK, so far so good. I go, Normal Summon Thunder King Rai-Oh, run over Broww, set some stuff, end. One of the cards in my hand at this point is Cardcar D. Opponent's turn, it draws, and somehow it Normal Summoned the Cardcar D from MY hand. Used the effect and everything.