Shantae Dance Matching

8

1

In the original Shantae game, there are transformation dances that you have to input in time using the D-Pad, A, and B. If you complete a predefined sequence while dancing, you will transform into the corresponding form (or teleport or heal). Your task is to output the corresponding effect when given an input. The catch is that you may get extraneous dance moves in the input, both before and after, and there may not even be a dance in the input.

The Dances

Using UDLRAB for dance moves:

  • Monkey: DR
  • Elephant: DL
  • Spider: DA
  • Harpy: DB
  • Tinkerbat: DUU
  • Heal: DUA
  • Scuttle Town: DULR
  • Water Town: DURLAB
  • Oasis Town: DURRBA
  • Zombie Caravan: DULLBA
  • Bandit Town: DUBLBR

Coding

Input: a sequence of dance moves. This can contain Up, Down, Left, Right, B, A, and Wait values. Use any convenient encoding.

Output: a value corresponding to the first matching dance in the sequence or a distinct value if there is no match. You can encode this in any convenient way.

Examples

Using . for waiting:

  • DR → Monkey
  • UUU.DLUAB → Elephant
  • L.DDBALL → Harpy
  • LRLRDURURLABNo match
  • DUBLBR → Bandit Town
  • DURLBANo match
  • DDUDR → Monkey
  • RLABNo match
  • .DUUBBB → Tinkerbat
  • DADRDL → Spider
  • .DURRBADR → Oasis Town
  • DURR.BANo match

Other Rules/Notes

  • Standard rules on loopholes and IO methods apply
  • Describe your encoding for dance moves and matching dances.
  • There may be more than one dance in the input. If that is the case, match only the first one that appears in the input.
  • Waiting interrupts dances.

Beefster

Posted 2019-05-01T17:45:05.900

Reputation: 6 651

1Related – Beefster – 2019-05-01T17:45:17.533

Now testcase 4 ends in DURLAB, which is Water Town – Skidsdev – 2019-05-01T18:11:04.643

@Skidsdev. Good catch. I meant to make that a no match test case there. – Beefster – 2019-05-01T18:11:31.970

1You can encode this in any convenient way: may we return the matching sequence, e.g. "DURRBA" for Oasis Town? – Arnauld – 2019-05-01T18:39:52.867

@Arnauld I guess that works. – Beefster – 2019-05-01T18:46:56.543

1Random: Longish ago, using only 'input' and 'wait' (ie timed coin entries) the casinos (in a country that I won't mention and which you are unlikely to guess and which isn't my country)(connected to me only by "internet") had their slot machine software hacked at source such that a player could multiply their input pot by a largish number. They then played, won or lost and cashed out with far more than they had input. It was in due course discovered and fixed. I identified the method based on a general description of what was happening overall - supplied by a puzzled security investigator. – Russell McMahon – 2019-05-01T20:22:42.503

Answers

3

JavaScript (ES6),  92 88 61  59 bytes

Saved 2 bytes thanks to a suggestion from @tsh

Expects UdLRAB for the dance moves and . for waiting. Outputs either undefined if there's no match, or the sequence of the matching dance (e.g. dR for Monkey or dURLAB for Water Town).

s=>(/d([A-R]|U(U|A|LR|RLAB|RRBA|LLBA|BLBR))/.exec(s)||0)[0]

Try it online!

or Try it with enhanced output

Arnauld

Posted 2019-05-01T17:45:05.900

Reputation: 111 334

R|L|A|B -> [RLAB]? – tsh – 2019-05-02T04:44:38.503

@tsh Actually, d([A-R]|U...) is apparently fine since any convenient encoding may be used for the input as well. Thanks! – Arnauld – 2019-05-02T11:45:17.070

2

JavaScript (Node.js), 179 164 153 148 137 115 bytes

d=>{for(;d;d=d.slice(1))for(z of "R.L.A.B.UU.UA.ULR.URLAB.URRBA.ULLBA.UBLBR".split`.`)if(!d.search('D'+z))return z}

Try it online!

-11 bytes thanks to Arnauld's answer making me realize output can be simplified
-8 bytes thanks to flawr in chat helping me golf array empty checks
-12 bytes thanks to Shaggy

Takes input as a string in same formatting as OP test cases.

Outputs the matched dance string minus the leading D for a match, or undefined for no match.

The integer corresponds to the match's index in this array (0-indexed):

