Created
August 17, 2018 19:57
-
-
Save gabrielsr/da2b416c08f6ad5f5f088d38b19ba9ce to your computer and use it in GitHub Desktop.
jokenPo simulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function match(){ | |
const END = 28; | |
const INITIAL_PLAYER_ONE_POS = 1; | |
const INITIAL_PLAYER_TWO_POS = 28; | |
let player_1 = 1; | |
let player_2 = 28; | |
let time = 0; | |
//RUN | |
while (player_1 != INITIAL_PLAYER_TWO_POS | |
&& player_2 != INITIAL_PLAYER_ONE_POS){ | |
if (player_2 - player_1 <= 1){ | |
console.log('same house. Jokenpo!'); | |
console.log(`hours:${time/ (60*24)}`); | |
let winnerTeam; | |
do { | |
time++; | |
winnerTeam = jokenPo(); | |
console.log(`jokenPo result: ${winnerTeam}`); | |
} while (winnerTeam == 'draw') | |
if (winnerTeam == 'player_1'){ | |
console.log(`player 2 starts again`); | |
player_2 = INITIAL_PLAYER_TWO_POS; | |
player_1++; | |
} | |
if (winnerTeam == 'player_2') { | |
console.log(`player 1 starts again`); | |
player_1 = INITIAL_PLAYER_ONE_POS; | |
player_2--; | |
} | |
} else { | |
time++; | |
player_1++; | |
player_2--; | |
console.log(`jump! (p1: ${player_1}, p2:${player_2}) `); | |
} | |
} | |
console.log('End of game!'); | |
if (player_1 == INITIAL_PLAYER_TWO_POS){ | |
console.log('player 1 wins'); | |
} | |
if (player_2 == INITIAL_PLAYER_ONE_POS) { | |
console.log('player 2 wins'); | |
} | |
console.log(`total time: ${time}s`); | |
} | |
function jokenPo() { | |
let outcome = Math.floor(Math.random() * 3); | |
if (outcome == 0){ | |
return 'draw'; | |
}else if(outcome == 1) { | |
return 'player_1'; | |
} else if (outcome == 2) { | |
return 'player_2'; | |
} | |
} | |
match(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment