Game Rules
This match is a 1:1 match between Player 1 and Player 2's code, and the programming language is JAVASCRIPT.
Attack: punch(1), kick(2)
Target: head(1), body(2), leg(3)
Best of 5 rounds
1 Round = 200 Turns
After checking the game rules, writing the codes for Player 1 and Player 2, click the Start Game button to start the match.
Code battle's lifecycle callback functions are onGameStart, onRoundStart, onTurnStart, onTurnEnd, onRoundEnd, onGameEnd.
Scoring rules:
- The success or failure of head, body, and leg attacks is the same as rock-paper-scissors rule.
- Punch(1): head 4pts, body 3pts, leg 2pts
- Kick(2): head 6pts, body 5pts, leg 4pts
- If hitting areas are same, punch(1) wins kick(2).
Building a basic strategy, analyzing your opponent's pattern and returning the best choice at onTurnStart is the key to winning.
Player 1
Player 2
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);
}
}
TURN
Player 1
0
Player 2
0
ROUND
Player 1
0
Player 2
0
GAME
Player 1
0
Player 2
0
Game Log
Recent logs are displayed at the top.