Pokémon TCG: Sword and Shield—Brilliant Stars

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

Status
Not open for further replies.

Daddiursa

New Member
Currently feedback on message #96 in this thread is much appreciated

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

Explaination of what this topic is about:

Calling all pokemaniacs out there!!

Now that the title have caught your attention, read on to find out what this weird topic is all about. You see, this fall I’m taking a course in High-level scripting languages at the University of Oslo (that’s programming languages in case you wonder). Python and Perl are examples of such languages. Now the best way to learn such a language is, I believe, to build something interesting in that language, like trying to make an exiting program... So I asked myself what that program could be, and since playing Pokemon is my #1 hobby, the answer gave itself. I want to make a program that you can play Pokemon TCG with.

Now, I know this might fail miserably due to the complexity of the task, but I am prepared to make limitations, and if it fails I will have learned something from building the program anyway, and that’s the main goal.

So what does this have to do with you, you might ask? Well, two things:

1) If you’re interested in Python programming you might wanna contribute by building parts of the program
2) If you want, you can enter this “think tank” and help out with comments about the design of the program as it emerges. Especially during the programming of the AI, where a sense of logic is really much more important that programming skills.

So what are those limitations I spoke about? Well, one cannot make the AI capable of handling any deck out there; one AI must be made for each deck. So I’m thinking about building it for Zap-Turn-Dos, as it is a pretty straightforward deck to play. But feel free to make comments about this as well. Also the program has to rely on command-line input and output in the beginning. I cannot start with spending many hours on a lush User Interface. A GUI will have to be built around the program at a later stage when the “engine” has legs to stand on.

So these are the tasks I see ahead, roughly speaking:

1) Find the data structures we need
2) Find out what kind of operations we have to do on those structures
3) Find the routines that must be established, how the program will float…
4) Build the AI
5) Make a GUI with buttons, card pictures, lists to choose from etc.


Here are my thoughts on Task #1:

Needed data structures:
  • Deck
  • Hand
  • Bench
  • Active Pokemon
  • Stadium
  • Discard Pile
  • Prizes
There has to be two instances of each of these “objects” except Stadium, one for the player and one for the machine. Also it’s not sufficient to just “name” them and make each of them capable of holding say a list of text strings carrying the name of each Pokemon on the bench. No, these might have to be “objects” because they have many separate values. Like a Pokemon on the bench can have a certain HP (due to damage), it can be evolved, it can be Rare-Candy evolved (skipped Stage 1), it can have energies attached and it can have trainers attached. So this is definitely a task which needs to be taken seriously.


Well, that’s it for now. It will be exiting to see if anyone has any comments about this. The topic will be made sticky soon, but at a later stage it might be moved if a more appropriate section can be found… But one thing is for certain, if we actually manage to make this program functionally, then that WILL BE NEWS…

So fellow programmers & designers out there, your time has come!

(Notice that this program has nothing to do with the Apprentice program itself, it was a way of illustrating my idea *points to topic title*)
 
Last edited:
The AI can only be as good as it's maker. So if we pull our heads together we might be able to build "the best AI" out there. The AI will have advantages we humans don't have... like making exact calculations on which card is most likely to appear on top of the deck and such things, but making the AI able to learn from mistakes... that's a science in itself... I don't think we will get there....
 
Last edited:
there has to be some way that this can work though.
i mean, excuse me if i bring up yu-gi-oh for a moment. take a look at their video games based on the tcg. very little does the computer opponents misplay.
and how can i forget the video game pokemon tcg? there were few misplays there aswell.
 
The problem for the AI is what to expect from the opponent. at the start it's straightforward. Hopefully a Voltorb, and extra on bench for safety, attach energy, recharge, and enter Zapdos ex turn two... but then later...when the Zappy dies... and you have Manetric's or Electrodes .... who should you bring up? You have to analyze a whole bunch of stuff right there and then to choose the best option. It's really tough to run thru everything one should consider, but hey, we can just start with the most obvious things to check for, and then expand it as time allows...
 
Last edited:
I tried this in Delphi. AI is just too much to handle. It would take you like month to programm AI for one deck.
Everything else is possible and relatively easy (aka involve basic skills).

However, your best bet would be to start by making AI for a deck with
1) only basics and energy cards (this would test deciding capabilities of whom to attach an energy.
2) next, try adding evolution and make it that when you have an evolution in hand and a correspondant basic in play you will evolve no matter what.
3) then make AI decide when its advantageous to evolve. Like if you can kill opponent with basic but not with stage 1 dont evolve.
4) try implementing basic trainers switch, potion that would activate depending on either being affected by a condition (switch) or having 2 or more damage (potion)
5) next try straight draw. Limit it to one with some kind of variable and your good.
6) shuffle and draw trainers would be next. This would be the worst to program, since you have to make AI decide when its advantegous to go for it. I would for a start make it use shuffle and draw trainer when no other card in its hand is playable.
7) Finally implement rest of trainers

