JSFiddle - React, Tailwind, and code Playground
by TimWolla
HTML
<textarea placeholder="Mafia" rows="10" cols="40" id="mafia"></textarea><textarea placeholder="Dorf" rows="10" cols="40" id="dorf"></textarea><br />
<button type="button" id="roll">Würfeln</button><br />
<textarea placeholder="Ergebnisse" rows="10" cols="40" id="result"></textarea>
CSS
textarea, button {
border: 1px solid;
width: 100%;
padding: 0;
}
CoffeeScript
# fisher yates shuffle (http://stackoverflow.com/a/6274398)
arrayShuffle = (array) ->
counter = array.length
while counter > 0
index = Math.floor counter * Math.random()
counter--
tmp = array[counter]
array[counter] = array[index]
array[index] = tmp
array
roll = (mafia, dorf) ->
mafia = arrayShuffle mafia
dorf = arrayShuffle dorf
result = []
if Math.random() < .5
result.push mafia.pop() + " (Mafia)"
all = arrayShuffle mafia.concat dorf
result.push (player = all.pop()) + " (" + (if player in mafia then "Mafia" else "Dorf") + ")"
result.push (player = all.pop()) + " (" + (if player in mafia then "Mafia" else "Dorf") + ")"
else
result.push dorf.pop() + " (Dorf)"
result
$('#roll').click ->
$('#result').val (roll $('#mafia').val().split(/\n/), $('#dorf').val().split(/\n/)).join "\n"