File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -2,22 +2,45 @@ const WebSocket = require('ws')
22
33const wss = new WebSocket . Server ( { port : 9999 } )
44
5+ const pseudoObstacle = angle => {
6+ if ( angle > 45 && angle < 90 ) {
7+ return 20
8+ } else if ( angle > 110 && angle < 150 ) {
9+ return 30
10+ } else {
11+ return 45
12+ }
13+ }
14+
15+ const distanceRandomizer = angle =>
16+ Math . floor ( Math . random ( ) * 2 ) + pseudoObstacle ( angle )
17+
518function * gen ( ) {
619 let angle = 0
720 while ( angle <= 180 ) {
8- yield { angle, distance : Math . floor ( Math . random ( ) * 30 ) }
21+ yield { angle, distance : distanceRandomizer ( angle ) }
922 angle ++
1023 }
24+ yield * invGen ( )
25+ }
26+
27+ function * invGen ( ) {
28+ let angle = 180
29+ while ( angle >= 0 ) {
30+ yield { angle, distance : distanceRandomizer ( angle ) }
31+ angle --
32+ }
1133 yield * gen ( )
1234}
1335
36+
1437wss . on ( 'connection' , function connection ( ws ) {
1538
1639 const data = gen ( )
1740
1841 const id = setInterval ( ( ) => {
1942 ws . send ( JSON . stringify ( data . next ( ) . value ) )
20- } , 20 )
43+ } , 10 )
2144
2245 ws . on ( 'close' , ( ) => {
2346 clearInterval ( id )
You can’t perform that action at this time.
0 commit comments