Skip to content

Instantly share code, notes, and snippets.

@MartinMuzatko
Last active January 20, 2020 16:44
Show Gist options
  • Save MartinMuzatko/02e67ea8b67074f8915480436c48b9f1 to your computer and use it in GitHub Desktop.
Save MartinMuzatko/02e67ea8b67074f8915480436c48b9f1 to your computer and use it in GitHub Desktop.
const WIN = 1
const LOSE = -1
const TIE = 0
const methods = ['rock', 'paper', 'scissor']
let score = 0
const gameMap = new Map([
['rock-paper', LOSE],
['rock-scissor', WIN],
['rock-rock', TIE],
['paper-paper', TIE],
['paper-scissor', LOSE],
['paper-rock', WIN],
['scissor-paper', WIN],
['scissor-scissor', TIE],
['scissor-rock', LOSE],
])
const randomItem = items => items[Math.random() * items.length | 0]
const getResult = player => {
const enemy = randomItem(methods)
return gameMap.get(`${player}-${enemy}`)
}
score += getResult('scissor')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment