Game Rules
This is a baseball game where Player 1 and Player 2's code battle 1:1. The programming language is JAVASCRIPT.
3x3 Strike Zone
Best of 7 rounds
1 Round = 9 innings
After checking the game rules, writing the codes for Player 1 and Player 2, click the Start Game button to start the match.
Strike Zone:
| 0,0 | 0,1 | 0,2 |
| 1,0 | 1,1 | 1,2 |
| 2,0 | 2,1 | 2,2 |
Turn Results:
- Home Run: Pitcher and hitter choices match exactly
- Hit: Pitcher and hitter rows match (always a single)
- Strike: Pitcher throws strike and hitter misses, or pitcher throws ball and hitter swings
- Ball: Otherwise
Ball Probability: Except center ([1,1]), corners have 5/9 and sides have 1/3 probability of becoming a ball.
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 Score 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 7 rounds.
* A round is one baseball game (9 innings).
*/
onRoundStart() {
printLog(this.player_name+": onRoundStart!");
}
/**
* Called with data when the round starts.
* You must return what your choices are this turn.
* For one round, the turn is repeated until 9 innings have been completed.
*
* @param data
* data.inning: current inning. 1~9
* data.is_offence: true(offence), false(defence)
* data.ball_count: ball counts. {s:0, b:0, o:0}
* data.score: current scores. {me:0, op:0}
* data.runner: runner's count. 0~3
*
* @return [row, col]
* row: 0 or 1 or 2
* col: 0 or 1 or 2
* If you enter a coordinate that is out of range or null,
* In the case of defense (pitcher), it is not a strike,
* If it is an offense (hitter), it is considered not to swing.
*/
onTurnStart(data) {
// random choice of 1 or 2 or 3. 3 is an out-of-range choice.
let row = Math.floor(Math.random() * 4);
let col = Math.floor(Math.random() * 4);
printLog(this.player_name+": onTurnStart! is_offence:"+data.is_offence+", choice:["+row+", "+col+"]");
return [row, col];
}
/**
* It is called when the turn is over and receives the result of the turn.
*
* @param result
* result.is_offence: true(offence), false(defence)
* result.choice: {me:[0,0], op:[0,0]}
* If the value is out of range, it will be null.
* result.result: 0 or 1 or 2 or 3
* 0: strike
* 1: ball
* 2: hit
* 3: home run
* result.ball_count: ball counts. {s:0, b:0, o:0}
* result.score: current scores. {me:0, op:0}
* result.runner: runner's count. 0~3
*/
onTurnEnd(result) {
printLog(this.player_name+": onTurnEnd! is_offence:"+result.is_offence+", choice:"+JSON.stringify(result.choice)+", result:"+result.result);
}
/**
* 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.score: current scores. {me:0, op:0}
* 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+", score:"+JSON.stringify(result.score));
}
/**
* 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);
}
}
Strike Zone
| 0,0 | 0,1 | 0,2 |
| 1,0 | 1,1 | 1,2 |
| 2,0 | 2,1 | 2,2 |
Ball Count
| S | 0 |
| B | 0 |
| O | 0 |
Runners
| 1B | |
| 2B | |
| 3B |
Score Board
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | R | Win | |
| Player 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Player 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Game Log
Recent logs are displayed at the top.