HabraWars: Graphic debug
You probably already know the idea of HabraWars, the last of the topics announces the first tournament. Which will happen today. Registration of new participants will be after November 20.
The rules and code of the sample robot are enough to start writing your conqueror of the pedestal. But debugging with just the FireBug console may not be clear enough. It is much more convenient to receive information while thinking of the robot directly to the arena.
And for this, it’s enough just to clear the field at the beginning of the tick and Canvas be transferred to the function of the thought process: And in the robot code add a parameter: Now you can draw debugging in the body of the thought function: And then convenience and visualization will come:

Or it’s even more convenient to show the forecast of the position of the enemy robot:

PS: Unfortunately, until these changes appear in the main battle engine, you will have to develop your robot offline. And of course, before moving the code online, you need to remove references to this_canvas from the robot code.
The rules and code of the sample robot are enough to start writing your conqueror of the pedestal. But debugging with just the FireBug console may not be clear enough. It is much more convenient to receive information while thinking of the robot directly to the arena.
And for this, it’s enough just to clear the field at the beginning of the tick and Canvas be transferred to the function of the thought process: And in the robot code add a parameter: Now you can draw debugging in the body of the thought function: And then convenience and visualization will come:
...
this.culc_frame = function() {
// Mutex
if (mutex)
return;
else
mutex = true;
// clear Area is now separated from draw
var padding = 10;
this.canvas.fillStyle = 'black';
this.canvas.fillRect(0, 0, this.canvas_width - 1, this.canvas_height - 1);
this.canvas.strokeStyle = 'white';
this.canvas.lineWidth = 1;
this.canvas.strokeRect(padding, padding, this.arena_width, this.arena_height);
...
control = this.shells[i].action(robot_info[i], robot_info.filter(exclude_myself), shot_info, {arena_width: this.arena_width, arena_height: this.arena_height, robot_radius: this.robot_radius, shot_speed: 12},engine.canvas);
...
// Draws current frame on canvas from string
// Using string params useful for battle replays
this.draw = function(situation) {
// Clear Background
var padding = 10;
this.canvas.fillStyle = 'black';
this.canvas.fillRect(0, 0, this.canvas_width - 1, this.canvas_height - 1);
this.canvas.strokeStyle = 'white';
this.canvas.lineWidth = 1;
this.canvas.strokeRect(padding, padding, this.arena_width, this.arena_height);
// Draw robots
current_index = 0;
...
this.action = function(my_state, enemies, shots, params,this_canvas) // На пример места, куда попадут летящие сейчас снаряды
for (var i = 0; i < shots.length; i++)
{
var shot_dest = get_shot_destination(shots[i]);
this_canvas.globalAlpha = 0.3;
this_canvas.beginPath();
this_canvas.arc(10 + shot_dest.x, 10 + shot_dest.y, 20, 0, Math.PI * 2, true);
this_canvas.closePath();
this_canvas.fillStyle = 'red';
this_canvas.fill();
this_canvas.globalAlpha = 1;
}

Or it’s even more convenient to show the forecast of the position of the enemy robot:

PS: Unfortunately, until these changes appear in the main battle engine, you will have to develop your robot offline. And of course, before moving the code online, you need to remove references to this_canvas from the robot code.