[Legends of Code and Magic] Remarks and bugs

Don’t worry. This is nothing compared to double hulk :smiley:

The leagues system can be used for a sprint IF the submit+promotion time is less than 5 minutes. Anything longer and the leagues system will only add frustration to the sprint.

Problem is, if the promotion is too fast, people will struggle to follow track of their results (last matches and progression) :stuck_out_tongue:

Without the performance issues, I think wood leagues are not an issue, as long as submits remain below < 10 minutes.

1 Like

Welcome to the Bronze league!

There are three additionnal abilities to take into account. Enjoy the game!

The Goal

Draft a deck of cards, battle an opponent with those cards and reduce their Health Points (HP) from 30 to 0.


This game is a two-player card game which is played in two phases: the Draft phase and the Battle phase.
During the Draft phase, both players must create a deck of 30 cards.
Once the Draft phase is over, both decks are shuffled.
During the Battle, the board is divided in two parts: each player plays cards from their hand on their side of the board.
Each player starts with 30 HP. Some cards can increase this number.
To reduce the health points of an opponent, the player must make use of cards to deal damage.

Draft Phase

For 30 turns, both players are given a choice between 3 different cards. Players select the card they want to add to their deck by using the PICK command followed by 0, 1 or 2.
By default, the PASS command will pick the first card.
Both players can select the same card, they will each receive a copy.

Battle Phase

Card Draw

First player starts with 4 cards in hand whereas the second player starts with 5.
Each turn, the active player draws one additional card from their deck.
Some cards can make players draw additional cards at the beginning of the next turn when played.
Both players possess runes which have an impact on card draw.
More details in Advanced Details section.


Mana is necessary to play cards.
Both players start with 1 max mana.
Each turn, the active player is granted one additional max mana, unless they already have 12 max mana.
Each player can spend as much mana per turn as they have max mana.

Card Types

There are two different types of cards: Creatures and Items.


Placing a creature card from the hand to the board is called summoning. A player summons creatures on their side of the board. They are used to attack the opponent and also serve as a defense against the creatures of the opposing player.
Creatures have a cost in mana, attack points and defense points. Some creatures start with certain abilities.
By default, creatures can’t attack the turn they are summoned. They can attack once per turn only.
When a creature attacks another one, they both deal damage equals to their attack to the defense of the other creature. When a creature attacks the opponent, it deals damage equals to its attack to the HP of the opponent.
Creatures are removed from play when their defense reaches 0 or less.
Creatures can have an effect on the player’s health, the opponent’s health or the card draw of the player when played.

Creatures can have different abilities:

Breakthrough: Creatures with Breakthrough can deal extra damage to the opponent when they attack enemy creatures. If their attack damage is greater than the defending creature’s defense, the excess damage is dealt to the opponent.
Charge: Creatures with Charge can attack the turn they are summoned.
Drain: Creatures with Drain heal the player of the amount of the damage they deal (when attacking only).
Guard: Enemy creatures must attack creatures with Guard first.
Lethal: Creatures with Lethal kill the creatures they deal damage to.
Ward: Creatures with Ward ignore once the next damage they would receive from any source. The “shield” given by the Ward ability is then lost.


When played, items have an immediate and permanent effect on the board or on the players. They are then removed from play.
Items have a cost in mana and one or multiple effects out of the following:
Permanent modifier of a creature’s attack and/or defense characteristics. Example: +0/+2 or -1/-1.
The addition or removal of one or more abilities to one creature.
Additional card draw the next turn they’re played.
Health gain for the player or health loss for the opponent.
There are three types of items:
Green items should target the active player’s creatures. They have a positive effect on them.
Red items should target the opponent’s creatures. They have a negative effect on them.
Blue items can be played with the “no creature” target identifier (-1) to give the active player a positive effect or cause damage to the opponent, depending on the card. Blue items with negative defense points can also target enemy creatures.


Possible Actions

SUMMON id to summon the creature id from your hand.
ATTACK id1 id2 to attack creature id2 with creature id1.
ATTACK id -1 to attack the opponent directly with creature id.
USE id1 id2 to use item id1 on creature id2.
USE id -1 to use item id.
PASS to do nothing this turn.
A player can do any number of valid actions during one turn. Actions must be separated by a semi-colon ;.

Game End

The game is over once any player reaches 0 or less HP.
Victory Conditions
Reduce your opponent Health Points (HP) from 30 to 0 or less.
Loss Conditions
Your HP gets reduced to 0 or less.
You do not respond in time or output an unrecognized command.

Advanced Details

You can see the game’s source code on https://github.com/CodinGame/LegendsOfCodeAndMagic.


