The first experience or how to try to become a legend of code and magic

Hello. My name is Valentine.

On July 10, I read the post Oli Ollisteka about on Habré and decided to try my hand at logical tasks, as well as in the Legends of Сode and Magic competition.

In view of the large amount of free time, I became interested in puzzles and tasks that are present on this resource. It’s good that every task, every puzzle makes you look for a solution, even if it’s not obvious.


Next will be a brief information about the rules of the competition, as well as some obvious or not so things for beginners.

Legends of Code and Magic

Contest, which runs from July 25 to August 24. The game is in a sense similar to Hearthstone, however, some of the things have been improved in the direction of the balance between the players.

The game takes place between two players, and it is a turn-based game. Each player has his or her deck of cards selected from the available options during the Draft phase before the Battle phase.

Phase Draft

During the Draft phase, each player forms his deck of 30 cards. Accordingly, the first 30 moves, each turn offers the player a choice of 3 cards, one of which he can choose.

At the time of writing, there are 4 types of cards in the game:

  1. Creatures (Creatures) are essentially monsters. They are the main resource of the player, which allows him to both defend and attack the enemy.
  2. Green items. Used on allied beings. Raise the value of attack / defense. Add abilities to a creature.
  3. Red items. Used on enemy creatures. Reduce the value of attack / defense. Take away the ability. Can instantly kill an enemy creature (-99 defense)
  4. Blue items. These cards are used only on the opponent. More often they take away life and the enemy, sometimes they make up for the health of their owner.

Also in the game there are 6 types of abilities in creatures:

  1. Breakthrough. If a creature with this ability deals damage more than the opponent’s creature’s health, the remaining damage will go to the opponent. (Useful ability, but as practice has shown, few people use these cards for their intended purpose)
  2. Charge. Allows you to attack on the same turn that was caused.

    (Indispensable in a quick-fight strategy, however, almost all cards with Charge have a low attack / defense value and if the battle is prolonged, the probability of losing increases)
  3. Drain. Attack on enemy creatures / enemy replenishes health comparable to the attack. (Uber-ability. The required number of cards allows you to increase health up to 50-70 points (from the original 30), but most of the cards with this ability also have low attack / defense values)
  4. Guard. The ability protects from a direct attack on the player. First you need to destroy creatures with this ability. (In my opinion, the card has the most useful ability. However, you should consider the fact that some of the cards with this ability have zero attack)
  5. Lethal. Destroys a creature that attacks. (As a rule, cards with lethal have a single protection, which means that they can remove a maximum of one card)
  6. Ward In fact - protection from the first damage. After the first attack, the defense essentially disappears and the map becomes ordinary. (This ability is kontrit and flew and breakthrough and draine. But the card does not protect the owner from damage, so I have not seen cards with ward in the strategies of other players).

After selecting the cards in your deck, the Draft phase ends. Battle phase begins

Battle Phase

In this phase, the main goal is to defeat the opponent, to reduce the amount of his health to 0.
At the same time, the player has such a parameter as Man. During the 1 turn in the Battle phase, the mana value is 1. Next, each turn the indicator increases by 1 until it reaches the maximum value of 12. Mana points are spent on the summons of creatures, as well as the use of items.


At the beginning of each turn, the player has information about his cards on the hands and the table, as well as the cards on the opponent's table. Based on this data, the bot (program) should make a string of commands.

Each turn from the collected deck gets one random card. If health drops to 25, 20, 15, 10, or 5, more cards will be called on the next turn.

In the following turn, the opponent will draw 3 cards from the deck.

As a rule, if the opponents are approximately equal in strength, the game ends in about 200 moves, but I have had a play in 240-250 moves. The lower limit is approximately 80-85, provided that the players did not fly errors with improper use of teams.

Possible useful strategies

The main difference of this competition from the previous Code of Kutulu is that this is a card game and there is an element of chance and luck in it.

During the contest, several strategies were tested:

  1. A set of creatures with charge, lethal and a breakthrough for quick victory.
  2. A set of creatures with Guard for maximum security + cards with charge and drain.
  3. A set of creatures with Guard + green and red cards.
  4. A set of creatures with a maximum attack / defense, the presence of indicators + to the health of the player or - to the health of the enemy, and only then, depending on the abilities.

Conventionally, strategies can be divided into 2 categories.

Quick victory - creatures attack only the enemy and guard creatures if there are any.
Complete victory - the creatures of the enemy are destroyed, and if there are no creatures, then the enemy himself.

Now briefly for each strategy:

A set of creatures with charge, lethal and breakthrough for quick victory

The strategy has shown its inconsistency due to the element of chance. You can score a lot of cards that cost 1-2 mana, but they will not be in the starting cards at all. This strategy should be used only for a quick victory and if the enemy has not called a single creature c Guard. During the contest, I met this strategy with other players, even from the top, but as a rule, if the game went over 100-120 moves, they quickly lost.

A set of creatures with Guard for maximum security + cards with charge and drain

One of the best strategies for a quick game. Cards are called defenders. And if there are none, then Charge and Drain. This strategy allows you to effectively destroy the enemy defenders and at the same time remain under protection. In the case of a transition to a long game, the strategy does not lose its power, as there are creatures with the Guard and having high rates of attack / defense.

Creature set with Guard + green and red cards

The strategy is worse than the previous one, since the object cards are more auxiliary than the main one. Therefore, it was decided to shift the priority to the creatures.

Creature set with maximum attack / defense

In drawing up this strategy, I was guided by the work of bots-bosses, as well as several players. The strategy is only suitable for a protracted game, as a rule there is not enough mana to summon in the initial moves.

Minuses. As well as workarounds

When compiling the bot for the last strategy, it was found that if the team of the call is directed to a card that cannot be summoned due to lack of mana, or an attack on the card that cannot be attacked, then this command is marked as Action is not legal. On the one hand, this is a remarkable feature of the contest, few of the participants took into account the health of the creatures during the attack or the impact of the object cards, so if all the creatures attacked a card that has already been destroyed, all the teams automatically switched to not legal.

However, the opportunity to make just a huge number of teams at a time.


In theory, you can write a team attack on a single card for each of the creatures of the enemy, and then on the enemy. Write all possible combinations of SUMMON and ATTACK.

It will be executed that will be executed, and the rest will go to Action is not legal.


At the time of this writing, my bot is on the 120th place in the bronze league.

And at 950 in the general top. However, by the end of the contest, I rolled out of the top 1000.
Modest result. This is partly due to the first experience of participating in the contest. Player rating is calculated based on the True Skill algorithm. According to this algorithm, 10–20 battles with the best in this league are conducted, based on the results, the starting place in the table is determined, and then battles with a rating of ± 10 are held, each victory increases the rating, each loss lowers. This is how more than 100 fights are conducted and a place in the table is determined. And further, the bot continues to fight with the players who send their program for processing. Thus, you can increase your rating just by being in the table. I sent the algorithm over and over again in the hope of being immediately in the top.

It remains to wait and prepare for the next competition on In addition, I'm waiting for the game to get into multiplayer, which will improve my code.

Also popular now: