Skip to content

Commit

Permalink
Merge pull request #23 from project-neon/feature/rogerioceni-vc-gerra…
Browse files Browse the repository at this point in the history
…rd-2005

Feature/rogerioceni vc gerrard 2005
  • Loading branch information
Alexsandr0x authored Feb 26, 2020
2 parents 0d39fa9 + 2cd547f commit 0935acc
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 80 deletions.
11 changes: 7 additions & 4 deletions lib/DumbCoach.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module.exports = class Coach {

this.currentOrder = {}

this.goalKeeper = null

this.init()
}

Expand All @@ -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) {
Expand All @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion lib/GameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
10 changes: 10 additions & 0 deletions lib/TensorMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 10 additions & 5 deletions players/experimental/AttackerMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -82,14 +80,21 @@ 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"),
lineSize: 1700,
lineDist: 100,
lineDistMax: 100,
decay: TensorMath.new.sum(1).mult(-1).finish,
multiplier: BASE_SPEED * 4
multiplier: BASE_SPEED
})
this.addIntetion(this.avoidFieldWalls3)

Expand Down
6 changes: 3 additions & 3 deletions players/experimental/AttackerTriangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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
}))

Expand All @@ -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', {
Expand Down
71 changes: 31 additions & 40 deletions players/experimental/GoalKeeperPush2.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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(){
Expand Down
23 changes: 12 additions & 11 deletions players/experimental/GoalkeeperMain2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,17 +27,17 @@ 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
this.addIntetion(new LineIntention('KeepOnBall', {
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
}))

/*
Expand All @@ -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
}))
}

Expand Down
13 changes: 7 additions & 6 deletions roles/AttackerRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
14 changes: 7 additions & 7 deletions roles/GoalkeeperRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
10 changes: 7 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,16 +57,20 @@ 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
},
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}
},
{

}
]
})
Expand Down

0 comments on commit 0935acc

Please sign in to comment.