diff --git a/lib/DumbCoach.js b/lib/DumbCoach.js index a776d75..572ea87 100644 --- a/lib/DumbCoach.js +++ b/lib/DumbCoach.js @@ -13,6 +13,8 @@ module.exports = class Coach { this.currentOrder = {} + this.goalKeeper = null + this.init() } @@ -39,6 +41,8 @@ module.exports = class Coach { this.goalKeeper = new GoalKeeper(this.match) this.attacker = new Attacker(this.match) + + this.attacker2 = new Attacker(this.match) } async decide(data, robots) { @@ -59,13 +63,12 @@ module.exports = class Coach { let it = 0 _.values(robots).map(robot => { - if (robot.radioId == 2) { + if (robot.radioId == 1) { this.goalKeeper.decidePlay(robot, data) - } else if (robot.radioId == 1) { + } else if (robot.radioId == 2) { this.attacker.decidePlay(robot, data) } else { - robot.runningPlay = this.dumbRobots[it] - this.dumbRobots[it].setRobot(robot) + this.attacker2.decidePlay(robot, data) } it += 1 }) diff --git a/lib/GameManager.js b/lib/GameManager.js index 2c01cff..f0c2482 100644 --- a/lib/GameManager.js +++ b/lib/GameManager.js @@ -84,7 +84,7 @@ module.exports = class GameManager { if (this.coaches.length > 1){ await this.coaches[1].decide(data[sides[1]], rivalTeamRobots) } - + let promises = _.values(this.robots).map(robot => { let teamId = robot.teamId let teamData = data[sides[teamId]] diff --git a/lib/TensorMath.js b/lib/TensorMath.js index c352e61..6fe9179 100644 --- a/lib/TensorMath.js +++ b/lib/TensorMath.js @@ -90,6 +90,16 @@ class TensorMath { this.operations.push(x => x < min ? 0 : (x > max ? 0 : x)) return this } + // Rampa de aceleração para se aproximar da bola + sigmoid () { + this.operations.push(x => (1/(1 + Math.exp(-(10*x -6))))) + return this + } + + sin () { + this.operations.push(x => Math.sin(x)) + return this + } toFixed (n) { this.operations.push(x => x.toFixed(n)) diff --git a/players/experimental/AttackerMain.js b/players/experimental/AttackerMain.js index 6de9fd7..081ce0d 100644 --- a/players/experimental/AttackerMain.js +++ b/players/experimental/AttackerMain.js @@ -8,8 +8,6 @@ const RulePlays = require('./RulePlays') const BASE_SPEED = 50 -let robot_saw_the_ball_multiplier = 0.5 - module.exports = class AttackerMain extends RulePlays { setup(){ super.setup() @@ -54,7 +52,7 @@ module.exports = class AttackerMain extends RulePlays { clockwise: -1, radius: 75, decay: TensorMath.new.finish, - multiplier: BASE_SPEED + multiplier: BASE_SPEED * 0.7 }) this.addIntetion(this.orbitalRight) @@ -64,7 +62,7 @@ module.exports = class AttackerMain extends RulePlays { clockwise: 1, radius: 75, decay: TensorMath.new.finish, - multiplier: BASE_SPEED + multiplier: BASE_SPEED * 0.7 }) this.addIntetion(this.orbitalLeft) @@ -82,6 +80,13 @@ module.exports = class AttackerMain extends RulePlays { multiplier: BASE_SPEED })) + this.addIntetion(new PointIntention('KeepOnBall', { + target: ball, + radius: 500, + decay: TensorMath.new.sin().finish, + multiplier: BASE_SPEED * 0.7 + })) + this.avoidFieldWalls3 = new LineIntention('avoidFieldWalls3', { target: {x:-780, y: 0}, theta: Vector.direction("up"), @@ -89,7 +94,7 @@ module.exports = class AttackerMain extends RulePlays { lineDist: 100, lineDistMax: 100, decay: TensorMath.new.sum(1).mult(-1).finish, - multiplier: BASE_SPEED * 4 + multiplier: BASE_SPEED }) this.addIntetion(this.avoidFieldWalls3) diff --git a/players/experimental/AttackerTriangle.js b/players/experimental/AttackerTriangle.js index fd4d6ec..9fadf8d 100644 --- a/players/experimental/AttackerTriangle.js +++ b/players/experimental/AttackerTriangle.js @@ -8,7 +8,7 @@ const OrbitalIntention = require('../../Intention/OrbitalIntention') const Vector = require('../../lib/Vector') const RulePlays = require('./RulePlays') -const BASE_SPEED = 75 +const BASE_SPEED = 70 module.exports = class AttackerTriangle extends RulePlays { setup () { @@ -47,7 +47,7 @@ this.addIntetion(new LineIntention('To the goal', { lineDist: 200, lineDistMax: 200, decay: TensorMath.new.finish, - multiplier: BASE_SPEED *1.1, + multiplier: BASE_SPEED, lineDistSingleSide: true })) @@ -58,7 +58,7 @@ this.addIntetion(new LineIntention('Keep eye on goal', { lineDist: 200, lineDistMax: 200, decay: TensorMath.new.finish, - multiplier: BASE_SPEED + multiplier: BASE_SPEED * 1.2 })) this.addIntetion(new PointIntention('goBall', { diff --git a/players/experimental/GoalKeeperPush2.js b/players/experimental/GoalKeeperPush2.js index ed3e670..547955f 100644 --- a/players/experimental/GoalKeeperPush2.js +++ b/players/experimental/GoalKeeperPush2.js @@ -1,10 +1,11 @@ const TensorMath = require('../../lib/TensorMath') const LineIntention = require('../../Intention/LineIntention') const PointIntention = require('../../Intention/PointIntention') +const LookAtIntention = require('../../Intention/LookAtIntention') const RulePlays = require('./RulePlays') const Vector = require('../../lib/Vector') -const BASE_SPEED = 40 +const BASE_SPEED = 60 const GOAL_LINE = -670 module.exports = class GoalkeeperPush2 extends RulePlays { @@ -14,47 +15,37 @@ module.exports = class GoalkeeperPush2 extends RulePlays { let ball = {x: this.frame.cleanData.ball.x, y: this.frame.cleanData.ball.y} return ball } - // Fixar goleiro na linha do gol this.addIntetion(new LineIntention('KeepGoalLine', { - target: {x: GOAL_LINE, y: 0}, - theta: Vector.direction("up"), - lineSize: 1700, - lineDist: 260, - decay: TensorMath.new.finish, - multiplier: BASE_SPEED - })) - - //Mantem o goleiro fixado na bola, seguindo eixo Y - this.addIntetion(new LineIntention('KeepOnBall', { - target: ball, - theta: Vector.direction("left"), - lineSize: 1700, - lineDist: 250, - decay: TensorMath.new.finish, - multiplier: BASE_SPEED * 1.2 - })) - - /* - Correção na função para o goleiro ter mais velocidade - em casos de bola muito proxima do eixo Y - */ - this.addIntetion(new LineIntention('KeepOnBall', { - target: ball, - theta: Vector.direction("left"), - lineSize: 400, - lineDist: 150, - decay: TensorMath.new.finish, - multiplier: BASE_SPEED * 1.2 - })) - - this.addIntetion(new PointIntention('PushBall', { - target: ball, - radius: 50, - radiusMax: 50, - decay: TensorMath.new.finish, - multiplier: BASE_SPEED * 1.8 - })) + target: {x: GOAL_LINE, y: 0}, + theta: Vector.direction("up"), + lineSize: 1700, + lineDist: 260, + decay: TensorMath.new.finish, + multiplier: BASE_SPEED * 1.6 + })) + + //Mantem o goleiro fixado na bola, seguindo eixo Y + this.addIntetion(new LineIntention('KeepOnBall', { + target: ball, + theta: Vector.direction("left"), + lineSize: 1700, + lineDist: 250, + decay: TensorMath.new.finish, + multiplier: BASE_SPEED * 1.4 + })) + + /* + Correção na função para o goleiro ter mais velocidade + em casos de bola muito proxima do eixo Y + */ + this.addIntetion(new PointIntention('KeepOnBall', { + target: ball, + radius: 100, + radiusMax: 100, + decay: TensorMath.new.finish, + multiplier: BASE_SPEED * 1.4 + })) } loop(){ diff --git a/players/experimental/GoalkeeperMain2.js b/players/experimental/GoalkeeperMain2.js index 88c9e3e..cd66a8d 100644 --- a/players/experimental/GoalkeeperMain2.js +++ b/players/experimental/GoalkeeperMain2.js @@ -4,17 +4,17 @@ const LookAtIntention = require('../../Intention/LookAtIntention') const Vector = require('../../lib/Vector') const RulePlays = require('./RulePlays') -const BASE_SPEED = 40 +const BASE_SPEED = 50 const MAX_SPEED = 80 -const GOAL_LINE = -670 +const GOAL_LINE = -650 module.exports = class GoalkeeperMain2 extends RulePlays { setup(){ super.setup() let ball = () => { let ball = { - x: this.frame.cleanData.ball.x, + x: this.frame.cleanData.ball.x, y: Math.max(Math.min(this.frame.cleanData.ball.y, 200), -200) } return ball @@ -27,7 +27,7 @@ module.exports = class GoalkeeperMain2 extends RulePlays { lineSize: 1700, lineDist: 260, decay: TensorMath.new.finish, - multiplier: BASE_SPEED * 1.6 + multiplier: BASE_SPEED * 1.4 })) //Mantem o goleiro fixado na bola, seguindo eixo Y @@ -35,9 +35,9 @@ module.exports = class GoalkeeperMain2 extends RulePlays { target: ball, theta: Vector.direction("left"), lineSize: 1700, - lineDist: 250, - decay: TensorMath.new.finish, - multiplier: BASE_SPEED * 1.4 + lineDist: 80, + decay: TensorMath.new.pow(2).finish, + multiplier: BASE_SPEED })) /* @@ -47,16 +47,17 @@ module.exports = class GoalkeeperMain2 extends RulePlays { this.addIntetion(new LineIntention('KeepOnBall', { target: ball, theta: Vector.direction("left"), - lineSize: 400, - lineDist: 150, - decay: TensorMath.new.finish, + lineSize: 600, + lineDist: 200, + lineDistMax: 200, + decay: TensorMath.new.pow(2).finish, multiplier: BASE_SPEED * 1.4 })) this.addIntetion(new LookAtIntention('LookAtBall', { target: ball, decay: TensorMath.new.pow(1/2).finish, - multiplier: 680 + multiplier: 320 })) } diff --git a/roles/AttackerRole.js b/roles/AttackerRole.js index 0a9a949..a3b9448 100644 --- a/roles/AttackerRole.js +++ b/roles/AttackerRole.js @@ -30,9 +30,9 @@ module.exports = class AttackerRole { buildTriangle (robot) { return { x1: GP.x, - y1: GP.y, + y1: GP.y - 100, x2: GP.x, - y2: -GP.y, + y2: -GP.y + 100, x3: robot.robots.self.position.x, y3: robot.robots.self.position.y @@ -59,12 +59,13 @@ module.exports = class AttackerRole { robot.runningPlay = this.plays.triangle this.plays.triangle.setRobot(robot) } else if (this.insideFieldConstraint(SMALL_AREA, ball)) { - robot.runningPlay = this.plays.hold - this.plays.hold.setRobot(robot) + robot.runningPlay = this.plays.hold + this.plays.hold.setRobot(robot) } else { - robot.runningPlay = this.plays.main - this.plays.main.setRobot(robot) + robot.runningPlay = this.plays.main + this.plays.main.setRobot(robot) } + console.log('|robot' + robot.radioId + '| decided play: ' + robot.runningPlay.constructor.name) } } diff --git a/roles/GoalkeeperRole.js b/roles/GoalkeeperRole.js index d305673..e5c889c 100644 --- a/roles/GoalkeeperRole.js +++ b/roles/GoalkeeperRole.js @@ -28,24 +28,24 @@ module.exports = class GoalKeeperRole { } decidePlay(robot, data) { - + const ball = data.cleanData.ball if( - this.insideFieldConstraint(FieldConstraints.GOAL_INNER_AREA, ball) + this.insideFieldConstraint(FieldConstraints.SMALL_AREA, ball) ){ - robot.runningPlay = this.plays.main - this.plays.main.setRobot(robot) + robot.runningPlay = this.plays.push + this.plays.push.setRobot(robot) } else if ( - this.insideFieldConstraint(FieldConstraints.LEFT, ball) + this.insideFieldConstraint(FieldConstraints.LEFT, ball) || this.insideFieldConstraint(FieldConstraints.RIGHT, ball) ) { robot.runningPlay = this.plays.sides this.plays.sides.setRobot(robot) - }else{ + } else{ robot.runningPlay = this.plays.main this.plays.main.setRobot(robot) } console.log('|robot' + robot.radioId + '| decided play: ' + robot.runningPlay.constructor.name) } -} \ No newline at end of file +} diff --git a/server.js b/server.js index 0f5c238..d36233d 100644 --- a/server.js +++ b/server.js @@ -38,7 +38,7 @@ async function startup(){ visionImpl = 'simple-simulation-vision' driverImpl = 'simple-simulation-driver' break - case 3: + case 3: visionImpl = 'vss-vision' driverImpl = 'vss-driver' break @@ -57,7 +57,7 @@ async function startup(){ // Driver: dados referentes ao output de dados de envio para os robos vision: {impl: visionImpl, params: config[visionImpl]}, driver: {impl: driverImpl, params: config[driverImpl]}, - coaches: [CoachClass], + coaches: [CoachClass, CoachClass], matchParams: { 'startSide': config.startSide, 'startColor': config.startColor @@ -65,8 +65,12 @@ async function startup(){ robotsProperties:[ { // TEAM 1 - robot_0: {vision_id: 1, radio_id: 2}, + robot_2: {vision_id: 1, radio_id: 3}, + robot_3: {vision_id: 9, radio_id: 2}, robot_1: {vision_id: 3, radio_id: 1} + }, + { + } ] })