The game Waving Hands is somewhere between a pen-and-paper Magic: the Gathering and a very elaborate Rock Paper Scissors. Each turn you write down one of eight gestures for each hand:
There are few important rules that take precedence over the rest:
- If both hands gesture
Pyou automatically surrender. (This is a simplification, but we'll go with that.)
- Only one hand at a time can gesture
A series of gestures performed by the same hand can cast a spell, where each spell is tied to one particular sequence. These sequences can overlap, but each gesture can only be used as the final gesture of a single spell (so you can create up to two spells in a single turn). Some spells require a gesture to be made with both hands simultaneously.
Your task is, given a list of gestures for each hand, to determine which spells could be cast in the current turn. For each hand, the last letter in the list represents the gesture chosen for the current turn.
Here is the list of gesture sequences. Upper case letters refer to a gesture performed by a single hand, lower case letters refer to a gesture performed with both hands.
B Stab cDPW Dispel magic cSWWS Summon elemental cw Magic mirror DFFDD Lightning bolt DFPW Cure heavy wounds DFW Cure light wounds DPP Amnesia DSF Confusion DSFFFc Disease DWFFd Blindness DWSSSP Delayed effect DWWFWc Raise dead DWWFWD Poison FFF Paralysis FPSFW Summon troll FSSDD Fireball P Shield p Surrender PDWP Remove enchantment PPws Invisibility PSDD Charm monster PSDF Charm person PSFW Summon ogre PWPFSSSD Finger of death PWPWWc Haste SD Missile SFW Summon goblin SPF Antispell SPFPSDW Permanency SPPc Time stop SSFP Resist cold SWD Fear SWWc Fire storm WDDc Lightning bolt WFP Cause light wounds WFPSFW Summon giant WPFD Cause heavy wounds WPP Counterspell WSSc Ice storm WWFP Resist heat WWP Protection from evil WWS Counterspell
Lightning bolt and
Counterspell have two different sequences each.
You may write a program or function, taking input in any convenient list or string format, via STDIN, command-line argument or function argument, as long as it's not pre-processed. You may output pairs of spells via return value or by printing to STDOUT. Again, you may use any convenient list or string format, as long as the output is unambiguous.
You may assume that the sequences for left and right hand are the same length, and that they are valid (in particular,
B will never be performed by two hands at the same time). Note that the input will only contain upper case letters. Lower case letters are only used in the above list to indicate that both hands need to perform the same (upper-case) gesture.
For spells which end in a two-hand gesture you should just output a single spell. If one hand cannot perform a spell, this needs to be indicated by a string containing only a hyphen,
This is code golf, so the shortest answer (in bytes) wins.
Each example consists of three lines: the left hand sequence, the right hand sequence (both input; the right-most gesture is the most recent one), and the list of all possible spell combinations (the output).
WFP WWS [["Cause light wounds","Counterspell"],["Shield","Counterspell"]] SD BB [["Missile","Stab"]] WWP WPP [["Surrender"]] DFW CCW [["Cure light wounds","-"]] FFW WWF [["-","-"]] DCW CCW [["Magic mirror"]] WFPSFW PPDDPP [["Summon goblin","Shield"],["Summon ogre","Shield"],["Summon troll","Shield"], ["Summon giant","Shield"],["Summon goblin","Amnesia"],["Summon ogre","Amnesia"], ["Summon troll","Amnesia"],["Summon giant","Amnesia"]] BSWWS CSWWS [["Counterspell","Counterspell"]] CSWWS CSWWS [["Counterspell","Counterspell"],["Counterspell","Summon elemental"], ["Summon elemental","Counterspell"],["Summon elemental","Summon elemental"]] PWPWWC BBSPPC [["Haste"],["Time stop"]]