Remix.run Logo
▲ rappatic 3 days ago

I imagine we can do better than a flat array to represent the permanents on the battlefield. Lots of cards filter permanents by type, mana cost, etc. Building a consideration for this into the data structure is a natural idea.

▲olivergregory 2 days ago | parent [-]

Every card, permanent, spell, etc. is an object in Magic. So I’m using a set multimap, with the key being the zone the card is in. Those filters you mention are actually cheap until you get unrealistic numbers like those that let you win this turn or the next one. You could create an index of the mana cost, the types, but that ends up being over-engineered.

I’ve tested using an ECS just for handling the core of the objects, but that lead nowhere event though it seemed a good fit from some perspectives.

I’m not surprised that an array is actually efficient after trying so many implementations.

▲rappatic 2 days ago | parent [-]

I'm looking at the line:

> On turns 52, 54, and 56, I counted the Zombies at the start of the turn and timed the emblem when it resolved at the end. In one laptop replay those steps took 1.72, 7.78, and 35.15 seconds

I'm surprised it turns out that building a consideration for this into the data structure is a bad idea.

▲kyralis 5 hours ago | parent [-]

This was my thought. Maintaining indices into the existing objects based on their keywords as an optimization seems simple, since you only need to update the index when a new object enters play, and only for the keywords on that card; most of these will not change most of the time, and card lookups then hit the index instead.

Also, that's a bunch of transformations/allocations along the way for those lookups that can suddenly go away.

I'm not saying we can't get into absurd territory, but there's some pretty basic optimization to be done to at least push those numbers out further.