It is currently 07 Nov 2025, 04:15
   
Text Size

Coding question: formats and predicates

Post MTG Forge Related Programming Questions Here

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

Coding question: formats and predicates

Postby RumbleBBU » 21 Jan 2013, 06:56

This post is mostly for Max but others are welcome to chime in too...

I want to expand the possibilities of GameFormatQuest by allowing the inclusion of cubes in the format specification for extra flexiblity, to make it possible to make individual cards available in a Quest World when desired. While cubes wouldn't produce boosters (at least in the first version of the code), you could find cube-based cards in the shop or receive them as rare rewards.

However, I'm facing a slight technical difficulty. Since GameFormatQuest is now extending GameFormat, it does not contain any filter/predicated definitions anymore. So it seems that I would need to:

1) Add (partly redundant) filter code to the GameFormatQuest class and override the superclass (GameFormat). The problem: I don't think this would be practical without overriding a lot of other stuff as well, like the private predicates filterRules and filterPrinted. At which point one might wonder what's the point of extending the GameFormat class in the first place.

or

2) Add the whole cube stuff to the superclass GameFormat. This would be bad! The stuff I want to add would affect Quest mode only, I don't want to mess with the fundamental GameFormat class.

Is there a third, better option?
User avatar
RumbleBBU
 
Posts: 394
Joined: 18 Aug 2012, 04:24
Has thanked: 29 times
Been thanked: 66 times

Re: Coding question: formats and predicates

Postby Max mtg » 21 Jan 2013, 12:25

So it looks like you need a filter to get from CardDb.allCards only the ones allowed by cube.

You don't have to extend GameFormat. It was designed to encapsulate the common filters, like a dozen of sets allowed and a number of cards banned. Originally quest cardpools restrictions looked like that format but mutable - that's why i suggested to use it.

Your task of making a Predicate<CardPrinted> out of a cube is different, so a new wrapper class (if you need one) should be used. By the way, that kind of filtering (N string comparisons for each card in cube against M cards in database to get a random card from that pool) will be slow.

Upd:
So to achieve better speed, hold somewhere a list of cards allowed - that is make that predicate once, get the list and hold is somewhere in QuestData as a transient field. If you need the very cube serialized, ok let it be a list of strings (not cards or any other structure incapsulating that list)

Upd2:
All this means to say that predicates are not effective for filtering out cards that belong to a cube, GameFormat or its descendats are unsiutable to perform that task.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Coding question: formats and predicates

Postby RumbleBBU » 23 Jan 2013, 08:51

Thanks for the reply, Max. That's pretty much what I suspected. Basically too much work for it could achieve. Although I'm not particularly worried about the performance issues here since this would only get called when the match is over or the spell store is being restocked...but in any case, this is idea is not getting a high priority for me.
User avatar
RumbleBBU
 
Posts: 394
Joined: 18 Aug 2012, 04:24
Has thanked: 29 times
Been thanked: 66 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 91 guests

Main Menu

User Menu

Our Partners


Who is online

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

Login Form