NUM_PLAYERS: 4,
FPS: 30,
WAIT_TIME: 60000, // 1 minute
- MAX_GAMES: 2, // the most games allowed to go on at once, to be tweaked as needed for purposes
- ROBO_TIME: 10, // time in seconds before filling out with robots
+ MAX_GAMES: 100, // the most games allowed to go on at once, to be tweaked as needed for purposes
+ ROBO_TIME: 5, // time in seconds before filling out with robots
// gamestate
DYING_TIME_IN_FRAMES: 100,
BOARD_RADIUS: 10,
MAX_INIT: 3, // initial speed constraints
BALL_RADIUS: 0.5,
MAX_SPEED: 15,
- SPEED_BUMP: 0.2,
+ SPEED_BUMP: 0.5,
// field
BOARD_RADIUS: 10, // completely arbitrary actually...
// paddle
const Coord = require('./coord.js');
const field = require('./field.js');
+const Endpoints = require('./endpoints.js');
+const Paddle = require('./paddles.js'); // hacky? not too hacky.
function Robot() {
this.status = 'x';
this.status = Math.random()>0.5 ? 'u' : 'd';
}
Robot.prototype.standard_ai = function(data) {
+ if(typeof data == "string")
+ return;
+ if(data.balls.length == 0)
+ return;
+ var me = data.id;
+ var eps = field.genAllEndpoints(data.n, data.dead);
+ var my_ep = eps.find(x => x.id == me);
+ if(typeof my_ep == 'undefined') {
+ this.status = 'x';
+ return;
+ }
+ var center = ep_midpoint(my_ep);
+ var nearest = data.balls[0];
+ var bdist2 = center.dist2(nearest);
+ for(var ball of data.balls) {
+ var newdist = center.dist2(ball);
+ if(newdist < bdist2) {
+ nearest = ball;
+ bdist2 = newdist;
+ }
+ }
+ var theta = Math.atan2(my_ep.s.y-my_ep.f.y, my_ep.s.x-my_ep.f.x);
+ // not totally sure if i need this copy, dunno where else the object is used...
+ var nearest_mod = new Coord(nearest.x, nearest.y)
+ nearest_mod.translate(center.x, center.y);
+ nearest_mod.rotate(-theta);
+ // now i get the paddle's relative position along the line, and use that to compare with
+ if(!data.paddles.some(p => p.id==data.id))
+ return;
+ var my_paddle = data.paddles.find(p => p.id == data.id);
+ // largely stolen from getPaddlePoints
+ var ep_len = my_ep.getLength();
+ var pspace_len = ep_len-c.WIDTH_RATIO*ep_len;
+ var idk_len = (ep_len-pspace_len)/2;
+ var paddle_ratio = (my_paddle.pos+1)/2;
+ var center_pos = idk_len+paddle_ratio*pspace_len;
+ if(data.id==2)
+ console.log(nearest_mod.x < center_pos, nearest_mod.x, center_pos);
+ this.status = (nearest_mod.x < center_pos) ? 'd' : 'u';
+}
+
+
+
+
+Robot.prototype.bad_ai = function(data) {
if(typeof data == "string")
return;
if(data.balls.length == 0)
var midpoint = function(a,b) {
return new Coord((a.x+b.x/2), (a.y+b.y)/2);
}
-
+var ep_midpoint = function(e) {
+ return midpoint(e.f, e.s);
+}
module.exports = Robot;