From 5a1f4d171989f460372cc772fce6399f3198d779 Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Tue, 14 May 2019 18:28:02 -0500 Subject: [PATCH] boutta nuke some junk, getting it recorded first in case it's a bad idea (it's not) --- TODO.org | 5 +++-- server/constants.js | 6 +++--- server/robot.js | 51 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/TODO.org b/TODO.org index 19fdde6..c630992 100644 --- a/TODO.org +++ b/TODO.org @@ -1,5 +1,6 @@ important: - -list of things i should still do: +- fix the robots +- paddle movement bump - fix collisions +- more balls - fiddle with variables to optimize fun diff --git a/server/constants.js b/server/constants.js index 5d21ea4..3f12a3d 100644 --- a/server/constants.js +++ b/server/constants.js @@ -6,8 +6,8 @@ var c = { 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, @@ -19,7 +19,7 @@ var c = { 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 diff --git a/server/robot.js b/server/robot.js index 0c1c356..cba2dd2 100644 --- a/server/robot.js +++ b/server/robot.js @@ -3,6 +3,8 @@ const c = require('./constants.js'); 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'; @@ -28,6 +30,51 @@ Robot.prototype.random_ai = function(data) { 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) @@ -66,6 +113,8 @@ Robot.prototype.standard_ai = function(data) { 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; -- 2.39.2