Goal:
Given two creatures with optional combat abilities, return unique but consistent values that represent which creatures died, if any.
Input:
#Longest form:
[[P,T, "<abilities>"], [P,T, "<abilities>"]]
#Shortest form:
[[P,T], [P,T]]
Each creature will be given in the form of [P,T,"<abilities>"]
. It will be in the form [P,T]
, [P,T,""]
, or [P,T,0]
if it has no abilities, your choice on form. P is an integer >=0, T is an integer >=1. <abilities>
is a subset of "DFI"
, or can be represented via a single number/bitstring if you wish. Order of the flags is also up to you.
Combat Mechanics:
Each creature has two stats, Power and Toughness in that order, and optional abilities. A creature's power is >=0. A creature's Toughness is >=1.
Each creature will simultaneously do damage equal to its power to the opposing creature (unless one has first-strike). If the value is greater than or equal to the opponent's toughness, it will die (unless it is indestructible).
Example: Alice is a 2/2
, Bob is a 3/4
, both with no abilities. Alice will do 2 damage to Bob and take 3 damage in return. Alice's toughness is 2 so it will die, Bob's toughness is 4 so it will live.
There are only 3 optional abilities we will consider for this (although there are more in the game). These will be one character flags:
- [D]eathtouch: Any amount of damage (X>0) is considered lethal.
- [F]irst Strike: Will deal its damage first, able to kill the other creature before it can attack back. If both creatures have First Strike, Resolve combat as normal.
- [I]ndestructible: No amount of damage is considered lethal, including Deathtouch.
Output:
Any consistent value for each of the following four cases. State the four values in your answer, please. Example return value in parens:
- Neither creature died (0)
- 1st creature died (1)
- 2nd creature died (2)
- Both creatures died (3)
Rules:
- Input is guaranteed to have two correctly formatted creatures.
- If you are using characters for abilities, you can assume they're ordered how you want but post the order used if relevant.
- If you are using a number/bitstring for abilities, post what encoding you're using. e.g.:
111
isD/F/I
,7
isD/F/I
, etc. - If a creature has no abilities, It can also be taken as
[P,T, ""]
or number equivalent - Standard Loopholes Forbidden
- This is code-golf so shortest code wins.
Examples:
Input: [[2,2], [1,1]]
Output: 2nd Dies
Input: [[0,2], [0,1]] #0/2 vs 0/1
Output: Neither Die
Input: [[2,1], [2,1]] #2/1 vs 2/1
Output: Both Die
Input: [[1,1, "D"], [2,2]] #1/1 Deathtoucher vs 2/2
Output: Both Die
Input: [[2,2], [0,1, "D"]] #2/2 vs 0/1 Deathtoucher
Output: 2nd Dies
Input: [[2,2], [1,1, "DF"]] #2/2 vs 1/1 Deathtouch First-striker
Output: 1st Dies
Input: [[0,2, "D"], [0,1, "DF"]] #0/2 Deathtoucher vs 0/1 Deathtouch First-striker
Output: Neither Die
Input: [[2,2], [2,2, "F"]] #2/2 vs 2/2 First-striker
Output: 1st Dies
Input: [[2,2, "I"], [1,1, "DF"]] #2/2 Indestructible vs 1/1 Deathtouch First-striker
Output: 2nd Dies
Input: [[9999,9999], [1,1, "I"]] #9999/9999 vs 1/1 Indestructible
Output: Neither Die
Input: [[2,2, "F"], [1,1, "F"]] #2/2 First-Striker vs 1/1 First-Striker
Output: 2nd Dies
#9/9 Deathtouch, Indestructible First-Striker vs 9/9 Deathtouch, Indestructible First-Striker
Input: [[9,9, "DFI"], [9,9, "DFI"]]
Output: Neither Die
D => 0, F => 1, I => 2
\$\endgroup\$