diff --git a/src/simulator/definitions/challenges/jbc22-Search-and-Rescue-New.ts b/src/simulator/definitions/challenges/jbc22-Search-and-Rescue-New.ts new file mode 100644 index 00000000..df40f7a6 --- /dev/null +++ b/src/simulator/definitions/challenges/jbc22-Search-and-Rescue-New.ts @@ -0,0 +1,74 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 22' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 22: Search and Rescue`, + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, + }, + canInStartBox: { + name: { [LocalizedString.EN_US]: "Can in Start Box" }, + description: { [LocalizedString.EN_US]: "Can in start box" }, + }, + canUpright: { + name: { [LocalizedString.EN_US]: "Can Upright" }, + description: { [LocalizedString.EN_US]: "Can is upright" }, + }, + }, + success: { + exprs: { + // Start Box Events + notInStartBox: { + type: Expr.Type.Event, + eventId: "notInStartBox", + }, + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", + }, + + // Can Events + canInStartBox: { + type: Expr.Type.Event, + eventId: "canInStartBox", + }, + canUpright: { + type: Expr.Type.Event, + eventId: "canUpright", + }, + + completion: { + type: Expr.Type.And, + argIds: [ + 'inStartBoxOnce', + 'canInStartBox', + 'canUpright', + ], + }, + }, + rootId: 'completion', + }, + sceneId: 'jbc22', +} as Challenge; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index da5c2692..2bc68f0e 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -21,6 +21,7 @@ export * from './jbc18-Stackerz-New'; export * from './jbc19-Bump-New'; export * from './jbc20-Amazing-New'; export * from './jbc21-Proximity-New'; +export * from './jbc22-Search-and-Rescue-New'; export * from './jbc23-Find-the-Black-Line-New'; export * from './jbc24-Walk-the-Line-New'; export * from './moonSandbox'; diff --git a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts index e8ded99f..1348314e 100644 --- a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts +++ b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts @@ -59,14 +59,6 @@ export const JBC_15: Scene = { }, geometry: { ...baseScene.geometry, - mainSurface_geom: { - type: "box", - size: { - x: Distance.meters(3.54), - y: Distance.centimeters(0.1), - z: Distance.meters(3.54), - }, - }, startBox_geom: { type: "box", size: { @@ -87,26 +79,6 @@ export const JBC_15: Scene = { nodes: { ...baseScene.nodes, - mainSurface: { - type: "object", - geometryId: "mainSurface_geom", - name: { [LocalizedString.EN_US]: "Mat Surface" }, - visible: false, - origin: { - position: { - x: Distance.centimeters(0), - y: Distance.centimeters(-6.9), - z: Distance.inches(19.75), - }, - }, - material: { - type: "basic", - color: { - type: "color3", - color: Color.rgb(0, 0, 0), - }, - }, - }, startBox: { type: "object", geometryId: "startBox_geom", diff --git a/src/simulator/definitions/scenes/jbc22-Search-and-Rescue-New.ts b/src/simulator/definitions/scenes/jbc22-Search-and-Rescue-New.ts new file mode 100644 index 00000000..7b2b2272 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc22-Search-and-Rescue-New.ts @@ -0,0 +1,132 @@ +import Scene from '../../../state/State/Scene'; +import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from '../../../util/math/unitMath'; +import { Distance } from '../../../util'; +import LocalizedString from '../../../util/LocalizedString'; +import Script from '../../../state/State/Scene/Script'; +import { createCanNode, createBaseSceneSurfaceA, canPositions } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; + +import tr from '@i18n'; +import Node from 'state/State/Scene/Node'; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const enterStartBox = ` +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + + +scene.addOnIntersectionListener('can', (type, otherNodeId) => { + console.log('Robot returned start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('canInStartBox', type === 'start'); + setNodeVisible('startBox', type == 'start'); + } +}, 'startBox'); +`; + +const uprightCan = ` +// When a can is standing upright, the upright condition is met. + +const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity(); +const yAngle = (nodeId) => 180 / Math.PI * -1 * Math.asin(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.Y, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.Y)); + + +scene.addOnRenderListener(() => { + const upright = yAngle('can') > 5; + scene.setChallengeEventValue('canUpright', upright); +}); +`; + +function randomCan(): number { + const cans = [2, 4, 6]; + const randomCan = cans[Math.floor(Math.random() * cans.length)]; + return randomCan; +} + +export const JBC_22: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 22' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 22: Search and Rescue`, + }, + scripts: { + notInStartBox: Script.ecmaScript('Not in Start Box', notInStartBox), + enterStartBox: Script.ecmaScript('Enter Start Box', enterStartBox), + uprightCan: Script.ecmaScript('Upright Can', uprightCan), + }, + geometry: { + ...baseScene.geometry, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + startBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.centimeters(30), + }, + }, + }, + nodes: { + ...baseScene.nodes, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + startBox: { + type: "object", + geometryId: "startBox_geom", + name: { [LocalizedString.EN_US]: "Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.centimeters(-3), + }, + }, + material: { + type: "pbr", + emissive: { + type: "color3", + color: Color.rgb(255, 255, 255), + }, + }, + }, + can: createCanNode(randomCan()), + }, +}; diff --git a/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts index 2e246f80..cb0bcb21 100644 --- a/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts +++ b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts @@ -54,7 +54,6 @@ scene.addOnRenderListener(() => { function randomCircle(): Vector3wUnits { const circles = [2, 4, 6, 9, 11]; const randomCircle = circles[Math.floor(Math.random() * circles.length)]; - console.log('randomCircle', randomCircle); const circle: Vector3wUnits = { ...canPositions[randomCircle - 1], }; diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index 6384d086..17eb2993 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -44,6 +44,7 @@ import jbc18 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; import jbc19 from "../../simulator/definitions/challenges/jbc19-Bump-New"; import jbc20 from "../../simulator/definitions/challenges/jbc20-Amazing-New"; import jbc21 from "../../simulator/definitions/challenges/jbc21-Proximity-New"; +import jbc22 from "../../simulator/definitions/challenges/jbc22-Search-and-Rescue-New"; import jbc23 from "../../simulator/definitions/challenges/jbc23-Find-the-Black-Line-New"; import jbc24 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; // import test from '../../simulator/definitions/challenges/archived/test'; @@ -287,10 +288,10 @@ const DEFAULT_CHALLENGES: Challenges = { value: jbc21, brief: ChallengeBrief.fromChallenge(jbc21), }), - // 'jbc22': Async.loaded({ - // value: jbc22, - // brief: ChallengeBrief.fromChallenge(jbc22), - // }), + 'jbc22': Async.loaded({ + value: jbc22, + brief: ChallengeBrief.fromChallenge(jbc22), + }), 'jbc23': Async.loaded({ value: jbc23, brief: ChallengeBrief.fromChallenge(jbc23), diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index df35a661..3c36ed1d 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -327,7 +327,7 @@ const DEFAULT_SCENES: Scenes = { jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }), jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }), - // jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), + jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), jbc23: Async.loaded({ value: JBC_SCENES.JBC_23 }), jbc24: Async.loaded({ value: JBC_SCENES.JBC_24 }), // scriptPlayground: Async.loaded({ value: JBC_SCENES.scriptPlayground }),