Each player has 5 runes corresponding to the 25, 20, 15, 10 and 5 HP thresholds.
The first time a player’s HP go below one of these thresholds, that player loses a rune and will draw an additional card at the beginning of the next turn. A maximum of 5 cards can thus be drawn this way during the entire game.
When players have no more cards in their decks and must draw a card, they lose a rune and reach the corresponding HP threshold.
Example: a player has 23 HP, 4 runes remaining and no more cards in the deck. If that player must draw a card, the player loses a rune (the 20 HP rune) and 3 HP to reach 20.
If a player has no more runes, no more cards in the deck and must draw a card, that player’s HP reaches 0.


If a player already has the maximum number of 8 cards in hand and must draw, the draw is cancelled.
If a player already has the maximum number of 6 creatures on board and tries summoning a new one, the summoning action is cancelled.
If a player tries to attack an untargetable target (wrong instance id or presence of other defensive creatures with Guard) with one of his creatures, the attack action is cancelled.
Once a player has played over 50 turns, their deck is considered empty.

Abilities special cases

Giving an ability to a creature with that same ability has no effect.
Attacking a creature with Ward with a creature with Lethal does not kill the creature (since no damage is dealt to the creature).
Attacking a creature with Ward with a creature with Breakthrough never deals excess damage to the opponent (since no damage is dealt to the creature).
Attacking a creature with Ward with a creature with Drain does no heal the player (since no damage is dealt to the creature).

Game Input

Input for one game turn

First 2 lines: for each player, playerHealth, playerMana, playerDeck and playerRune:
Integer playerHealth: the remaining HP of the player.
Integer playerMana: the current maximum mana of the player.
Integer playerDeck: the remaining number of cards in the player’s deck.
Integer playerRune: the next remaining rune of a player.
The player’s input comes first, the opponent’s input comes second.

During the Draft phase, playerMana is always 0.

Next line: Integer opponentHand, the total number of cards in the opponent’s hand. These cards are hidden until they’re played.

Next line: Integer cardCount: during the Battle phase, the total number of cards on the board and in the player’s hand. During the Draft phase, always 3.

Next cardCount lines: for each card, cardNumber, instanceId, location, cardType, cost, attack, defense, abilities, myhealthChange, opponentHealthChange and cardDraw:
Integer cardNumber: the identifier of a card (see complete list).
Integer instanceId: the identifier representing the instance of the card (there can be multiple instances of the same card in a game).
Integer location, during the Battle phase:
0: in the player’s hand
1: on the player’s side of the board
-1: on the opponent’s side of the board
Always 0 during the Draft phase. Always 0 for items.
Integer cardType:
0: Creature
1: Green item
2: Red item
3: Blue item
Integer cost: the mana cost of the card,
Integer attack:
Creature: its attack points
Item: its attack modifier
Integer defense:
Creature: its defense points
Item: its defense modifier. Negative values mean this causes damage.
String abilities of size 6: the abilities of a card. Each letter representing an ability (B for Breakthrough, C for Charge and G for Guard, D for Drain, L for Lethal and W for Ward).
Integer myHealthChange: the health change for the player.
Integer opponentHealthChange: the health change for the opponent.
Integer cardDraw: the additional number of cards drawn next turn for the player.

Output for one game turn of the Draft

PICK nb where nb equals 0, 1 or 2 to choose one of the three proposed cards to add to your deck.
PASS to do nothing (picks the 1st card by default).

Output for one game turn of the Card Battle

The available actions are:
SUMMON id to summon the creature of instanceId id from the player’s hand.
ATTACK idAttacker idTarget to attack an opposing creature or opposing player of instanceId idTarget with a creature on the board of instanceId idAttacker.
idTarget can be the “no-creature” identifier -1. It is used to attack the opponent directly.
USE idCard idTarget to use an item of instanceId idCard on a creature of instanceId idTarget or without a target with the “no-creature” identifier -1.
PASS to do nothing.
Players may use several actions by using a semi-colon ;.
Players may append text to each of their actions, it will be displayed in the viewer.

Example: SUMMON 3;ATTACK 4 5 yolo; ATTACK 8 -1 no fear.


Response time for the first draft turn <= 1000ms
Response time for the first battle turn <= 1000ms
Response time per turn <= 100ms
0 <= cost <= 12
0 <= creatures on one side of the board <= 6
0 <= cards in hand <= 8


For sprints the unsureness factor for TrueSkill should be way lower, so that not 100+ games are required to beat the boss. When many games are played and multiple AIs are submitted the ladder remains in flux, but when 2/3 of the league are above the boss, there should be promotions to compensate.

The 100+ matches on submit is only available on Gold/Legend League, we already have a lower limit for wood league.