Very exhausting task to try. If you could find a way in which my Borland Delphi programming would help you, I would gladly take part in this.
 
Venusaur said:
Would the AI look at what the opponent is doing and change its moves because of it? Like would it think "hey there's an Eevee on the opponent's bench. There's a chance it could evolve to Jolteon and since my Zapdos ex is weak to lightning, I'd better get Zapdos ex out of harms way".

If I tell the AI that, then yes that's how it's gonna work. But the trouble is in what sequence should the AI check for possible options... like should the AI first see if it can knock out the opponents active? (if the opponent has only one active retreatin to a "healthier" Manetric would be stupid if it can't KO the active). So then what should it do, should it "scan" the opponents pokemon for possible threats...? trying to save prizes... wait for Scoop Up... how should it "rate" the benefit of a KO of the opp. active leaving a damaged Zappy behind compared to a non-KO attack and leaving a fresh Manetric behind (as own active)...? That's tough descisions right there....
 
Last edited:
Why not programming a program which you can use to play pokemon online against human players and which automatically plays after the rules (like Magic online)?

Although an AI would be very, very cool.
 
metagross said:
I tried this in Delphi. AI is just too much to handle. It would take you like month to programm AI for one deck.
Everything else is possible and relatively easy (aka involve basic skills).

However, your best bet would be to start by making AI for a deck with
1) only basics and energy cards (this would test deciding capabilities of whom to attach an energy.
2) next, try adding evolution and make it that when you have an evolution in hand and a correspondant basic in play you will evolve no matter what.
3) then make AI decide when its advantageous to evolve. Like if you can kill opponent with basic but not with stage 1 dont evolve.
4) try implementing basic trainers switch, potion that would activate depending on either being affected by a condition (switch) or having 2 or more damage (potion)
5) next try straight draw. Limit it to one with some kind of variable and your good.
6) shuffle and draw trainers would be next. This would be the worst to program, since you have to make AI decide when its advantegous to go for it. I would for a start make it use shuffle and draw trainer when no other card in its hand is playable.
7) Finally implement rest of trainers

Very exhausting task to try. If you could find a way in which my Borland Delphi programming would help you, I would gladly take part in this.


That's a very good piece of advice right there! And that's why I'm going with Zapdos. It can win, it is certainly a boring deck... but for this to work it has to be a deck where the "desicion-making" is easy. My daughter uses a Zapdos deck and that too is "tweaked" to be easy to play. Less shuffling cards, straight draw etc.

You probably have lots to contribute with, so stick by!
 
Glumanda said:
Why not programming a program which you can use to play pokemon online against human players and which automatically plays after the rules (like Magic online)?

Although an AI would be very, very cool.

First, the aim is to learn valuable stuff for the scripting course I'm taking, and second, we already have Lackey and Apprentice.. I want to, however small, take a step back to the good ol' Pokemon TCG Gameboy Color game... I REALLY loved that game...
 
Sure if you ever needed to solve some kind of logic problem, I will gladly help! Shame I dont know anything about Python, but I can help you with all kinds of checks. I will probably make a list sometime tommorow to help you with this problem.
 
metagross said:
Sure if you ever needed to solve some kind of logic problem, I will gladly help! Shame I dont know anything about Python, but I can help you with all kinds of checks. I will probably make a list sometime tommorow to help you with this problem.

That's brilliant!!

At the level I am on now I'm thinking about the data structures (task #1), I'm trying to convince myself that using classes is the way to go, so I'm reading about that right now, Are you also into object-orientation? I haven't got a clue if Delphi is an obj.orient. language or not. In Python it is like with C++, it's an option, but not demanded. Anyway the AI is a little further down the road, so no need to be in a haste for input on that.
 
Last edited:
I don't know if Nintendo has a tradition for releasing old code, like many computer firms have... they release code for old games so that interested ppl can have fun with it. But I would guess that the gameboy game is written in Assembly Code, and that's virtually impossible to understand. Assembly code is purely movement of numbers. The whole program is made up by numbers that are being manipulated. So its not like "if this then do that else do that" like a high-level language. it's just nothing in common with a normal (spoken) language so you cannot just "jump" into it somewhere and say "ah, that's a cool effect, or "that's a smart way to play" b/c you have no clue if the numbers represent graphics or cards or logic or anything... it's all just numbers... people who understand this are the ones making computer viruses... I've seen the assembly code for Space Invaders... just for fun... and its like 2000 pages of numbers.. if I show it to you you will have nightmares....
 
