It is currently 30 Oct 2025, 02:29
   
Text Size

AF_ZoneAffecting.drawCanPlayAI()

Post MTG Forge Related Programming Questions Here

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

AF_ZoneAffecting.drawCanPlayAI()

Postby Chris H. » 19 Nov 2010, 17:35

I was in the process of improving the AI for AF_ZoneAffecting.drawCanPlayAI() and I see that Sol got there first. With r3677 I get the following error exception.

Once this is taken care of I will try to figure out how to add my code into drawTargetAI(). My code was basically making sure that the AI would not draw into a hand size that is larger than it's max hand size. The code here is a little tricky since it originally assumes that draw abilities are targeted.

So if Sol can figure out how to fix the bug listed below I will try to add my code once again. :D

Code: Select all
An error has occured. You can copy/paste this message or save it to a file.
Please report this, plus what you tried to do, to:
   http://www.slightlymagic.net/forum/viewforum.php?f=26
If you don't want to register an account, you can mail it directly to
   mtgerror@yahoo.com


There is an error in the card code for Divination:



Version:
Forge -- official beta: $Date: 2010-09-14 08:34:27 -0400 (Tue, 14 Sep 2010) $, SVN revision: $Revision: 2039 $

OS: Mac OS X Version: 10.6.4 Architecture: x86_64

Java Version: 1.6.0_22 Vendor: Apple Inc.

Detailed error trace:
java.lang.NullPointerException
   at forge.AbilityFactory_ZoneAffecting.drawCanPlayAI(AbilityFactory_ZoneAffecting.java:150)
   at forge.AbilityFactory_ZoneAffecting$2.canPlayAI(AbilityFactory_ZoneAffecting.java:58)
   at forge.ComputerAI_General.getPlayable(ComputerAI_General.java:151)
   at forge.ComputerAI_General.getMain2(ComputerAI_General.java:138)
   at forge.ComputerAI_General.playCards(ComputerAI_General.java:28)
   at forge.ComputerAI_General.main2(ComputerAI_General.java:24)
   at forge.ComputerAI_Input.think(ComputerAI_Input.java:65)
   at forge.ComputerAI_Input.showMessage(ComputerAI_Input.java:31)
   at forge.GuiInput.setInput(GuiInput.java:27)
   at forge.GuiInput.update(GuiInput.java:21)
   at java.util.Observable.notifyObservers(Observable.java:142)
   at java.util.Observable.notifyObservers(Observable.java:98)
   at forge.MyObservable.updateObservers(MyObservable.java:9)
   at forge.InputControl.resetInput(InputControl.java:32)
   at forge.Input_PassPriority.selectButtonOK(Input_PassPriority.java:39)
   at forge.GuiInput.selectButtonOK(GuiInput.java:35)
   at forge.GuiDisplay3.okButtonActionPerformed(GuiDisplay3.java:1001)
   at forge.GuiDisplay3.access$3(GuiDisplay3.java:1000)
   at forge.GuiDisplay3$26.actionPerformed(GuiDisplay3.java:795)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.plaf.basic.BasicButtonListener$Actions.actionPerformed(BasicButtonListener.java:287)
   at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1639)
   at javax.swing.JComponent.processKeyBinding(JComponent.java:2851)
   at javax.swing.JComponent.processKeyBindings(JComponent.java:2886)
   at javax.swing.JComponent.processKeyEvent(JComponent.java:2814)
   at java.awt.Component.processEvent(Component.java:6129)
   at java.awt.Container.processEvent(Container.java:2085)
   at java.awt.Component.dispatchEventImpl(Component.java:4714)
   at java.awt.Container.dispatchEventImpl(Container.java:2143)
   at java.awt.Component.dispatchEvent(Component.java:4544)
   at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
   at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
   at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
   at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
   at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
   at java.awt.Component.dispatchEventImpl(Component.java:4586)
   at java.awt.Container.dispatchEventImpl(Container.java:2143)
   at java.awt.Window.dispatchEventImpl(Window.java:2478)
   at java.awt.Component.dispatchEvent(Component.java:4544)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
`
BTW, the error shows up for the card Divination, which I had just converted from keyword to AB_Draw. Note that this card is not targeted. This is what the card now looks like on my local copy:

Code: Select all
Name:Divination
ManaCost:2 U
Types:Sorcery
Text:no text
A:SP$Draw | Cost$ 2 U | NumCards$ 2 | SpellDescription$ Draw two cards.
SVar:Rarity:Common
SVar:Picture:http://www.wizards.com/global/images/magic/general/divination.jpg
End
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: AF_ZoneAffecting.drawCanPlayAI()

Postby friarsol » 19 Nov 2010, 18:03

Ah yep. I got it. The null check needs to be on the outside.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: AF_ZoneAffecting.drawCanPlayAI()

Postby Chris H. » 19 Nov 2010, 18:11

friarsol wrote:Ah yep. I got it. The null check needs to be on the outside.
`
Thank you. :D
`
I added in my code and re-tested and it works. I will merge this addition in after the current build error is taken care of.

Code: Select all
    public static boolean drawTargetAI(AbilityFactory af) {
        Target tgt = af.getAbTgt();
        HashMap<String,String> params = af.getMapParams();
       
        int computerHandSize = AllZoneUtil.getCardsInZone(Constant.Zone.Hand, AllZone.ComputerPlayer).size();
        int humanLibrarySize = AllZoneUtil.getCardsInZone(Constant.Zone.Library, AllZone.HumanPlayer).size();
        int computerLibrarySize = AllZoneUtil.getCardsInZone(Constant.Zone.Library, AllZone.ComputerPlayer).size();
        int computerMaxHandSize = AllZone.ComputerPlayer.getMaxHandSize();
       
        // todo: handle deciding what X would be around here for Braingeyser type cards   
        int numCards = 1;
        if (params.containsKey("NumCards"))
            numCards = Integer.parseInt(params.get("NumCards"));
       
        if (tgt != null) {
            // ability is targeted
            tgt.resetTargets();
           
            if (!AllZone.HumanPlayer.cantLose() && numCards >= humanLibrarySize) {
                // Deck the Human? DO IT!
                tgt.addTarget(AllZone.HumanPlayer);
                return true;
            }
           
            if (numCards >= computerLibrarySize) {
                // Don't deck your self
                return false;
            }
           
            if (computerHandSize + numCards > computerMaxHandSize) {
                // Don't draw too many cards and then risk discarding cards at EOT
                return false;
            }
           
            tgt.addTarget(AllZone.ComputerPlayer);
        }
        else {
            // ability is not targeted
            if (numCards >= computerLibrarySize) {
                // Don't deck yourself
                return false;
            }
            if (computerHandSize + numCards > computerMaxHandSize) {
                // Don't draw too many cards and then risk discarding cards at EOT
                return false;
            }
        }
        return true;
    }// drawTargetAI()
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 3 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 3 guests

Login Form