Pokémon TCG: Sword and Shield—Brilliant Stars

The PokeM8 project: Building "apprentice with brains" in Python

Status
Not open for further replies.
As far as shuffling goes, just make sure to run through those steps at least 3x (shuffling the shuffled deck), as the "randomizer" for computers is at times less than random.
 
It's ALIVE!!

Well, most of the underlying datastructure are in place. I still need to make special routines for "wierd" attacks and poke-powers, but a Zappy deck and a T-Tar deck are what will face each other in battle in this program.. eventually after many longs nigths and lotsa coffee, that is...

Well, a genuine command-line driven interface is all there is for the moment... as I am about to start programming the actual play sequence...

pic1.JPG


(don't laugh!)

---------

Next picture I'll post will be of the "table" as both player have drawn their initial hand, put down basics, prizes etc..
 
Last edited:
Just a little step back to the shuffling issue, Here you see the deck-list after it's been shuffled 5000 times, there are still some cards stacked together, but I'm guessing this is the nature of statistics... I can't find a better way to shuffle... And I'm also guessing that the shuffling we do by hand isn't really random in the same way...

In [11]: run PokeM8.py
Master_Ball
Voltorb
Prof_Cozmo
Lightning_Energy
Lightning_Energy
TV_Reporter
Lanettes_Net_Search
Lightning_Energy
Lanettes_Net_Search
Manectric
Warp_Point
Prof_Cozmo
Voltorb
Master_Ball
Lightning_Energy
Zapdos_ex
Lightning_Energy
Marys_Request
Electrike
Manectric
Manectric
Warp_Point
Electrike
Lanettes_Net_Search
Marys_Request
Battle_Frontier
Electrike
Zapdos_ex
Lightning_Energy
Prof_Cozmo
Lanettes_Net_Search
Lightning_Energy
Lightning_Energy
Lightning_Energy
TV_Reporter
TV_Reporter
Electrike
Marys_Request
Prof_Cozmo
Master_Ball
Voltorb
Lightning_Energy
Battle_Frontier
Lightning_Energy
Lightning_Energy
Lightning_Energy
TV_Reporter
Zapdos_ex
Lightning_Energy
Marys_Request
Lightning_Energy
Battle_Frontier
Battle_Frontier
Manectric
Zapdos_ex
Master_Ball
Lightning_Energy
Voltorb
Lightning_Energy
Lightning_Energy
 
cattdreams said:
have you tried varying the random functions seed?

The shuffle functions goes something like this:

counter = 59

while counter >=0:
randomnumber = random.randint(0,counter) # Picks a random number between or including 0 and 59

...some code moving card[randomnumber] from a sorted deck list to the new shuffled one
...counter is incremented by one

# the program enters this loop until counter is -1, then is passes.


(For those of you unfamiliar with datastructures most languages number their lists, arrays etc from 0, and not like we count, from1 and up. So first instance of an array (etc) is array[0])
 
Last edited:
OK, no school assignments this week, so plenty of time to work on the PokeM8...

Here's small update:

pic2.JPG


...as you can see I have now reached the spot where the shuffling is done and the player gets to choose what basic to lay down.

(it's a pity the program isn't ready... I got quite a good hand... Spinning Tail turn two and all...)
 
Last edited:
OK, last update before I hit the sack.

pic3.JPG



This looks messy when you see it like this, but the important thing is the "ROUND" part at the bottom. Cos this will keep popping up whenever a round is finished or the player might wanna know the status/score.

Next job is to get some sort of menu with options so that the player can choose what he wants to do during his turn.

Please comment and suggest as you want. I'm all ears.
 
Last edited:
Is there code in there in case you have more than 1 Basic that you'd like to lay down? I'm talking player's choice, not computer error or anything like that. Also, you should have the 1st turn choice at the beginning, but I'm guessing that you have that planned after getting the major stuff down.

Is there any way to access the descriptions of a card before you put it down? Also, you might want to differentiate between sets for the Pokemon. For example: is that DX Jirachi, or HL Jirachi? Which Dk Pupitar is that? Shtuff like that.

This is looking great so far! Keep those updates coming, I'd love to see where this is going!
 
Thanks for the feedback!

There is a routine to place additional basic on the bench at start up, but the program don't show this option unless there really are more basics to put down. The AI will also let you know if he places more basics on the bench.

However handling errors (like typing letters where only numbers are legal entries) is saved for last...

You're right about descriptions. Initially I only though about that for cards on the hand... but in the long run you definately would want full info even when choosing a starter (cos there may be two versions of the same basic pokemon).

For the moment I'm only using one version of each card, but adding info about what set the card is form, and maybe collectors number to differentiate cards within the sets, is saved for later.

Right now there are two decks in the program. A Spinning Tail for you and a Zap-turn-dos for the machine. Since there are so many cards available, and each needs to be plotted into a database of some kind with full description of characteristics + there needs to be a function specially written for every different poke-body/power and attack out there, I am unsure of how to progress when (if) I'm done with this version. Maybe hear what deck you guys would find it interesting to play with. I dunno.
 
Small update!

pic4.JPG


Here you see I've included attack cost - attack name and attack damage for the AI's pokemon in play, at least. Will do the same for the player soon.

Attack text and poke-power/poke-body text will be included later... I'm not too sure how much I can include before this overview gets too messy... Opinions?

...and the ultimate goal is to wrap this in a graphical user-interface anyway, there a picture of the card will tell all the info needed, but for now I'll include as much as you need to be able to use the program and play with it.
 
Last edited:
As you see I'm on a roll here...

OK, now you have the chance to enter the complex world I'm living in at the moment... I could really use your input on how to deal with this AI-problem, namely choosing the best supporter to play...

Btw, here is the AI's deck-list, a really straight-forward Zap-turn-dos, made this way more for the sake of the programming than being the best deck out there :

4 Zapdos_ex
4 Voltorb
4 Electrike
4 Manectric
4 Marys_Request
4 Lanettes_Net_Search
4 Prof_Cozmo
3 TV_Reporter
2 Master_Ball
2 Warp_Point
3 Battle_Frontier
4 Super_Scoop_Up
18 Lightning_Energy


So the lines in itallic below are the ones I'd line you to think about.

Here is what might be called pseudo-code for handling the AI's way of finding the optimal supporter from the ones it has on it's hand:

1. Check if playing a Supporter is possible
2. Check if Lanettes Net Search is at hand
3. Check if Lanettes Net Search is the right card to play

NO: <Under what conditions>

YES: <Under what conditions>

4. Check if playing a Supporter is possible
5. Check if Marys Request is at hand

> Here I'll automaticly play Marys_Request, because by entering here
> I've ruled out Lanettes Net Search, and for simplicity I've
> rated this the best draw card in the deck, even though there are
> situations when you'd rather play one of the other draw cards even
> if you have Mary's at hand, but that's not dealt with here...

6. Check if playing a Supporter is possible
7. Check if Prof_Cozmo and TV Reporter both are present

YES: <Under what conditions should I choose Prof_Cozmo>
<Under what conditions should I choose TV Reporter>

NO: ok, just move on then...

... depending on the outcome at step 7 I either go on to use Cozmo or TV Reporter or none, because no one of those are at hand.

...now since playing Cozmo is easy, I move on to TV Reporter, which gives me this issue:

<How to find the optimal card to discard when using TV Reporter?>

----

Theres are choices where the answer might come easy to you during a game of Pokemon, but trying to really express what you're doing and how you're making prioreties... what's quite different.

So, once again your thoughts are welcome!!
 
Last edited:
Daddiursa said:
As you see I'm on a roll here...

OK, now you have the chance to enter the complex world I'm living in at the moment... I could really use your input on how to deal with this AI-problem, namely choosing the best supporter to play...

Theres are choices where the answer might come easy to you during a game of Pokemon, but trying to really express what you're doing and how you're making prioreties... what's quite different.

So, once again your thoughts are welcome!!
Hey there Daddiursa, I am currently a college student majoring in CIS (Computer Information Systems) and I have basic experience with C+ and Visual Basic. I know it isn't much, but I think I can try to help. Bear with me, they just introduced me to this programming stuff last semester so I'm still pretty new.

I'm not sure if your language (Python) uses a nested "IF" or not, but you could try using "IF" statements for the supporters (ie: can only play one supporter per turn, etc.).

For preventing people from playing multiple supporter cards you could try:
ColdFire64's basic "Nested 'IF' statement " said:
IF SUPPORTER(PLAYER_NUM)=TRUE THEN
MSGBOX("You can only play one supporter card per turn!")
UNDO_PLAY
ELSE
IF SUPPORTER(PLAYER_NUM)=FALSE THEN
PLAY_CARD;

As you know with programming, we'd have to initialize these variables at the beginning of the program.

The code I just made is an event that basically says, if a certain player (A or B) plays a supporter that's already in play, then a message box would appear telling the user that they can't play more than one supporter per turn. The "ELSE" means that if someone plays a supporter AND if it's they only supporter they played, then the card is played.

You also mentioned trying to get the AI to "prioritize" certain Supporter cards and make decisions about which supporter card to play. You could try this nested "IF" but I'm not sure if it would work. I would think that you would have to initialize the supporters as Integers rather than chars, and make a certain supporter equal to a certain number (like supporter1=1, supporter2=2, etc). You can then have the "IF" do some math to for the AI and tell it to choose the highest number supporter card in the hand to play during a particular turn.
ColdFire64's supporter AI code said:
IF SUPPORTER1< SUPPORTER2 THEN
SUPPORTER2=TRUE
ELSE
(etc.)
I'm not sure if I was doing that right, but I would assume that is what the logic is for this.

You may have to also initialize supporters as char so that when the cards are played you don't get a bunch of "supporter##" text. My guess would be to have it check the sequence of numbers and have it play the highest number. Supporters such as Professor Elm's Training Method may have a higher "priority" number than a Wally's Training.

I guess when it comes down to it, there is an issue with prioritizing the supporters since many people like to use different supporter cards that they feel is more better played than others. Perhaps an option to let the user set up/tell the AI which supporters to use as a way of testing their skills against certain cards would be a nice touch.

Just my thoughts. Sorry if I look like a newbie at this, but it's the best I can do for a beginning programmer.
 
Hi ColdFire64!

Nice of you to contribute with your thoughts. I think some of your questions regarding what Python can do in comparison to C++ wil be answered when you look at the present source code:

http://www.multinett.no/~simonsig/PokeM8/PokeM8.py
http://www.multinett.no/~simonsig/PokeM8/PokeM8module.py
http://www.multinett.no/~simonsig/PokeM8/AIs_deck.txt
http://www.multinett.no/~simonsig/PokeM8/Players_deck.txt

The .py files can be viewed in a program like Notepad, but when you view them in a program made for writing code in Pyhton (like Emacs, or a Python Shell etc), then you can apply color-coding which makes the code 10 times easier to read. I use IPython for testing the files, and IDLE Python Shell for writing code. I think both are freeware, we get them for free at least thru the course websites resource page, which happens to be in english. (Scroll down to the "Installing the Scripting Software on Windows" if Windows is your OS of choice).

The PokeM8.py is where the program is run from. The PokeM8Module features all the classes and all the functions I use thoughout the project, and it's imported by PokeM8.py (see beginning of code).

If-tests, while- & for-loops etc are the tools in this language too, to build the algorithms necessary. The language borrows heavily from C, C++ and Unix-methodology, as you will see.

Now over to some of your ideas. You introduce a "priority number" which you say also can be manipulated thru user input (for deck testing). This is a great idea, and certainly something I will bring with me in the project. But to be able to make the AI choose the best option this "prioritynumber" isn't always the same. Let me explain:

Scenario 1:
The AIs has a Voltorb in play with two energies, and can play another energy from the hand, but AI doesn't have Zapdos ex... That's when you want to play Lanette over any other supporter, to fetch Zapdos ex....

Scenario 2:
Same as above, only now you have a Zapdos ex, but not many other cards... just enough energy to do Electron Crush... You have LNS, but you also have other supporters... That's when you DON'T wanna play LNS...

Scenario 3:
You have a Zappy going as active, one at hand. Your have energies, you have both LNS and other supporters. You have a Manetric, but no Electrike... That's when you WANT to play LNS, to find an Electrike.

So in each of these scenarios the AI can't rely on a ready-made priority number, it has to analyze the cards on the table (seen as InPlayObjects in the code, named AIsActive and AIsBench) and the cards on AIs hand (AIsHand in the code). And then choose accordingly. It's heavy duty stuff, but I'm not giving up, by no means. It's actually the same thing you do yourself during a game of Pokemon TCG, only I have to express this in logical and mathematical terms (eg. coding algorithms).

Hope this made some sense... keep your opionions coming! They are valuable.

----

(Note that if you download the files and they just look like a big chunk of text, copy the content into new files, like Word-documents or something, and the text will look allright.)
 
Last edited:
Will this AI info eventually be able to adapt to other decklists? it just seems like all of this info is based on playing just one deck. 'ursa, do you think it's possible--once u get the coding down for the AI, that is--that there could be a non-codegeek-friendly way of editing the AI based on decklists and (possibly) difficulty against the player (measured in misplays)? that would be quite nice. GL w/ the project! it looks like u are making progress, so forge ahead!
 
mrdraz07 said:
Will this AI info eventually be able to adapt to other decklists? it just seems like all of this info is based on playing just one deck. 'ursa, do you think it's possible--once u get the coding down for the AI, that is--that there could be a non-codegeek-friendly way of editing the AI based on decklists and (possibly) difficulty against the player (measured in misplays)? that would be quite nice. GL w/ the project! it looks like u are making progress, so forge ahead!

Programming for other user deck-lists could be possible, that's just a matter of taking each card one at a time (Obviously starting with the most used/interesting ones). And when more cards are programmed for, the user can build even more types of decks. But when it comes to the AI it's another cup of tea... I chose Zapdos ex because it's a pretty straightforward deck, yet in terms of how much code it is to write a Zappy AI, I'm not talking a few lines... I have only just begun, and the code is approaching 800 lines by now.

So in other words an AI you can tune yourself is virtually impossible. But I'd really like to build more AI's, but then I have to build them from scratch... But when this version of The PokeM8 is done, I'll know a little more of what that's like... and if it's worth expanding this universe. Time will show.
 
Last edited:
Well for Supporters I would start by putting Supporters into groups.

(A)Draw
(B)Search
(C)Energy
(D)Other

I would create values for each card within the group. Personally I rate Mary's as the best Draw in the deck, the Cozmo, then TVR.

Then I would use some sort of evaluation of the opponent's possible deck. In the future, you would want to make a HUGE, all encompassing, set of code that would evaluate EVERY posibble Pokemon that could come into play next turn, AND, to be safe, assume it will have enough energy to do its best attack. Now the AI would play conservatively with that but its a good start. Back to the RL matchup though...

Evaluate the board and the AI's hand. If Zapdos ex is active and has 110HP, have the AI go through the math "What's the most damage that can be done next turn?" Well, the obvious answer is 120 from Dark Tyranitar so that's quite the dilemma!?!

You already have the basics: If Zapdos is in hand and Energy is good, play the Draw card. And so forth. Against RL I would only leave Zapdos ex out there for one turn unless you know 100% for sure that you won't get KO'd next turn. In my previous paragraph I stated that you wouldn't know 100% for sure so I would have the computer play the Draw card on the 1st turn possible unless the Zapdos had damage on it. Then on the 2nd turn I'd play Lanette's.

That is the most straight forward way to do it, especially since damage evaluation is nearly impossible with this matchup.

Another thought is to give the AI an aggressive side. If you're facing a Pupitar with 0 energy attached to it, Voltorb, Rare Candy, Energy Bomb, Rare Candy, Dark TTar is possible but let the computer play it out and assume that only 3 energy (Scramble) can be attached next turn to a Dark TTar.

My thoughts are a little muddled, looking back on them, but hopefully it made sense.
 
Thanks TacC!

I agree on the rating of the Supporters, which is basically how I will be doing it in the program. Except that I won't do it by points, I'll be doing it by sequence, let me explain. I write the code so that it checks for the most "critical" move first. That is finding Zapdos ex with Lanette when a Legendary Ascent is possible. If the AI needs to find a Zappy that way and plays Lanette, then a flag playedSupporter = 1 is set so that when the program execute the next chunk of code, it will just bypass whenever there is a check-for-supporter routine. After non-supporter trainers are played, energy attached, attacks performed etc, then it's the players turn, and then the whole sequence repreats itself. And of course there is a check for KO, special conditions etc in there too.

Oh, one more thing. The "test-deck" for the player is a T2 style Spinning Tail. So no unexpected Electrode bombing, no Pow!'ing and no scramble too. This makes it easier for the AI to calculate expected damage. Later if I get as far as wanting to introduce other decks, then naturally the AI needs to be "educated" too.

Update:

The Lanette-routine is now finished (not perfect though), but at least it's working (and thinking). The other supporters are "piece of cake", 'cept maybe choosing the card to discard when doing TV Reporter. So I'll have them done in a few days.

Later, when also attacking, placing energy, evolving, using powers etc etc are included in the program, I'll be looking for betatesters, people who would volunteer to install Python on their machine, and download the program for test-runs, and give me feedback on errors, omissions and suggestions on improvement...
 
Last edited:
We'll I've got Python on my PC (I'd have to dust off about 2 years of dust though) so I would love to Beta test it to death.

One thing I forgot to ask you... does the AI use Master Ball or Dual Ball before making any calculations regarding Supporter plays? It should play out the non-Supporters first and hope to keep the Supporter slot open for a TVR or something.

Also curious to see if the AI holds back on cards for fear of Rocket's Admin. If Zapdos ex is Active and in hand, will the AI play Dual Ball? Basically that's what I mean.
 
Status
Not open for further replies.
Back
Top