This match is a 1:1 match between Player 1 and Player 2's code, and the programming language is JAVASCRIPT.
After checking the game rules, writing the codes for Player 1 and Player 2, click the Start Game button to start the match.
1 game consists of 5 rounds, 1 round consists of 100 turns.
Code battle's lifecycle callback functions are onGameStart, onRoundStart, onTurnStart, onTurnEnd, onRoundEnd, onGameEnd, and you have to implement your own logic on each function.
Building a basic strategy of the game, analyzing your opponent's pattern and returning the best choice at onTurnStart is the key to winning.
The game rules
- In each turn, you select the punch_or_kick and the hitting_area.
- punch_or_kick: punch(1), kick(2)
- hitting_area: head(1), body(2), leg(3)
- The success or failure of head, body, and leg attacks is the same as the rock-paper-scissors rule.
- Head attack(1) loses to body attack(2).
- Body attack(2) loses to leg attack(3).
- Leg attack(3) loses to head attack(1).
- If punch_or_kick is punch(1),
- If head attack(1) is successful, you gain 4 points.
- If body attack(2) is successful, you gain 3 points.
- If leg attack(3) is successful, you gain 2 points.
- If punch_or_kick is kick(2),
- If head attack(1) is successful, you gain 6 points.
- If body attack(2) is successful, you gain 5 points.
- If leg attack(3) is successful, you gain 4 points.
- If both player's hitting_areas are same,
- If both player's punch_or_kicks are same, it is a draw.
- Else, punch wins kick.
class {
/**
* Please write code with JAVASCRIPT, and do not change the first line and the name of the on...() methods.
*/
/**
* Please set the player's name or nickname.
* If left as is, it will be replaced by Player1 or Player2.
* The player_name can be used to identify whose logs when call printLog,
* and it is displayed on the TURN / ROUND / GAME status board.
*/
player_name = "_will be replaced_";
/**
* Called when the game starts.
* Here is the initialization of the variables to use during the game.
*/
onGameStart() {
// printLog(string) is a function that outputs text to the game log area at the bottom of the play area.
printLog(this.player_name+": onGameStart!");
}
/**
* Called when the round starts.
* 1 game runs 5 rounds.
*/
onRoundStart() {
printLog(this.player_name+": onRoundStart!");
}
/**
* Called when the turn starts.
* 1 round runs 200 turns.
* @return [punch_or_kick, hitting_area]
* punch_or_kick: 1(punch), 2(kick)
* hitting_area: 1(head), 2(body), 3(leg)
*/
onTurnStart() {
// random choice of 1 or 2
let punch_or_kick = Math.floor((Math.random() * 2) + 1);
// random choice of 1 or 2 or 3
let hitting_area = Math.floor((Math.random() * 3) + 1);
printLog(this.player_name+": onTurnStart! punch_or_kick:"+punch_or_kick+", hitting_area:"+hitting_area);
return [punch_or_kick, hitting_area];
}
/**
* It is called when the turn is over and receives the result of the turn.
* @param result
* result.win: -1(lose) or 0(tie) or 1(win)
* result.opponentchoice: opponent's choice on this turn. [punch_or_kick, hitting_area]
* result.winscore: How many points have you won by winning this turn?
* result.losescore: How many points have you lost in this turn?
*/
onTurnEnd(result) {
printLog(this.player_name+": onTurnEnd! win:"+result.win+", opponent's choice:"+result.opponentchoice
+", winscore:"+result.winscore+", losescore:"+result.losescore);
}
/**
* It is called when the round is over and receives the result of the round.
* @param result
* result.win: -1(lose) or 0(tie) or 1(win)
* result.wincnt: How many rounds did you win in this game?
* result.losecnt: How many rounds did you lose in this game?
*/
onRoundEnd(result) {
printLog(this.player_name+": onRoundEnd! win:"+result.win+", wincnt:"+result.wincnt+", losecnt:"+result.losecnt);
}
/**
* It is called when the game is over and receives the result of the game.
* @param result
* result.win: -1(lose) or 0(tie) or 1(win)
*/
onGameEnd(result) {
printLog(this.player_name+": onGameEnd! win:"+result.win);
}
}