Combat Refactoring
Posted: 18 Oct 2014, 09:01
by elcnesh
As I mentioned, I've been working on constructing an algorithm to determine a legal set of attackers, taking into account all restrictions and requirements (including those of cards we currently don't have implemented, like Viashino Bey). After messing around with code for weeks, I decided it'd be better to just put the entire algorithm in words first, discuss it until we get something that works, and implement that. So, I've put together a Google Docs document detailing the algorithm I've come up with so far: https://docs.google.com/document/d/1XPZdVWQptA-vTnsFQU-IohfvAOT4z3g1RPc3sk4xgBE/edit?usp=sharing
Not everything works completely, as annotated in red, but I think the general structure should be able to cover that as well. The restrictions and requirements mentioned cover all cards ever printed as far as I know. I do want it to work with all the cards, because otherwise we might have to go back and restructure it again later. For the obvious cases I've also put some O-notation running times next to them.
Please feel free to comment, either here or directly in the document (it should be open for comments), about what you think about the structure, specific cases, things that might not work in certain corner cases, missing cards, etc. Please keep in mind that this hasn't been implemented, let alone tested.
Reference
Not everything works completely, as annotated in red, but I think the general structure should be able to cover that as well. The restrictions and requirements mentioned cover all cards ever printed as far as I know. I do want it to work with all the cards, because otherwise we might have to go back and restructure it again later. For the obvious cases I've also put some O-notation running times next to them.
Please feel free to comment, either here or directly in the document (it should be open for comments), about what you think about the structure, specific cases, things that might not work in certain corner cases, missing cards, etc. Please keep in mind that this hasn't been implemented, let alone tested.
Reference
- Master Attack List | Open
- Attack requirements:
Attacks this/each combat if able: appears on Hellraiser Goblin, Illusionist's Gambit, Marauding Maulhorn and Zurgo Helmsmasher. Creates one general requirement for the creature to attack.
Attacks this/each turn if able: common effect (eg. Juggernaut). Creates one general requirement for the creature to attack unless the creature was already declared as an attacker earlier this turn.
Attacks <defender> this/each combat if able: appears on Ruhan of the Fomori and scheme cards Rotted Ones, Lay Siege and The Dead Shall Serve. Creates a requirement for the creature to attack a specific defender.
Attacks <defender> this/each turn if able: appears on Alluring Siren, Gideon Jura and Taunt (I presume) and scheme card My Crushing Masterstroke. Creates a requirement for the creature to attack a specific defender unless it already attacked that defender earlier this turn.
Attacks or blocks this combat if able: appears on Boros Battleshaper. Creates a general requirement for the creature to attack. In case the creature attacks and then is stolen by the defender, it would no longer be required to block as the requirement was already fulfilled, but for purpose of attacking, it behaves exactly like "Attacks each/this combat if able."
Cogwork Tracker: Creates a requirement for the creature to attack any player from a defined set of players, if that set is non-empty.
Ekundu Cyclops: Creates a requirement on itself that is satisfied if either Ekundu Cyclops attacks or if NO creatures attack. It's not satisfied if there's a non-empty set of attackers that doesn't include Ekundu Cyclops. If Ekundu Cyclops is generally incapable of attacking, the requirement should not be created (otherwise strange situations might result).
Magnetic Web: Creates a requirement on each creature with at least one magnet counter that is satisfied if either that creature attacks or if NO creatures with at least one magnet counter attack. If some creatures with magnet counters attack and some don't, the requirements for those not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.
Viashino Bey: Creates a requirement on each creature that is satisfied if either that creature attacks or if Viashino Bey does NOT attack. If Viashino Bey attacks, the requirements for creatures that are not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.
War's Toll: Creates a requirement on each creature controlled by the active opponent(s) that is satisfied if either that creature attacks or if NO creatures controlled by that opponent attack. If some opponent's creatures attack and some don't, the requirements for those not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.
Individual attack restrictions:
Can't attack: common effect. Creature can't be declared as attacker at all. Creatures with defender belong here unless they are able to ignore defender (from Animate Wall, Rolling Stones, Wakestone Gargoyle, Warmonger's Chariot or from innate abilities of Colossus of Akros, Dark Maze, Mirror Wall, Mobile Fort, Nivix Cyclops, Ogre Jailbreaker, Pillar of War, Prison Barricade, Returned Phalanx, Slithering Shade, Spire Serpent, Vodalian War Machine, Walking Wall or Wall of Wonder). Detained creatures belong here. Creatures with summoning sickness belong here unless they have haste or are capable of attacking as though they had haste (Chaos Lord/Instill Energy). Conditional effects like Blind-Spot Giant belong here if the condition is not dependent on other declarations OR on the defender (they are simply checked once and then it's decided whether they apply or not).
Can't attack <defender>: appears on Arboria, Blazing Archon, Chronomantic Escape, Elephant Grass, Form of the Dragon, Illusionist's Gambit, Island Sanctuary, Mystic Barrier, Reverence, Teferi's Moat, Vow of Duty, Vow of Flight, Vow of Lightning, Vow of Malice, Vow of Wildness, Web of Inertia and plane card Agyrem. Removes specific defender(s) from the set of defenders a creature can attack. Creatures with defender-dependent attack condition like Armored Galleon belong here; if the condition is not satisfied for a particular player, the creature can't attack that player or any of his planeswalkers. In case of 2HG (not implemented yet), a team can be attacked if any player on the team satisfies a "can't attack unless" condition, but not if any player satisfies a "can't attack if" condition; I presume that an individual player must still satisfy the condition if a planeswalker is attacked.
"Can't attack unless" defender-dependent conditions: Armored Galleon, Bog Serpent, Chained Throatseeker, Dandan, Deep-Sea Serpent, Dreamwinder, Ethereal Whiskergill, Floodchaser, Giant Shark, Goblin Goon, Goblin Rock Sled, Godhunter Octopus, Gorilla Pack, Hammerhead Shark, Island Fish Jasconius, Kukemssa Serpent, Manta Ray, Marjhan, Merchant Ship, Mogg Toady, Monstrous Hound, Pirate Ship, Red Cliffs Armada, Ronom Serpent, Sea Monster, Sea Serpent, Sealock Monster, Serpent of the Endless Sea, Slipstream Eel, Slipstream Serpent, Steam Frigate, Veiled Serpent, Vodalian Knights, Vodalian Serpent, Whimwader, Wu Warship, Zhou Yu, Chief Commander
"Can't attack if" defender-dependent conditions: Branded Brawlers, Goblin Mutant, Mogg Jailer, Orgg, Veteran Brawlers
Predicate restrictions:
"Can't attack alone": appears on Ember Beast, Jackal Familiar, Loyal Pegasus, Mogg Flunkies and Sightless Brawler. Attack sets which contain only this creature are impossible. If combined with "Can only attack alone", the creature can't attack at all.
"Can only attack alone": appears on Errantry and Master of Cruelties. Attack sets which contain this creature and any other creature are impossible. If combined with "Can't attack alone" or with Okk, Orcish Conscripts or Scarred Puma, the creature can't attack at all.
Okk: Attack sets where Okk is the creature with the highest power or one of the creatures with the highest power are impossible. If combined with "Can only attack alone", Okk can't attack at all.
Orcish Conscripts: Attack sets which contain only Orcish Conscripts or Orcish Conscripts and exactly one other creature are impossible. If combined with "Can only attack alone", Orcish Conscripts can't attack at all.
Scarred Puma: Attack sets that include Scarred Puma, but no other creature of specified color(s) (which can be modified through sleight effects or Swirl the Mists) are impossible. Gatherer rulings indicate that Scarred Puma can never satisfy its own condition even if it has the required color(s). If combined with "Can only attack alone", Scarred Puma can't attack at all.
Global attack limiters:
Astral Arena - lowers global maximum of attackers to 1 if higher.
Caverns of Despair - lowers global maximum of attackers to 2 if higher.
Crawlspace - lowers maximum amount of creatures attacking Crawlspace's controller to 2.
Dueling Grounds - lowers maximum amount of attackers to 1 if higher. In addition, if this is not the first combat of the turn and any creatures have been declared as atackers on previous combats, no other creature is permitted to attack. (Not 100% sure what happens if multiple creatures attack, then Dueling Grounds enters the battlefield, and there's another combat, but I think you could attack with one of the creatures that attacked previously.)
Silent Arbiter - lowers global maximum of attackers to 1 if higher.
Attack costs (total cost of is still functionally distinct from no cost as the creature is still unaffected by attack requirements since you may choose to "not pay" ):
Brainwash - adds cost of for the creature to attack.
Collective Restraint - adds cost of equal to number of basic land types controlled by Collective Restraint's controller for the creature to attack the controller of Collective Restraint.
Cowed by Wisdom - adds cost of mana equal to amount of cards in hand of Cowed by Wisdom's controller for the creature to attack.
Elephant Grass - adds cost of for the creature to attack the controller of Elephant Grass.
Exalted Dragon - adds cost of "sacrifice a land" for Exalted Dragon to attack.
Flooded Woodlands - adds cost of "sacrifice a land" for the creature to attack.
Floodtide Serpent - adds cost of "return an enchantment you control to its owner's hand" for Floodtide Serpent to attack.
Ghostly Prison - adds cost of for the creature to attack the controller of Ghostly Prison.
Hollow Warrior - adds cost "tap an untapped creature you control not declared as an attacking or blocking creature this combat" for Hollow Warrior to attack.
Koskun Falls - adds cost of for the creature to attack the controller of Koskun Falls.
Leviathan - adds cost of "sacrifice two Islands" (can be hacked) for Leviathan to attack.
Myr Prototype - adds cost of equal to number of +1/+1 counters on Myr Prototype for Myr Prototype to attack.
Norn's Annex - adds cost of {P/W} for the creature to attack the controller of Norn's Annex or one of his or her planeswalkers.
Oppressive Rays - adds cost of for the creature to attack.
Phyrexian Marauder - adds cost of equal to number of +1/+1 counters on Phyrexian Marauder for Phyrexian Marauder to attack.
Propaganda - adds cost of for the creature to attack the controller of Propaganda.
Reclamation - adds cost of "sacrifice a land" for the creature to attack.
Sphere of Safety - adds cost of equal to number of enchantments controlled by Sphere of Safety's controller for the creature to attack the controller of Sphere of Safety or one of his or her planeswalkers.
War Tax - adds cost of for the creature to attack.
Whipgrass Entangler - adds cost of equal to the number of Cleric permanents on the battlefield (can be artifically evolved) for the creature to attack.
Windborn Muse - adds cost of for the creature to attack the controller of Windborn Muse.
- Master Block List | Open
- Blocking algorithm is more complicated than attacking one because some blockers can block multiple attackers.
The basic thing would be to determine, for each blocker, a set of creatures it could block (analogical to set of defenders an attacker could attack). Each blocker has a "blocking limit" which sets maximum amount of creatures it can block (can't be more than all possible attackers it could block). If a blocker has no limit on blocking, its limit is set as the number of attackers it can block.
Creatures that are tapped can't block unless specifically allowed to by Masako the Humorless. This list won't attempt to show various evasion abilities, blocking limitations (including "can't block") or "evasion ignoring" like Wall of Diffusion or Staff of the Ages; it will be more concerned with predicate restrictions and requirements. This also includes attacker-dependent restrictions like Goblin Goon; those simply remove possible blocking assignments depending on attacking creature's controller (or maybe they make creature able or unable to block based on stats of all attacking players? But that's only relevant in 2HG anyway).
As for banding, that seems to not come into effect during blocking declarations. Creature that blocks one member of the band will automatically become a blocker of the others after the declaration is complete. This presumably means that these automatic blocks can't be used to fulfill requirements.
Blocking requirements:
<creature1> must block <creature2> if able: This is the basic requirement that occurs in many forms, from focused provoke ability to global Lure effects or even something like Blaze of Glory. If creature1 can conceivably block creature2, it gets a requirement to do so.
Effects that create temporary effects of this kind can set them to last for a turn (Auriok Siege Sled) or for a combat (Avalanche Tusker). Presumably, if the effect lasts for the turn, it only needs to be satisfied once. Not sure what happens when effect is created AFTER it was already satisfied. (Not sure what happens in the attacking case here, either.)
<creature> blocks each/this turn if able: appears on Courtly Provocateur, Culling Mark, Grand Melee, Invasion Plans, Mark for Death, Nacatl Hunt-Pride, Predatory Rampage, Provoke, Razorgrass Screen, Spirespine and Watchdog. Creates a general requirement for the creature to block unless it was already declared as a blocker this turn. Ignored if the creature can't block anything.
<creature> must be blocked each/this turn if able: appears on Deadly Allure, Enlarge, Goblin Fire Fiend, Goldenhide Ox, Hinterland Hermit/Hinterland Scourge, Inescapable Brute, Irresistible Prey, Loathsome Catoblepas, Satyr Piper and vanguard card Sisters of Stone Death Avatar. Creates a general requirement for any creature to block this creature unless it was already blocked earlier this turn. Ignored if nothing can block it.
Boros Battleshaper - creates a general requirement for the creature to block, unless it was somehow declared as an attacker this combat. Ignored if the creature can't block anything.
Nacatl War-Pride - creates a requirement for Nacatl War-Pride which is satisfied only if Nacatl War-Pride is blocked by exactly one creature. If the creature is not blocked or if it's blocked by two or more creatures, the requirement is not satisfied. If nothing can block Nacatl War-Pride, the requirement is ignored. The requirement is also ignored if Nacatl War-Pride combines with "Can't be blocked except by two or more creatures" or "Can't be blocked except by three or more creatures".
Predicate restrictions:
On attackers:
Can't be blocked by more than one creature: Appears on Alpha Authority, Familiar Ground, Huang Zhong, Shu General, Ironhoof Ox, Krosan Vorine, Norwood Riders, Stalking Tiger, Vorrac Battlehorns and Yuan Shao, the Indecisive. Blocking sets where a creature with this power is blocked by two or more creatures are impossible. If combined with "Can't be blocked except by two or more creatures" or "Can't be blocked except by three or more creatures", it's treated as unblockable.
Can't be blocked except by two or more creatures: Appears on Belligerent Sliver, Caterwauling Boggart, Demoralize, Goblin War Drums, Gorilla War Cry, Gruul Nodorog, Gruul War Chant, Horde of Boggarts, Imposing Visage, Iroas, God of Victory, Kederekt Creeper, Kruin Outlaw/Terror of Kruin Pass, Madcap Skills, Purphoros's Emissary, Pyreheart Wolf, Ripscale Predator, Searing Spear Askari, Stormblood Berserker, Summit Apes, Two-Headed Dragon, Two-Headed Sliver, Viashino Runner, Vine Kami, Wind Spirit and vanguard card Two-Headed Giant of Foriys Avatar. Blocking sets where a creature with this power is blocked by exactly one creature are impossible. If only one creature could block this creature, it's treated as unblockable. If combined with "Can't be blocked by more than one creature", it's treated as unblockable.
Can't be blocked except by three or more creatures: Appears on Gorilla Berserkers, Guile, Pathrazer of Ulamog, Phyrexian Colossus and Underworld Cerberus. Blocking sets where a creature with this power is blocked by exactly one creature or exactly two creatures are impossible. If only one or two creatures could block this creature, it's treated as unblockable. If combined with "Can't be blocked by more than one creature", it's treated as unblockable.
Tromokratis - If defending player controls n creatures, where n >= 2, blocking sets where Tromokratis is blocked by 1 - (n-1) creatures are impossible. If defending player controls at least 1 creature that is not able to block Tromokratis for whatever reason, it's treated as unblockable. If combined with "Can't be blocked by more than one creature", Tromokratis is treated as unblockable if defending player controls at least 2 creatures.
On blockers:
Can't block alone: Appears on Ember Beast, Jackal Familiar, Loyal Pegasus and Mogg Flunkies. Blocking sets where only this creature blocks are impossible.
Okk - Blocking sets where Okk is the creature with the highest power or one of the creatures with the highest power are impossible.
Orcish Conscripts - Blocking sets which contain only Orcish Conscripts or Orcish Conscripts and exactly one other creature are impossible.
Global limitations:
Astral Arena - sets global maximum of blockers to 1 if higher.
Caverns of Despair - sets global maximum of blockers to 2 if higher.
Dueling Grounds - lowers global maximum of blockers to 1 if higher. In addition, if this is not the first combat of the turn and any creatures have been declared as blockers on previous combats, no other creature is permitted to block. (Similar caveat as in the attack scenario.)
Silent Arbiter - sets global maximum of blockers to 1 if higher.
Blocking costs (similar caveat about cost as in attacking case; in addition, it seems that it's generally only required to pay for the blocker once, even if it blocks multiple attackers):
Awesome Presence - adds cost of for the creature to block the creature enchanted with Awesome Presence. (Payment is of course valid only for one creature with Awesome Presence.)
Cowed by Wisdom - adds cost of equal to amount of cards in hand of Cowed by Wisdom's controller for the creature to block.
Heat Wave - adds cost of "1 life" for the creature to block creatures controlled by the controller of Heat Wave.
Hipparion - adds cost of for Hipparion to block creatures with power 3 or greater.
Hollow Warrior - adds cost "tap an untapped creature you control not declared as an attacking or blocking creature this combat" for Hollow Warrior to block.
Myr Prototype - adds cost of equal to number of +1/+1 counters on Myr Prototype for Myr Prototype to block.
Oppressive Rays - adds cost of for the creature to block.
War Cadence - adds cost of for the creature to block.
Whipgrass Entangler - adds cost of equal to the number of Cleric permanents on the battlefield (can be artifically evolved) for the creature to block.