0  - Monkey: DR
1  - Elephant: DL
2  - Spider: DA
3  - Harpy: DB
4  - Tinkerbat: DUU
5  - Heal: DUA
6  - Scuttle Town: DULR
7  - Water Town: DURLAB
8  - Oasis Town: DURRBA
9  - Zombie Caravan: DULLBA
10 - Bandit Town: DUBLBR

Probably room for golfing, especially in compressing the dance move set.

Explanation

General approach

Iterate through the input string, removing the first character each time and checking if the resulting string starts with a valid dance string.

The whole thing is just a for loop inside a for loop, I'll break it down into 3 parts:
- Condition
- Inner Loop
- Outer Post

Condition

This is the termination condition for the outer loop, IE while this is true, keep looping.
Quite simple:

d

d is a string, in JS empty strings are falsey "d is not empty".

Inner Loop

This is the stuff that happens each loop:

for(z of "R.L.A.B.UU.UA.ULR.URLAB.URRBA.ULLBA.UBLBR".split`.`)

So first we define an array with:

"R.L.A.B.UU.UA.ULR.URLAB.URRBA.ULLBA.UBLBR".split`.`

This creates an array of all dance move strings, missing the D at the start of each of them (They all begin with D). We'll call this array x
There's probably significant golfing potential here.

We then iterate through each item in x (stored in z), and run the following:

if(!d.search('D'+z))return z

This uses d.search to return the index in the string of 'D'+z. If and only if d begins with 'D'+z, this will return 0, which is a falsey value in JS.
As such, !d.search will only be true when the string starts with 'D'+z.

Note: This is why we omit the Ds in x, as it saves us 10 bytes (1 per dance), and only costs us a single byte in this search

Then, if the search matches, we return z. This is the dance we've found, without the leading D.

If not, we keep looping.

Outer Post

This is stuff that happens at the end of each iteration of the outer loop:

d=d.slice(1)

Just remove the first character from d

No Match

If d becomes empty and no match has been found, the end of the function is reached. This implicitly returns undefined as per standard JavaScript behavior

Skidsdev

Posted 2019-05-01T17:45:05.900

Reputation: 9 656

@Shaggy I'd just made the substr -> slice change myself, and I keep forgetting that d is a string, not an array. Empty strings are falsey :P And good catch on the braces, I forgot about the whole 1 child statement thing – Skidsdev – 2019-05-01T20:12:51.450

@Shaggy ah nice! I assume d.search will return 0 if the search string is at the start of d, which is of course a falsey value – Skidsdev – 2019-05-01T20:25:19.213

Yep. It's kinda like indexOf but it supports RegEx, which is irrelevant here. – Shaggy – 2019-05-01T20:27:22.763

And of course it's also 1 byte shorter ;) – Skidsdev – 2019-05-01T20:29:05.587

82 bytes – Shaggy – 2019-05-01T20:56:19.997

@Shaggy Your version will return R for DLDR – Embodiment of Ignorance – 2019-05-01T22:10:22.493

@Shaggy that version seems to find the dance in the input string that is first in the dance array, not first in the input. – Skidsdev – 2019-05-02T12:53:58.483

@EmbodimentofIgnorance, ah, so it will. Try this instead. Can probably be golfed further.

– Shaggy – 2019-05-02T21:26:44.447

2

Retina, 53 43 42 37 bytes