But I had 110 Games before being promoted to Wood 2, at this point I was a rank 80 and the Boss at 180 out of the 230 bots in Wood 3.

For instance, in wood2 you only had 30 matches to generate.

But, when someone play with you, you will have a match in your last battle, but you won’t progress in your own “30” matches ranking.

That’s something we will look into. I.E, playing a match should update the ranking progress for all player involved in the match.

To be clearer:

  • If we have only 2 players that need to generate 30 matches:
    Both will have 60 matches in there last battles (30 “A generate a match using B as opponent”, and 30 “B generate a match using A as opponent”)
1 Like

On the same note: When opening the “Last battles” tab, please do not launch the TV with some random battle, it freezes everything and takes aeons to load useless stuff (the TV is useful for checking some specific battle, not a random one).


My thoughts on the 4h sprint format:
I think 4h is really fun, because it allowes participants with less time a good chance at winning. Also it allows more diverse strategies as none are optimized to a high degree.

Problematic where the slow promotions.
I don’t know much about the infrastructure of the Codingame servers, but my guess is that under the load of all 750 people submitting at the same time, something will always break or slow to the crawl.

The idea of only one league would solve the issue of participants not being able to bug check rule changes, but still everything would be slow and it would be hard if not impossible to gain any information by looking at the rank and past games.

My thought was to not even have a ladder while the 4h sprint runs. Everybody could still check his version against other submitted bots (maybe only if he submits that version himself - otherwise noone would submit right?), but there would not be the huge load of in that sense “unnecessary” ladder games being run, which won’t finish in time anyways.

It would still be fair and i would not be disappointed for something not working what should have.
That limitation might even be a feature, to kinda blindy code and not just copying the best bot/strat!

just a thought, might be stupid, what do you think? :slight_smile:

I only played for the last hour which was over my lunch break, but I thought it was fun. The server problems / slowness made it pretty frustrating, but I enjoyed the format and the game. I’m looking forward to the marathon.

Also whoever thought of highlighting the new rules in green each league is a genius! Huge improvement.


If your creature with Drain and 12 attack damages a creature with only 1 defense, do you get 1 health or 12 health?

For local play and offline testing I prepared a cg-brutaltester compatible referee:

Compiled and ready to use version here:

I want to share here to make it easier to test for everyone (and maybe lighter for Codingame servers), hope it’s not against CG policy or authors intentions.

Btw. the original referee code crashed due to empty entries in last columns of the cards description file.


10 minutes is a very very long time in a 4 hour sprints with 3 woods leagues. It means in the best case we have to wait 30 minutes (1/8 of the sprint length). This best case is only achievable if we have to submit only once in every wood league or if our code is good enough to promote more than one league. If you have to submit twice in each, you wait 60 minutes (1/4 of the sprint length!)

As the wood league are more about learning the rules than being better than all other player. Removing the leader board in the woods leagues and to promote automatically if you beat the boss at least 6 time over 10 battles would make a lot of sense, reduce the promotion delay and the load on the server.


Actually I would even be happy to just have wood 3 rules, should be enough complexity for 4h. That applies to all challenges i participated in.


Well, I disagree.

Nothing prevents you from coding when your battles are computing. Even if you don’t know the next rules yet, you can surely improve the code you’ve written to prepare the next steps.
You can also take a few minutes to watch replays you lose and possibly fix bugs in your code.

10mn submissions max looks OK to me.


What is the point of improving a code when this code will crash in the next league because of an invalid action ?

Of course we can continue to code when our code is submitting. But it’s pointless. We can’t know for sure the next league, we can’t test it. Most of the time we are promoted to the next league and our code just crash because we are trying to attack the player and now there’s guard creature on the board. How are we supposed to improve our code to handle that ?

Give us a button to play at any league level even if you are in wood 3 and i’ll follow you on that. But at the time coding while waiting for a promotion in wood leagues is wasted time.


That’s the reason why my code improvements during the 30min wait were only attempts to handle the possible unknown and not break on new leagues, but that was more than enough time, so that the second submit (~30 min) went into my daily commute home.

Writing my answer, I could already hear you scream with rage :smiley: I was pretty sure you’d be the first to answer.

Most of the time we are promoted to the next league and our code just crash

You’re only writing this in bad faith.

I am merely saying that the time from clicking the submit button to getting promoted to an upper league can easily be used towards improving an AI (one way or another) rather than just waiting to implement the new rule. If that time remains below 10 minutes, it is to me perfectly acceptable.

Maybe I’m subjective on this since I always know the new rules :grin:

Anyway, I agree that the leagues format isn’t really suited for short contest durations.

This could potentially be problematic since the ranking matches are supposed to be around your own rank. At least the initial 10 matches of fresh submits should probably not be counted for the opponents.