Computer is thinking
 Posted: 23 Sep 2009, 21:25
Posted: 23 Sep 2009, 21:25I got the "Computer is thinking" bug for the first time. In the console, there appears an Exception:
the real problem is bugs in the card code. these cause the exceptions in the first place.
In my case, the computer wanted to activate a Lifespark Spellbomb (you can tell from the line in CardFactory):
fixed (& optimized; needs iterable card list) code:
			- Code: Select all
- Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
 at java.util.ArrayList.RangeCheck(ArrayList.java:547)
 at java.util.ArrayList.get(ArrayList.java:322)
 at CardList.getCard(CardList.java:72)
 at CardList.get(CardList.java:73)
 at CardFactory$808.canPlayAI(CardFactory.java:25135)
 at ComputerAI_General.getMain2(ComputerAI_General.java:217)
 at ComputerAI_General.playCards(ComputerAI_General.java:48)
 at ComputerAI_General.main2(ComputerAI_General.java:43)
 at ComputerAI_Input.think(ComputerAI_Input.java:45)
 at ComputerAI_Input.showMessage(ComputerAI_Input.java:25)
 at GuiInput.setInput(GuiInput.java:27)
 at GuiInput.update(GuiInput.java:21)
 at java.util.Observable.notifyObservers(Observable.java:142)
 at java.util.Observable.notifyObservers(Observable.java:98)
 at MyObservable.updateObservers(MyObservable.java:12)
 at Phase.nextPhase(Phase.java:109)
 at GuiDisplay3$25.actionPerformed(GuiDisplay3.java:772)
 at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
 at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
 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:1636)
 at javax.swing.JComponent.processKeyBinding(JComponent.java:2849)
 at javax.swing.JComponent.processKeyBindings(JComponent.java:2884)
 at javax.swing.JComponent.processKeyEvent(JComponent.java:2812)
 at java.awt.Component.processEvent(Component.java:5993)
 at java.awt.Container.processEvent(Container.java:2041)
 at java.awt.Component.dispatchEventImpl(Component.java:4583)
 at java.awt.Container.dispatchEventImpl(Container.java:2099)
 at java.awt.Component.dispatchEvent(Component.java:4413)
 at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
 at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:704)
 at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:969)
 at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:841)
 at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:668)
 at java.awt.Component.dispatchEventImpl(Component.java:4455)
 at java.awt.Container.dispatchEventImpl(Container.java:2099)
 at java.awt.Window.dispatchEventImpl(Window.java:2475)
 at java.awt.Component.dispatchEvent(Component.java:4413)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
the real problem is bugs in the card code. these cause the exceptions in the first place.
In my case, the computer wanted to activate a Lifespark Spellbomb (you can tell from the line in CardFactory):
- Code: Select all
- public boolean canPlayAI() {
 CardList land = new CardList(AllZone.Computer_Play.getCards());
 land = land.getType("Land");
 CardList basic = land.getType("Basic");
 if(basic.size() < 3) return false;
 Card[] basic_1 = basic.toArray();
 for(Card var:basic_1)
 if(var.isTapped()) basic.remove(var);
 basic.shuffle();
 if(basic.get(0) != null) {
 setTargetCard(basic.get(0));
 return true;
 }
 return false;
 }//canPlayAI()
fixed (& optimized; needs iterable card list) code:
- Code: Select all
- public boolean canPlayAI() {
 CardList land = new CardList(AllZone.Computer_Play.getCards());
 land = land.getType("Land").getType("Basic");
 for(Card var:land)
 if(var.isTapped()) land.remove(var);
 if(land.size() == 0 || land.get(0) == null) return false;
 basic.shuffle();
 setTargetCard(land.get(0));
 return true;
 }//canPlayAI()
 
 