Created
January 18, 2018 17:23
-
-
Save wizardofrobots/ca25935525dc44c7a3c422fc02b8f485 to your computer and use it in GitHub Desktop.
Revisions
-
RobotWizard created this gist
Jan 18, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ const { vector, comm } = require("bytearena-sdk"); const Vector2 = vector.Vector2; const agent = comm.connect(); let count = 1 const countLimit = 55 let countDirection = 1 let first = true let angle = 0 agent.on("perception", perception => { const actions = [] let p = 1 let x = 0 let y = 1 let steering if (count === countLimit) { if (first === true) { if (angle != 0 ){ angle = 0 // console.log("zero") } else { // console.log("pi") angle = Math.PI } first=false } steering = navigate(perception, angle) // console.log(steering) if (steering.x == 0) { count = 1 first = true } } else { count += countDirection steering = new Vector2(0, 1) } // console.log(count) actions.push({ method: "steer", arguments: steering.toArray() }); agent.do(actions); }); const navigate = (perception, angle) => { let steering = null let x, y let p = 1 let error=angle-perception.azimuth if (Math.abs(error) > .01) { x =p * (angle - perception.azimuth) y = 1 } else { x = 0 } steering = new Vector2(x, y) return steering }