Skip to content

Commit 202181b

Browse files
committed
Tests should fail if the robot has collided with an obstacle
1 parent 424f456 commit 202181b

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/bundles/robot_minigame/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export function turn_right() {
367367
* @returns if all tests pass
368368
*/
369369
export function run_all_tests() : boolean {
370-
return run_tests(state);
370+
return !state.hasCollided && run_tests(state);
371371
}
372372

373373
// ==================

src/tabs/RobotMaze/components/RobotSimulation.tsx renamed to src/tabs/RobotMaze/RobotSimulation.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useRef, useState } from 'react';
2-
import { run_tests } from '../../../bundles/robot_minigame/helpers/tests';
3-
import type { Area, Action, Robot, RobotMinigame } from '../../../bundles/robot_minigame/types';
2+
import { run_tests } from '../../bundles/robot_minigame/helpers/tests';
3+
import type { Area, Action, Robot, RobotMinigame } from '../../bundles/robot_minigame/types';
44

55
/**
66
* Calculate the acute angle between 2 angles
@@ -130,6 +130,7 @@ interface MapProps {
130130

131131
const RobotSimulation : React.FC<MapProps> = ({
132132
state: {
133+
hasCollided,
133134
width,
134135
height,
135136
robot: {radius: robotSize},
@@ -276,7 +277,7 @@ const RobotSimulation : React.FC<MapProps> = ({
276277
: animationStatus === 2
277278
? <button onClick={() => {setAnimationStatus(1);}}>Resume</button>
278279
: <button onClick={() => {setAnimationStatus(0);}}>Reset</button>}
279-
{animationStatus === 3 && <span style={{marginLeft: '5px'}}>{run_tests({tests, areaLog}) ? 'Success! 🎉' : message}</span>}
280+
{animationStatus === 3 && <span style={{marginLeft: '5px'}}>{!hasCollided && run_tests({tests, areaLog}) ? 'Success! 🎉' : message}</span>}
280281
</div>
281282
<div style={{display: 'flex', justifyContent: 'center'}}>
282283
<canvas ref={canvasRef}/>

src/tabs/RobotMaze/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import type { DebuggerContext } from '../../typings/type_helpers';
3-
import RobotSimulation from './components/RobotSimulation';
3+
import RobotSimulation from './RobotSimulation';
44

55
/**
66
* Renders the robot minigame in the assessment workspace

0 commit comments

Comments
 (0)