1
\$\begingroup\$

This challenge is inspired by turn based videogames like "Heroes of Might and Magic"


Implement this game mechanic:

  • There is some units(Imps, Swordsmans etc...) in our game
  • Every unit have an integer "initiative"
  • Your program must decide which unit's turn now - based on unit's initiative
  • The more initiative means more frequent turns(for example unit with 10 iniative will move 5 times more often than 2 iniative unit)
  • Unit with highest initiative moves first
  • Input: Array of pairs of [unit_name: string, unit_initiative: integer]
  • Output: Unit names in moving sequence separated by line break (\n)
  • Make 50 turns total

Test case:

Units: [["Imp", 500], ["Mammoth", 50], ["Swordsman", 250], ["Elf", 350]]

turn sequence(50 turns) output:

Imp
Elf
Imp
Swordsman
Elf
Imp
Imp
Swordsman
Elf
Imp
Elf
Imp
Swordsman
Imp
Elf
Imp
Swordsman
Elf
Imp
Elf
Imp
Swordsman
Mammoth
Imp
Elf
Imp
Swordsman
Elf
Imp
Imp
Swordsman
Elf
Imp
Elf
Imp
Swordsman
Imp
Elf
Imp
Swordsman
Elf
Imp
Elf
Imp
Swordsman
Mammoth
Imp
Elf
Imp
Swordsman

Other rules:

  • Use your favorite language
  • Write shortest code possible
  • Attach a link to an online iterpreter
  • Please follow standard code golf rules
New contributor
Rundom is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
  • 5
    \$\begingroup\$ Welcome to the site. You need to provide an objective scoring criterion. From the ‘other rules’ bit, I assume you’re intending to make this a code golf challenge, so this should be tagged as such. The usual scoring for code golf is bytes. Optional challenges don’t tend to work because if you’re optimising code length you’ll ignore the optional challenges. \$\endgroup\$ – Nick Kennedy Nov 30 at 10:27
  • 3
    \$\begingroup\$ To add on, the optional challenges are also a problem since they look like they can be interpreted in a way that trivializes the task. They are very vague as to what they require so you might, remove all the units on the first turn, to avoid doing any computation, and say that this is fulfilling the first optional task. \$\endgroup\$ – Wheat Wizard Nov 30 at 13:51
  • \$\begingroup\$ Inputs and outputs specified; Optional challenges removed; "Write shortest code possible" added to "Other rules"; \$\endgroup\$ – Rundom Dec 2 at 9:44
  • 1
    \$\begingroup\$ Thanks for taking the time to fix the challenge. I am still unsure of the task. A couple of questions I have are: What sort of order is required if any? for example in your example could I just give Imp 500 turns in a row, then the elf 350, then the swordsman 250, then the mammoth 50 and then repeat? Or do I have to do some specific order? Or is there a rule that the order must follow? In order for this to be clear it must be possible to look at the output of a program on given inputs and objectively determine whether that program is valid. \$\endgroup\$ – Wheat Wizard Dec 2 at 14:18
1
\$\begingroup\$

Jelly, 20 15 bytes

P:ṭ×¥Ɱ"Ɗ,€"ẎṢṪ€

Try it online!

A dyadic link taking a list of initiative scores as its left argument and a list of characters as its right and returning a list of the characters in movement order.

Jelly, 14 bytes

İṭ×¥Ɱ"$,€"ẎṢṪ€

Try it online!

This version is one bytes shorter but I expect may sometimes get the order wrong because of inaccuracies in floating point calculations.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.