@@ -6,12 +6,12 @@ import {
66} from 'js-slang/dist/stdlib/list' ;
77
88type Point = { x : number , y : number } ;
9- type PointWithRotation = { x : number , y : number , angle : number }
9+ type PointWithRotation = { x : number , y : number , angle : number } ;
1010
1111type CommandData = {
12- type : String ,
12+ type : string ,
1313 location : PointWithRotation
14- }
14+ } ;
1515
1616type Polygon = Point [ ] ;
1717
@@ -128,7 +128,7 @@ export function rotate_right(angle: number) {
128128
129129 robot . dx = Math . cos ( currentAngle ) ;
130130 robot . dy = - Math . sin ( currentAngle ) ;
131-
131+
132132 if ( robot . dx < 0.00001 && robot . dx > - 0.00001 ) robot . dx = 0 ;
133133 if ( robot . dy < 0.00001 && robot . dy > - 0.00001 ) robot . dy = 0 ;
134134
@@ -163,9 +163,9 @@ export function set_rect_wall(x: number, y: number, width: number, height: numbe
163163}
164164
165165// creates irregularly shaped wall
166- // takes in a list of vertices as its argument
166+ // takes in a list of vertices as its argument
167167export function set_polygon_wall ( vertices : List ) {
168- const polygon : Polygon = [ ]
168+ const polygon : Polygon = [ ] ;
169169
170170 while ( vertices != null ) {
171171 const p = head ( vertices ) ;
@@ -184,20 +184,20 @@ export function getY():number {
184184 return robot . y ;
185185}
186186
187- // moves robot to the nearest wall
187+ // moves robot to the nearest wall
188188export function move_forward_to_wall ( ) : void {
189189 if ( alrCollided ( ) ) return ;
190190
191191 let distance = findMoveDistance ( ) ; // do the raycast, figure out how far the robot is from the nearest wall
192192
193193 // a lil extra offset from wall
194- distance = Math . max ( distance - robot . radius - 5 , 0 )
195-
194+ distance = Math . max ( distance - robot . radius - 5 , 0 ) ;
195+
196196 const nextPoint : Point = {
197197 x : robot . x + distance * robot . dx ,
198198 y : robot . y + distance * robot . dy
199- }
200-
199+ } ;
200+
201201 robot . x = nextPoint . x ;
202202 robot . y = nextPoint . y ;
203203 stateData . movePoints . push ( nextPoint ) ;
@@ -206,12 +206,12 @@ export function move_forward_to_wall(): void {
206206 stateData . messages . push ( `Distance is ${ distance } Collision point at x: ${ nextPoint . x } , y: ${ nextPoint . y } ` ) ;
207207}
208208
209- // Moves forward by a small amount
209+ // Moves forward by a small amount
210210export function move_forward ( moveDist : number ) : void {
211211 const nextPoint : Point = {
212212 x : robot . x + moveDist * robot . dx ,
213213 y : robot . y + moveDist + robot . dy
214- }
214+ } ;
215215
216216 // need to check for collision with wall
217217
@@ -226,31 +226,31 @@ export function sensor(): boolean {
226226 return false ;
227227}
228228
229- // returns the distance from the nearest wall
229+ // returns the distance from the nearest wall
230230function findMoveDistance ( ) : number {
231231 let minDist : number = Infinity ;
232232
233233 // loop through all the walls
234234 for ( const wall of stateData . walls ) {
235- const intersectionDist = raycast ( wall ) ; // do the raycast
235+ const intersectionDist = raycast ( wall ) ; // do the raycast
236236
237237 // if intersection is closer, update minDist
238238 if ( intersectionDist !== null && intersectionDist < minDist ) {
239239 minDist = intersectionDist ;
240- }
240+ }
241241 }
242242
243243 // check outer bounds as well
244244 const intersectionDist = raycast ( bounds ) ;
245245 if ( intersectionDist !== null && intersectionDist < minDist ) {
246246 minDist = intersectionDist ;
247- }
248-
247+ }
248+
249249 // Closest intersection point
250- // By all rights, there should always be an intersection point since the robot is always within the bounds
250+ // By all rights, there should always be an intersection point since the robot is always within the bounds
251251 // and the bounds should be a collision
252252 // but something goes wrong, will just return 0
253- return minDist === Infinity ? 0 : minDist ;
253+ return minDist === Infinity ? 0 : minDist ;
254254}
255255
256256// does the raycast logic for one particular wall
@@ -264,7 +264,7 @@ function raycast(polygon: Polygon): number | null {
264264 const x1 = polygon [ i ] . x , y1 = polygon [ i ] . y ;
265265 const x2 = polygon [ ( i + 1 ) % polygon . length ] . x , y2 = polygon [ ( i + 1 ) % polygon . length ] . y ;
266266
267- // calculate the top and bottom coordinates of the robot
267+ // calculate the top and bottom coordinates of the robot
268268 const topX = robot . x - robot . radius * robot . dy ;
269269 const topY = robot . y - robot . radius * robot . dx ;
270270
@@ -276,7 +276,7 @@ function raycast(polygon: Polygon): number | null {
276276 { x : robot . x , y : robot . y } ,
277277 { x : topX , y : topY } ,
278278 { x : bottomX , y : bottomY }
279- ]
279+ ] ;
280280
281281 for ( const source of raycast_sources ) {
282282 const intersectionDist = getIntersection ( source . x , source . y , robot . dx + source . x , robot . dy + source . y , x1 , y1 , x2 , y2 ) ;
@@ -285,7 +285,7 @@ function raycast(polygon: Polygon): number | null {
285285 }
286286 }
287287 }
288-
288+
289289 return minDist === Infinity ? null : minDist ;
290290}
291291
@@ -320,7 +320,7 @@ function getIntersection(x1, y1, x2, y2, x3, y3, x4, y4): number | null {
320320 }
321321
322322 if ( ! b ) return null ;
323-
323+
324324 return r ;
325325}
326326
@@ -330,5 +330,5 @@ function alrCollided() {
330330
331331// debug
332332function logCoordinates ( ) {
333- stateData . messages . push ( `x: ${ robot . x } , y: ${ robot . y } , dx: ${ robot . dx } , dy: ${ robot . dy } ` )
333+ stateData . messages . push ( `x: ${ robot . x } , y: ${ robot . y } , dx: ${ robot . dx } , dy: ${ robot . dy } ` ) ;
334334}
0 commit comments