-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete JBC 22. Cleanup in 15 and 23
- Loading branch information
Showing
7 changed files
with
213 additions
and
34 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/simulator/definitions/challenges/jbc22-Search-and-Rescue-New.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/simulator/definitions/scenes/jbc22-Search-and-Rescue-New.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters