Skip to content

Commit

Permalink
Complete JBC 22. Cleanup in 15 and 23
Browse files Browse the repository at this point in the history
  • Loading branch information
tcorbly committed Oct 30, 2024
1 parent 9d0b6bc commit 730f72c
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions src/simulator/definitions/scenes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
28 changes: 0 additions & 28 deletions src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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",
Expand Down
132 changes: 132 additions & 0 deletions src/simulator/definitions/scenes/jbc22-Search-and-Rescue-New.ts
Original file line number Diff line number Diff line change
@@ -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()),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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],
};
Expand Down
9 changes: 5 additions & 4 deletions src/state/reducer/challenges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/state/reducer/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down

0 comments on commit 730f72c

Please sign in to comment.