📜 ⬆️ ⬇️

CodeCraft - the battle of programmers




CodeCraft belongs to the genre Programming game . Many of you probably know about the HabraWars project or about other Programming games. That is, the desire to write an environment for programmer battles arose among many. Here I, for example, had this idea.
Its distinguishing features are:


Why did I decide that the environment for programmer battles should be just that?

Yes, I just always imagined mental combat as a competition of strategies, rather than single units. Otherwise, it’s not the strategy that is programmed, but the behavior, it turns out more like a shooter.
It is much more colorful to look at the algorithm of the armies behavior: even rows of phalanxes, which methodically crowd out the enemy, packs of units that rush through, cunning maneuvers with fast units, unexpected strikes from the rear, a classic victory over a stronger rival thanks to the environment, etc. In many ways, the game is inspired by drawings from history textbooks, where conventional graphic images of different types of troops and their movements are noted. On the most boring pairs, imagination set them in motion, creating the concept of CodeCraft.

')




Story



The idea of ​​creating the game came to me like this: it was necessary to diversify my birthday, where only programmers were collecting then. So began the creation of the project. The idea was supported and soon joined the development of Mad_Fish . In the beginning, unit management was something like control in HabraWars. A player could turn a unit, fly forward and shoot if charged. The difference was in the possibility of a ram, which is almost meaningless for single battles, and in managing accelerations, not speed. Everyone invited to the DR was given the task: to come with his player. That is, bring it on a flash drive. It turned out that the created players were terribly stupid - the one who at least did not fire on his own and did not ram them won. Therefore, the non-shooting and non-moving player sometimes quite confidently won. After the holiday, I realized that avoiding rams, friendly fire and such things are routine things that are not interesting to play.

Simplicity



In practice, it became clear the need for extreme simplification of the management of units. Therefore, now there is an opportunity to write only what is interesting. I created standard implementations for the behavior of units and groups of units - the EtalonAI library.
For example, the code

foreach (UnitPilot pilot in friends) <br> pilot.AttackClosest(); <br><br> * This source code was highlighted with Source Code Highlighter .


is already an adequate algorithm for combat. A unit can also be ordered to hold a position, attack a specific enemy, fly to the indicated coordinates, or wait for orders. A unit has a list of units close to it, units, enemies that aim at it. As well as all units are available in the lists of friends and enemies.
To control a group of units, you can create a squad. The example creates a detachment of ten fighters.

DestroyersSquad1 = new SquadronColonel(friends[0], game);<br> for ( int i=0;i<10;i++)<br> DestroyersSquad1.AddUnit(friends[i]); <br>


Further, the whole squad can be sent to a given point.

DestroyersSquad1.GoToOrder( new GameVector(-3000, -2000)); <br>


You can order to move "through the attack"

DestroyersSquad1.AttackOrder( new GameVector(-3000, -2000)); <br><br>


You can set the type of building - line, rectangle, wedge or pack (without building).
DestroyersSquad1.SetFormationTypeLine(WidthBetweenUnits, AngleForward); <br>

Creating your own geometry is also possible.
There are also orders to attack the nearest enemy, ramming the enemies (by the way, a useful thing is to destroy the enemy cruiser with fighters)

It is just as easy to investigate the enemy - the class EnemyAnalyzing periodically conducts the clustering of enemies - that is, you can easily find out which teams your opponent has divided the fleet

Working with geometry is also taken into account - the GameVector vector class contains methods for rotation, vector math operators are overloaded. There is a class Angle, which allows you to fold the corners, without fear of getting a thousand degrees, to find the difference, the distance between the corners, etc. for more details see documentation.

Of course, standardization to such an extent excludes the possibility of creating a unique behavior of a unit, a particularly cool Jedi-Chacnor fighter, but the game is strategic in ideology. In addition, as mentioned above, there are two levels of abstraction of interaction with the game: the first is a high-level one, where the player indicates who to attack or where to fly the squad and what order; at the second level, the player indicates directly the linear acceleration, the acceleration of the rotation of the unit and the moment of the shot. So the units were controlled until the birthday. It turns out that the opportunity to get confused and make Chuck Norris remains.

Debugging



There are several ways to debug




The settings file allows

How to write a player


Writing "Hello world" and an adequate algorithm takes only a couple of minutes. The player can be written in any .NET language.
For this you need:

That's it. It's almost a complete guide.

Details



The game was written in C # using XNA, so pardon, Windows-only. After all, I did not expect to show anyone other than friends, but all the same, C # is a complete convenience. Mad Fish is now porting a game for Linux.
Control keys


Conclusion



I hope to develop the project further. For example, graphics are humanly done and all that. Mad_Fish is currently porting CodeCraft to OpenGL, and says that Microsoft shouldn’t depend on)
But the most interesting thing is of course to download a player written by one of you; look at his tactics; figure out how to beat it; load your player winning it and wait for the opponent's response.
Download strangers and add your players here.



Links




Records of games in CodeCraft. Participants are examples of players


Have a nice game

Source: https://habr.com/ru/post/75998/


All Articles