Last edited:
We could then sell it to Nintendo as a core for a new TCG DS game! :lol:

Anyway, yeah Delphi is like an extension of Pascal, in the same way that C++ is an extension of C. It is obj. oriented, however I can see the basics done with simple IF, CASE and WHILE.

There is for sure a need for a plan. Its in fact the most important. You have to decide what you want to do and mainly HOW. I would myself start with just the game structure and focusing on that. Once youre done, you could start implementng AI. You have to be sure that everything works while controlled by the player before implementing in AI.

I guess the best would be to create 3 arrays of either objects or records (or equivalents on Python) each representing Deck, Discard Pile and your Hand. Howevermaking these classic static arrays would be a problem. So 3 dynamic arrays. When your turn starts (click a button), Hand array would expand to X+1 objects and Deck array shrink to Y-1. I dont know how fast the program would be though, if it would have to reconfigure at least 2 arrays each time a card is played.

Well, LMK if you need any help on how to program a specific part and I will try to help.
 
I have done some java-programming, so I'm thinking classes here. A class for Deck, Hand, Active, Bench etc. Both the player and the AI creates instances of these classes to capture everything they need. Now the methods are all written inside the class. So it will work like this when the Player draws a card

playerDeck.drawCard()

then the "playerDeck" object will do the nessecary steps: calling playerHand.add("the drawn card as parameter), plus it will remove this element from playerDeck.removeFirst (lists are basically arrays in Python, but Python is dynamically typed so lists can be of any type), and thus the list of the cards in the deck will be the same only without the element that was removed from the first spot.

So it will be a lot of playerBench.add("card").

I'm also thinking that the cards in itself should be objects... cos what happens when a damaged active goes to the bench? It doesn't help to change the names of the active pokemon? The "state" needs to be kept (eg. HP and cards attatched).

Any thoughts?
 
Last edited:
Agreed. Cards have to be objects. Well, what else? It has like a ton of info. Trainers would be the easiest I think. You would have a procedure inside that object named something like Effect or something, that would contain everything that has to be done and you would just call the procedure whenever a player decides to play that card.
 
It may be difficult to get the program to "interpret" effects of cards correctly so as to play by the rulings. It may also become a pain when rulings go and change on you...
 
The REALLY funny part will be to feed the AI with some appropriate things to say to it's opponent, based on how well it's doing. I bet it will be a nice touch to the program when the AI screams PWN!!!!!11! when your priced Ludicolo bites the dust... or threatens to start War Games in your backyard if you KO his Manectric...
 
Last edited:
WOW that's pretty cool, playing against a machine and test ur decks alone or at least with no one else but ur computer sound pretty cool..
Good luck with that !!!
 
Well, here's an update from the very very early stage in development, but for those of you interested. Here is the code at this stage:

(I'm trying to build the card-structures and setting a few values etc.)

#!/usr/bin/env python
import sys, math

try:
deck = sys.argv[1]
except:
print "Usage:",sys.argv[0], "deckname.txt"; sys.exit(1)

pDeck = open(deck, 'r') # open file for reading

playersDeck = []

# putting the cards from file into a list structure
for line in pDeck:
pair = line.split()
numb = float(pair[0]); name = pair[1]
counter = numb
while counter>0:
playersDeck.append(name)
counter -= 1

pDeck.close()

playerDeck = [] # to store cards "objects"

class Cards:
def __init__(self, name):
self.name = name
self.type = typeCheck(name)
if self.type == 'pokemon':
self.hp = findHP(self.name)
self.stage = findStage(self.name)
if self.type == 'trainer':
self.trainerType = findTrainerType(self.name)
print self.trainerType

def typeCheck (name):
trainers = ['Marys_request', 'Prof_Cozmo', 'Warp_point'] # For testing purposes
if name in trainers: return 'trainer'
pokemon = ['Zapdos_ex', 'Voltorb'] # For testing purposes
if name in pokemon: return 'pokemon'
energy = ['Lightning_energy'] # For testing purposes
if name in energy: return 'energy'

def findHP (name):
if name == 'Zapdos_ex': return 110
if name == 'Voltorb': return 40

def findStage (name):
if name == 'Zapdos_ex': return 0
if name == 'Voltorb': return 0

def findTrainerType (name):
supporters = ['Marys_request', 'Prof_Cozmo']
if name in supporters: return 'supporter'
nonSupporters = ['Warp_point']
if name in nonSupporters: return 'nonSupporter'

for line in playersDeck:
obj = Cards(line)
playerDeck.append(obj)


(later on I'll probably just post a link to a file, cos the code will get VERY lenghty as work progresses)


I'll just keep this for now, and move on to the next task. Making a routine for shuffling the deck.
 
Last edited:
Status
Not open for further replies.
Back
Top