@@ -70,7 +70,6 @@ export function set_rotation(rotation: number) {
7070 robot . dy = - Math . sin ( rotation ) ;
7171}
7272
73-
7473export function set_width ( width : number ) {
7574 stateData . width = width ;
7675}
@@ -88,7 +87,7 @@ export function init(width: number, height: number, posX: number, posY: number,
8887 set_pos ( posX , posY ) ;
8988 set_rotation ( rotation ) ;
9089
91- stateData . moveCommands . push ( { type : " begin" , position : getPositionWithRotation ( ) } ) ; // push starting point to movepoints data
90+ stateData . moveCommands . push ( { type : ' begin' , position : getPositionWithRotation ( ) } ) ; // push starting point to movepoints data
9291 stateData . isInit = true ;
9392
9493 bounds = [
@@ -111,13 +110,12 @@ export function turn_left() {
111110 if ( robot . dx < 0.00001 && robot . dx > - 0.00001 ) robot . dx = 0 ;
112111 if ( robot . dy < 0.00001 && robot . dy > - 0.00001 ) robot . dy = 0 ;
113112
114- stateData . moveCommands . push ( { type : " rotateLeft" , position : getPositionWithRotation ( ) } ) ;
113+ stateData . moveCommands . push ( { type : ' rotateLeft' , position : getPositionWithRotation ( ) } ) ;
115114
116115 // debug log
117116 logCoordinates ( ) ;
118117}
119118
120-
121119export function turn_right ( ) {
122120 let currentAngle = Math . atan2 ( - robot . dy , robot . dx ) ;
123121
@@ -129,7 +127,7 @@ export function turn_right() {
129127 if ( robot . dx < 0.00001 && robot . dx > - 0.00001 ) robot . dx = 0 ;
130128 if ( robot . dy < 0.00001 && robot . dy > - 0.00001 ) robot . dy = 0 ;
131129
132- stateData . moveCommands . push ( { type : " rotateRight" , position : getPositionWithRotation ( ) } ) ;
130+ stateData . moveCommands . push ( { type : ' rotateRight' , position : getPositionWithRotation ( ) } ) ;
133131
134132 // debug log
135133 logCoordinates ( ) ;
@@ -146,7 +144,7 @@ export function rotate_right(angle: number) {
146144 if ( robot . dx < 0.00001 && robot . dx > - 0.00001 ) robot . dx = 0 ;
147145 if ( robot . dy < 0.00001 && robot . dy > - 0.00001 ) robot . dy = 0 ;
148146
149- stateData . moveCommands . push ( { type : " rotateRight" , position : getPositionWithRotation ( ) } ) ;
147+ stateData . moveCommands . push ( { type : ' rotateRight' , position : getPositionWithRotation ( ) } ) ;
150148
151149 // debug log
152150 logCoordinates ( ) ;
@@ -163,7 +161,7 @@ export function rotate_left(angle: number) {
163161 if ( robot . dx < 0.00001 && robot . dx > - 0.00001 ) robot . dx = 0 ;
164162 if ( robot . dy < 0.00001 && robot . dy > - 0.00001 ) robot . dy = 0 ;
165163
166- stateData . moveCommands . push ( { type : " rotateLeft" , position : getPositionWithRotation ( ) } ) ;
164+ stateData . moveCommands . push ( { type : ' rotateLeft' , position : getPositionWithRotation ( ) } ) ;
167165
168166 logCoordinates ( ) ;
169167}
@@ -218,7 +216,7 @@ export function move_forward_to_wall(): void {
218216
219217 robot . x = nextPoint . x ;
220218 robot . y = nextPoint . y ;
221- stateData . moveCommands . push ( { type : " move" , position : getPositionWithRotation ( ) } ) ;
219+ stateData . moveCommands . push ( { type : ' move' , position : getPositionWithRotation ( ) } ) ;
222220
223221 // for debug
224222 stateData . messages . push ( `Distance is ${ distance } Collision point at x: ${ nextPoint . x } , y: ${ nextPoint . y } ` ) ;
@@ -229,9 +227,9 @@ export function move_forward(moveDist: number): void {
229227 // need to check for collision with wall
230228 const dist = findDistanceToWall ( ) ;
231229 stateData . messages . push ( `${ dist } ` ) ;
232-
230+
233231 if ( dist < moveDist + robot . radius ) {
234- stateData . message = " collided" ;
232+ stateData . message = ' collided' ;
235233 stateData . success = false ;
236234 moveDist = dist - robot . radius + 1 ; // move only until the wall
237235 }
@@ -243,7 +241,7 @@ export function move_forward(moveDist: number): void {
243241
244242 robot . x = nextPoint . x ;
245243 robot . y = nextPoint . y ;
246- stateData . moveCommands . push ( { type : " move" , position : getPositionWithRotation ( ) } ) ;
244+ stateData . moveCommands . push ( { type : ' move' , position : getPositionWithRotation ( ) } ) ;
247245
248246 logCoordinates ( ) ;
249247}
@@ -252,7 +250,7 @@ export function move_forward(moveDist: number): void {
252250// add as a command later
253251export function sensor ( ) : boolean {
254252 const dist = findDistanceToWall ( ) ;
255- stateData . moveCommands . push ( { type : " sensor" , position : getPositionWithRotation ( ) } )
253+ stateData . moveCommands . push ( { type : ' sensor' , position : getPositionWithRotation ( ) } ) ;
256254 if ( dist <= 10 + robot . radius ) {
257255 return true ;
258256 }
@@ -363,7 +361,7 @@ function alrCollided() {
363361
364362function getPositionWithRotation ( ) : PointWithRotation {
365363 const angle = Math . atan2 ( - robot . dy , robot . dx ) ;
366- return { x : robot . x , y : robot . y , rotation : angle }
364+ return { x : robot . x , y : robot . y , rotation : angle } ;
367365}
368366
369367// debug
0 commit comments