The Lance-Rolls of Moravel Field
On Moravel Field stands the Iron Centaur, a clockwork jouster that rides against any challenger bold enough to take up a lance. The Order of the Broken Pennon pays each challenger a bounty by points. A herald records every bout as a pass-roll: the outcome of each pass, in the order the passes were ridden.
Write tallyBout(passes), which takes passes, a list of strings. Each string is exactly one of "miss", "strike", "shatter", "unhorse" or "foul", all lowercase. The function returns the challenger's score as an integer.
Read the passes in order and apply these rules:
"miss"adds 0 points."strike"adds 1 point."shatter"adds 2 points."unhorse"adds 5 points and ends the bout. Every pass after it is ignored."foul"ends the bout and makes the final score 0. Every pass after it is ignored.
If no pass ends the bout, the score is the total of all the passes. An empty list scores 0.
examples
- case 1
passes of ["strike", "miss", "shatter"]3 (1 + 0 + 2, and no pass ends the bout) - case 2
passes of ["strike", "unhorse", "foul"]6 (the unhorsing ends the bout at 1 + 5, so the later foul is never ridden) - case 3
passes of ["shatter", "shatter", "foul", "unhorse"]0 (the foul ends the bout and wipes the 4 points; the unhorsing comes too late)
- reward
- 220 XP
- signature
tallyBout
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- plain bout with no ending pass
- empty roll scores zero
- unhorse ends the bout and ignores later passes
- foul wipes score and ignores later unhorse
- foul after unhorse is ignored
- all misses
- single foul
- single unhorse
- long bout without ending
- unhorse as the final pass