Check the rules of the game, fill in the functions below, select your opponent and press the start button to start the game.
You and your opponent will each receive 2 cards (Hwatu card), and it is a game where you win or lose with a combination of 2 cards.
There are 20 cards in total, and there are two pairs of cards that represent the numbers 1 to 10. It is assumed that the cards consist of numbers 1 to 10 and numbers 11 to 20 so that only the numbers can be distinguished. For example, 15 is the second card meaning 5.
You get money when the game starts, you get 2 cards and 1 opponent card at the start of the round, and you have to choose raise or call or die on each turn.
"raise" is an action that raises table money, "call" is an action that accepts only the amount of money raised by the opponent and ends the round and confirms the win or lose, and "die" is an action that gives up the opponent's card check and pays only the basic money(1) before giving up the round.
Code battle is a battle between your code and opponent's code, and the language is JAVASCRIPT.
Fill in the code, select the opponent (LEVEL1, LEVEL2, LEVEL3, Online opponent) and then press the game start button will start the match.
1 game consists of a maximum of 200 rounds and the game ends if either you or your opponent runs out of money while the round is repeated. And, 1 round consists of several turns. On each turn, you can "raise" to raise table money and pass it to your opponent's turn, or you can "call" or "die" to finish the round.
OnGameStart and onGameEnd functions are called at the beginning and end of the game, onRoundStart and onRoundEnd functions are called at the beginning and end of each round, and onTurnStart is called on each turn. onGameStart => onRoundStart => onTurnStart => onRoundEnd => onGameEnd. You can implement your own logic in each function.
Building a basic strategy of the game, analyzing your opponent's pattern and returning the best choice from onTurnStart is the key to winning.
11
12
13
14
15
16
17
18
19
20
Order | Group | Name | Remarks |
1 | Gwang-ttaeng | 3 and 8 gwang-ttaeng | When two cards are 3 and 8. Sutda's strongest combination. |
2 | Gwang-ttaeng | 1 and 8 gwang-ttaeng | When two cards are 1 and 8. |
3 | Gwang-ttaeng | 1 and 3 gwang-ttaeng | When two cards are 1 and 3. |
4 | Ttaeng | 10 ttaeng | When two cards are 10 and 20. |
5 | Ttaeng | 9 ttaeng | When two cards are 9 and 19. |
6 | Ttaeng | 8 ttaeng | When two cards are 8 and 18. |
7 | Ttaeng | 7 ttaeng | When two cards are 7 and 17. |
8 | Ttaeng | 6 ttaeng | When two cards are 6 and 16. |
9 | Ttaeng | 5 ttaeng | When two cards are 5 and 15. |
10 | Ttaeng | 4 ttaeng | When two cards are 4 and 14. |
11 | Ttaeng | 3 ttaeng | When two cards are 3 and 13. |
12 | Ttaeng | 2 ttaeng | When two cards are 2 and 12. |
13 | Ttaeng | 1 ttaeng | When two cards are 1 and 11. |
14 | Kkeus | 9 kkeus | When the "units" number of the sum of two card is 9. (Ex: 5 and 14, or 3 and 6). If it's the same, compare the big cards. (Ex: ['5' and 4] < [3 and '6']) |
15 | Kkeus | 8 kkeus | When the "units" number of the sum of two card is 8. (Ex: 5 and 13, or 6 and 2) |
16 | Kkeus | 7 kkeus | When the "units" number of the sum of two card is 7. (Ex: 2 and 15, or 3 and 4) |
17 | Kkeus | 6 kkeus | When the "units" number of the sum of two card is 6. (Ex: 5 and 11, or 1 and 5) |
18 | Kkeus | 5 kkeus | When the "units" number of the sum of two card is 5. (Ex: 2 and 13, or 3 and 2) |
19 | Kkeus | 4 kkeus | When the "units" number of the sum of two card is 4. (Ex: 4 and 10, or 1 and 3) |
20 | Kkeus | 3 kkeus | When the "units" number of the sum of two card is 3. (Ex: 1 and 12, or 2 and 1) |
21 | Kkeus | 2 kkeus | When the "units" number of the sum of two card is 2. (Ex: 2 and 10, or 3 and 9) |
22 | Kkeus | 1 kkeus | When the "units" number of the sum of two card is 1. (Ex: 1 and 10, or 5 and 6) |
23 | Kkeus | 0 kkeus | When the "units" number of the sum of two card is 0. (Ex: 1 and 9, or 3 and 7) |
/**
* Please write code with JAVASCRIPT.
*/
var who_first = "";
/**
* Called when the game starts.
* Here is the initialization of the variables to use during the game.
* @param data
* data.my_money: My starting money
* data.op_money: The opponent's starting money
*/
function onGameStart(data) {
// print(string) is a function that outputs text to the game log area at the bottom of the play area.
print("onGameStart!");
}
/**
* Called when the round starts.
* One round means one sutda match, and here you will receive the data for the match.
* @param data
* data.my_money: My money
* data.op_money: The opponent's money
* data.my_cards: My card numbers [First card, Second card]
* data.op_card: The opponent's first card number
* data.who_first: Who is the first turn. "me" means me, "op" means the opponent.
*/
function onRoundStart(data) {
print(
"onRoundStart!"
+" my_money:"+data.my_money+", op_money:"+data.op_money
+", my_cards:["+data.my_cards[0]+","+data.my_cards[1]+"]"
+", op_card:"+data.op_card+", who_first:"+data.who_first
);
who_first = data.who_first;
}
/**
* Called when the turn starts.
* You need to choose "raise" or "call" or "die" in here.
* @param data
* data.my_cards: My card numbers [First card, Second card]
* data.op_card: The opponent's first card number
* data.op_turn_result: The result of the opponent's turn. The return value of the opponent's onTurnStart().
* @return {
* "action": "raise" or "call" or "die". You must return "raise" or "die" when the "data.op_turn_result" is null.(the first turn).
* "money": If you choose "raise", this value should be the sum of the opponent's raising money and my raising money.
* If you choose "call", this value should be the opponent's raising money.
* If you choose "die", this value should be 1.
* }
*/
function onTurnStart(data) {
// A very simple sample code is below
// Write a better algorithm to determine "action" and "money".
var result = {};
if (who_first == "me" && data.op_turn_result == null) {
result["action"] = "raise";
result["money"] = 1;
} else { // who_first == "op"
result["action"] = "call";
result["money"] = data.op_turn_result.money;
}
// Print logs
var op_turn_str;
if (data.op_turn_result == null) {
op_turn_str = "op_turn{ null }";
} else {
op_turn_str = "op_turn{ action:"+data.op_turn_result.action+", money:"+data.op_turn_result.money+" }";
}
print("onTurnStart! "+op_turn_str+", my_return: { action:"+result.action+", money:"+result.money+" }");
return result;
}
/**
* It is called when the round is over and receives the result of the round.
* If you or your opponent's turn result is not raise (call or die), the round ends and somebody makes money.
* @param data
* data.win: -1(lose) or 1(win)
* data.last_turn_result: The last turn result of the round
* data.who_last: Whose turn was the last turn. me or op
* data.my_money: My current own money
* data.op_money: The opponent's current own money
* data.my_cards: My card numbers [First card, Second card]
* data.op_cards: The opponent's card numbers [First card, Second card(If you or your opponent's last action is "die", this value is 0)]
*/
function onRoundEnd(data) {
print(
"onRoundEnd! win:"+data.win
+", last_turn { action:"+data.last_turn_result.action+", money:"+data.last_turn_result.money+", who:"+data.who_last+" }"
+", my_money:"+data.my_money+", op_money:"+data.op_money
+", my_cards:["+data.my_cards[0]+","+data.my_cards[1]+"]"
+", op_cards:["+data.op_cards[0]+","+data.op_cards[1]+"]"
);
}
/**
* It is called when the game is over and receives the result of the game.
* @param data
* data.win: -1(lose) or 0(tie) or 1(win)
* data.my_money: My final money
* data.op_money: The opponent's final money
*/
function onGameEnd(data) {
print("onGameEnd! win:"+data.win+", my_money:"+data.my_money+", op_money:"+data.op_money);
print("----------------------------");
}