It is currently 04 Sep 2025, 10:38
   
Text Size

Beached As - fixed performance issues with Wonder etc...

Post MTG Forge Related Programming Questions Here

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

Beached As - fixed performance issues with Wonder etc...

Postby mtgrares » 02 Jul 2010, 16:05

How did you fix the problem? Feel free to copy and paste your code here. It seems like I coded Wonder eons ago. :D
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Beached As - fixed performance issues with Wonder etc...

Postby Beached As » 06 Jul 2010, 12:04

mtgrares wrote:How did you fix the problem? Feel free to copy and paste your code here. It seems like I coded Wonder eons ago. :D
Previously the code for the incarnations (e.g. Wonder) removed the keyword from all creatures effected by Wonder and then added the keyword back to them whenever the state effects are checked. The problem is however, that state effects are checked VERY often (you can confirm this by adding a message popup in any active state effect). The new code only adds and removes keywords from single creatures as they enter or leave the controller's play zone.

Old Code for Wonder:

Code: Select all

   public static Command Wonder                      = new Command() {
      private static final long serialVersionUID = 8346741995447241353L;

      CardList                  old              = new CardList();

      public void execute() {
         // reset creatures
         removeFlying(old);

         if(isInGrave(Constant.Player.Computer)) addFlying(Constant.Player.Computer);

         if(isInGrave(Constant.Player.Human)) addFlying(Constant.Player.Human);
      }// execute()

      void addFlying(String player) {
         PlayerZone play = AllZone.getZone(
               Constant.Zone.Play, player);
         CardList list = new CardList(play.getCards());
         list = list.getType("Creature");

         // add creatures to "old" or previous list of creatures
         old.addAll(list.toArray());

         addFlying(list);
      }

      boolean isInGrave(String player) {
         PlayerZone grave = AllZone.getZone(
               Constant.Zone.Graveyard, player);
         CardList list = new CardList(grave.getCards());

         PlayerZone play = AllZone.getZone(
               Constant.Zone.Play, player);
         CardList lands = new CardList(play.getCards());
         lands = lands.getType("Island");


         if(!list.containsName("Wonder") || lands.size() == 0) return false;
         else return true;
      }

      void removeFlying(CardList list) {
         for(int i = 0; i < list.size(); i++)
            list.get(i).removeExtrinsicKeyword("Flying");
      }

      void addFlying(CardList list) {
         for(int i = 0; i < list.size(); i++)
            list.get(i).addExtrinsicKeyword("Flying");
      }
   }; // Wonder

New Code for Wonder:

Code: Select all

   public static Command Wonder                      = new Command() {
      private static final long serialVersionUID = -846723300545847505L;

      CardList                  old              = new CardList();
      CardList                  next             = new CardList();

      public void execute() {
         if(Phase.GameBegins == 1) {
         // reset creatures
         removeFlying(old);

         if(isInGrave(Constant.Player.Computer)) addFlying(Constant.Player.Computer);

         if(isInGrave(Constant.Player.Human)) addFlying(Constant.Player.Human);
         }
      }// execute()

      void addFlying(String player) {
         next.clear();
         PlayerZone play = AllZone.getZone(Constant.Zone.Play, player);
         CardList playlist = new CardList(play.getCards());
         playlist = playlist.getType("Creature");
         for(int i = 0; i < playlist.size(); i++) {
            if(!old.contains(playlist.get(i))) next.add(playlist.get(i));
         }
         // add creatures to "old" or previous list of creatures
         
         
         addFlying(next);
      }

      boolean isInGrave(String player) {
         PlayerZone grave = AllZone.getZone(
               Constant.Zone.Graveyard, player);
         CardList list = new CardList(grave.getCards());

         PlayerZone play = AllZone.getZone(
               Constant.Zone.Play, player);
         CardList lands = new CardList(play.getCards());
         lands = lands.getType("Island");


         if(!list.containsName("Wonder") || lands.size() == 0) return false;
         else return true;
      }

      void removeFlying(CardList list) {
           CardList List_Copy = new CardList();
           List_Copy.add(list);
         for(int i = 0; i < List_Copy.size(); i++) {
            Card c = List_Copy.get(i);
            if(!isInGrave(c.getController()) && old.contains(c)) {
               List_Copy.get(i).removeExtrinsicKeyword("Flying");
               old.remove(c);
            }
      }
      }

      void addFlying(CardList list) {
         int Count = list.size();
         for(int i = 0; i < Count; i++) {
            list.get(i).addExtrinsicKeyword("Flying");
            old.add(list.get(i));
         }
      }
   }; // Wonder

This new method can also be applied to power/toughness bonuses and i've used this method to code Coat of Arms
Beached As
Programmer
 
Posts: 110
Joined: 23 Feb 2010, 07:48
Has thanked: 0 time
Been thanked: 0 time

Re: Beached As - fixed performance issues with Wonder etc...

Postby mtgrares » 08 Jul 2010, 14:26

Previously the code for the incarnations (e.g. Wonder) removed the keyword from all creatures effected by Wonder and then added the keyword back to them whenever the state effects are checked.
Yeah, that was my code. I didn't know how to do it any better. Thanks for the update, no one likes it when Forge slows to a crawl.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Beached As - fixed performance issues with Wonder etc...

Postby juzamjedi » 08 Jul 2010, 14:42

This is pretty awesome - I liked the incarnations, but previously they made the game way too slow for my liking. I will have to try them again in draft.
juzamjedi
Tester
 
Posts: 575
Joined: 13 Nov 2008, 08:35
Has thanked: 6 times
Been thanked: 8 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 66 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 66 users online :: 0 registered, 0 hidden and 66 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 66 guests

Login Form