0L`;\w|;:(:|A|LR|RLAB|RRBA|LLBA|BLBR)

Try it online!

Slightly deviates from the standard input and output to make use of ;: as DU respectively. Inspiration from tsh, saving 5 bytes.

Matches the first dance and outputs it, after seeing Arnauld's answer. Saved 10 bytes thanks to Neil suggesting using the list stage L and limiting the output to the first match. Saved one byte thanks to tsh shortening the regex.

The header and footer just allow for multiple inputs and making the output readable, respectively.

FryAmTheEggman

Posted 2019-05-01T17:45:05.900

Reputation: 16 206

43 bytes. Can be translated to Retina 0.8.2 by using 1! instead of 0L, but in that case the footer won't work (1M! will work even with the footer). – Neil – 2019-05-01T20:02:52.270

@Neil Thanks for the golf, I always forget about L. – FryAmTheEggman – 2019-05-01T20:21:54.923

Maybe R|L|A|B -> [RLAB]? – tsh – 2019-05-02T07:12:12.150

@tsh Thanks! That was a holdover from my previous approach and I never checked it. – FryAmTheEggman – 2019-05-02T16:52:01.160

One more step, what about D[RLAB]|DU(...) instead? – tsh – 2019-05-03T03:39:40.167

@tsh Good idea, but I noticed that abusing the input/output helps a bit more by letting me use \w instead. – FryAmTheEggman – 2019-05-03T03:52:56.617

1

Perl 5 -p, 47 bytes

/D([RLAB]|U(U|A|LR|LLBA|RLAB|RRBA|BLBR))/;$_=$&

Try it online!

Returns the dance's code (allowed as per @Arnauld's comment) or blank if no match.

Xcali

Posted 2019-05-01T17:45:05.900

Reputation: 7 671

1

Charcoal, 48 bytes

≔⌊E⁺D⪪”{➙∧⪫⁻Y⟧¹⊟AOP9GKπ⁸Pa↷VB”D⟦⌕⁺θιιLι⟧η✂θ§η⁰Ση

Try it online! Link is to verbose version of code. Explanation:

⁺D⪪”{➙∧⪫⁻Y⟧¹⊟AOP9GKπ⁸Pa↷VB”D

Split the compressed string RDLDADBDUUDUADULRDURLABDURRBADULLBADUBLBR (which contains all of the dances except for the leading D) on D, and then prefix the D back to each entry.

E...⟦⌕⁺θιιLι⟧

For each dance, concatenate it to the input and find the first position of the dance in the concatenation, plus also take the length of the dance. For dances that weren't found this means that the result will be the length of the input string instead of -1.

≔⌊...η

Take the minimum of those results, i.e. the position and length of the dance that appeared first.

✂θ§η⁰Ση

Extract that dance from the original string.

Neil

Posted 2019-05-01T17:45:05.900

Reputation: 95 035

1

Jelly, 33 28 bytes

“¡ịḟ½NỵC\HỤĊȷṗ~’b6ṣ0;€0ɓUwⱮM

Try it online!

Takes as input a list of integers representing the moves:

0 D
1 U
2 R
3 B
4 L
5 A
6 .

Returns a wrapped integer for the answer, or a list of all these integers for no match:

1 Monkey
2 Harpy
3 Elephant
4 Spider
5 Tinkerbat
6 Heal
7 ScuttleTown
8 OasisTown
9 WaterTown
10 BanditTown
11 ZombieCaravan
1,2,3,4,5,6,7,8,9,10,11 NoMatch

TIO link includes code in the footer to translate these back to the strings in the question, but is not needed for the program to function using the integers specified here.

Nick Kennedy

Posted 2019-05-01T17:45:05.900

Reputation: 11 829

0

05AB1E, 104 bytes

'dð.•—Áå•«•¼L?D/8¢Am.Z¼ž•6BSèJ#«å.•g³ç¼…¬ÿ¬Õ‚YÙ•“ÆÚàæɾ ÿ“#.•664Îè¡HĆ∍•¸«“scuttle„©Ê´ bandit“#ð“‰à“«««sÏ

Try it online!


I wrote this monstrosity without realizing I could use numbers for name moves...

Magic Octopus Urn

Posted 2019-05-01T17:45:05.900

Reputation: 19 422

0

sfk, 119 91 bytes

xex -i -firsthit
_DR_
_DL_
_DA_
_DB_
_DUU_
_DUA_
_DULR_
_DURLAB_
_DURRBA_
_DULLBA_
_DUBLBR_

Try it online!

Gives the first dance present as a sequence of moves.

(xex is just a stream editor, and in this case _<pattern>_ is search text)

Οurous

Posted 2019-05-01T17:45:05.900

Reputation: 7 916

0

05AB1E, 28 27 bytes

Saved 1 byte thanks to Grimy

Œ.Δ•1Λ*#$ß‘«∍@…9\÷•6B1¡1ìQZ

Try it online!

Outputs either the match (i.e. 10 for Monkey) or -1 for no match

1 = D
0 = R
2 = L
3 = A
4 = B
5 = U
6 = .

Explanation

Œ.Δ                           # Find the first substring of the input
                         Q    # that is equal to
                          Z   # any element in
   •1Λ*#$ß‘«∍@…9\÷•           # 29058694378496950170872579685936
                   6B         # converted to base-6
                     1¡       # split on 1's
                       1ì     # with a 1 prepended to each

Emigna

Posted 2019-05-01T17:45:05.900

Reputation: 50 798

The ¦ isn't needed if you pick the right number – Grimmy – 2019-05-03T12:36:08.217

@Grimy: Thanks! I had a previous (longer) version where I didn't need the ¦, but I didn't think of reordering after I changed the meaning of the numbers :) – Emigna – 2019-05-03T13:14:22.380

26 with a different encoding – Grimmy – 2019-05-03T15:11:03.280