It is currently 29 Aug 2025, 09:18
   
Text Size

Getting started - hello

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Re: Getting started - hello

Postby Sloth » 01 Jul 2012, 06:51

mcrawford620 wrote:Regarding the functions above that check the costs for the AI, do those functions check if the AI can play the card *right now* when some of the mana is already tapped? I was actually hoping for a function that would see if the AI could theoretically play a card given the current mana situation, but if the mana was all untapped. Say, on his next turn.
A function like this hasn't been done yet.

mcrawford620 wrote:I see a couple of comments saying "AI cannot use this properly until he can use SAs during Humans turn." What is causing that limitation? Is there no way for the AI to cast spells during the Human's turn?
This is outdated (for at least three years).
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Getting started - hello

Postby friarsol » 01 Jul 2012, 14:11

Sloth wrote:
mcrawford620 wrote:I see a couple of comments saying "AI cannot use this properly until he can use SAs during Humans turn." What is causing that limitation? Is there no way for the AI to cast spells during the Human's turn?
This is outdated (for at least three years).
Haha not quite three years, but definitely at least two.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Getting started - hello

Postby mcrawford620 » 03 Jul 2012, 04:40

Another function question:

Can I, at an arbitrary time, figure out if the AI's life will be in danger from combat? I see the functions CombatUtil.lifeInDanger() and so on, but I'm not sure how to get a Combat object just whenever I want, or if that's even possible.
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times

Re: Getting started - hello

Postby Sloth » 03 Jul 2012, 06:13

mcrawford620 wrote:Another function question:

Can I, at an arbitrary time, figure out if the AI's life will be in danger from combat? I see the functions CombatUtil.lifeInDanger() and so on, but I'm not sure how to get a Combat object just whenever I want, or if that's even possible.
You can always create a new combat object (the real one is AllZone.getCombat()) and add attackers, blockers, etc.

Example:
Code: Select all
Combat combat = new Combat()
combat.addAttacker(cardX);
combat.addBlocker(cardX, cardY);
if (CombatUtil.lifeInDanger(combat)) {
...
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Getting started - hello

Postby mcrawford620 » 03 Jul 2012, 16:00

Hmm, I tried something like that, adding all of the potential human attackers one by one, but no AI blockers.

But I kept getting Array Out Of Bounds Exceptions, either in lifeInDanger() on this line:
Code: Select all
final CardList attackers = combat.sortAttackerByDefender()[0];
or down in sortAttackerByDefender():
Code: Select all
attackers[i].add(atk);
Do I have to add all of the potential blockers one by one as well? I couldn't figure that part out.
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times

Re: Getting started - hello

Postby Sloth » 03 Jul 2012, 16:30

Argh, i forgot to set the defender (player or planeswalker):
Code: Select all
Combat combat = new Combat()
combat.initiatePossibleDefenders(AllZone.getComputerPlayer());
combat.addAttacker(cardX);
combat.addBlocker(cardX, cardY);
if (CombatUtil.lifeInDanger(combat)) {
...
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Getting started - hello

Postby mcrawford620 » 03 Jul 2012, 22:18

OK I used something like that and now it works well. One thing I'm using it for is to work on some of these cards that Tap multiples of the human's creatures and stuff. It seemed like the only problem with the AI was that it would cast them to tap just one card, when it should wait to get the maximum cards out of it. So I put in a check where if the AI's life is not in danger, it will not cast the spell for less than the max effect.

Which taught me that Early Frost is a very annoying card to play against! Good luck getting anything started when your opponent has a bunch of those. :)
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times

Re: Getting started - hello

Postby Sloth » 04 Jul 2012, 09:26

Thanks a lot mcrawford. It's really nice to see someone else caring about the AI. :D

Just looking at this part of the code makes me want to add some more checks. Is this ok with you?
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Getting started - hello

Postby mcrawford620 » 05 Jul 2012, 04:05

Of course! I know I'm just putting in what I can think of, which isn't much.
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times

Re: Getting started - hello

Postby mcrawford620 » 05 Jul 2012, 05:49

I'm also committing some AI changes for fetching cards which is also just some basic logic, so add more if you can. Better than list.shuffle(), at least. Hopefully useful for the AI.
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times

Previous

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 27 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 27 users online :: 0 registered, 0 hidden and 27 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 27 guests

Login Form