From 2fd85c7dafd3716bef0a2e8870399265245be575 Mon Sep 17 00:00:00 2001 From: rihal <-> Date: Fri, 3 Apr 2026 20:47:32 +0200 Subject: [PATCH] correcting calculation of rescue multiplier in RCJ --- .../simulationLogic/simulation.scene.js | 2 +- .../simulationLogic/simulation.scene.ts | 33 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.scene.js b/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.scene.js index a0471e6ce8..3487adc823 100644 --- a/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.scene.js +++ b/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.scene.js @@ -1,3 +1,3 @@ -var __spreadArray=this&&this.__spreadArray||function(t,e,i){if(i||2===arguments.length)for(var s,o=0,r=e.length;o=0?(s(this).html("Stop
Scoring Run"),o.init(),o.resetObstaclesCallback(),s("#rcjStartStop").addClass("running"),!1):(s(this).html("Start
Scoring Run"),clearInterval(o.stopWatch),s("#rcjStartStop").removeClass("running"),s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),o.robot&&o.robot.interpreter.terminate(),o.programPaused=!0,!1)})),s("#rcjLoP").off().on("click",(function(t){if(!s("#rcjLoP").hasClass("disabled")){t.preventDefault(),o.robot.interpreter.terminate(),o.programPaused=!0,s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled");var i=r.default.getTilePose(o.lastCheckPoint,e.tiles[o.lastCheckPoint.next],o.prevCheckPointTile);o.robot.pose=new n.Pose(i.x,i.y,i.theta),o.robot.initialPose=new n.Pose(i.x,i.y,i.theta),o.wasOnLineOnce=!0,o.line=!0,o.path=o.lastCheckPoint.index[0],o.lastPath=o.path;var a=Math.floor((o.robot.pose.x-10)/90),c=Math.floor((o.robot.pose.y-10)/90);return o.lastTile=o.configData.tiles[a+","+c+",0"],o.loPCounter+=1,o.loPSum+=1,o.nextCheckPoint&&o.loPCounter>=3&&s("#rcjNextCP").removeClass("disabled"),!1}})),s("#rcjNextCP").off().on("click",(function(t){if(!s("#rcjNextCP").hasClass("disabled")){if(t.preventDefault(),o.robot.interpreter.terminate(),o.programPaused=!0,s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),o.nextCheckPoint){var i=r.default.getTilePose(o.nextCheckPoint,e.tiles[o.nextCheckPoint.next],o.prevNextCheckPoint);o.robot.pose=new n.Pose(i.x,i.y,i.theta),o.robot.initialPose=new n.Pose(i.x,i.y,i.theta);var a=Math.floor((o.robot.pose.x-10)/90),c=Math.floor((o.robot.pose.y-10)/90);o.lastTile=o.configData.tiles[a+","+c+",0"],o.wasOnLineOnce=!0,o.line=!0,o.path=o.nextCheckPoint.index[0],o.lastPath=o.path,o.loPCounter=0,o.section+=1,o.lastCheckPoint=o.nextCheckPoint,o.setNextCheckPoint()}return!1}})),s("#rcjName").text(e.name),s("#rcjTeam").text(t.interpreter.name),s("#rcjTime").text("00:00:0")}return t.prototype.handleShortCuts=function(t){var e="";if(void 0!==t.key)e=t.key;else if(void 0!==t.which)switch(t.which){case 32:e=" ";break;case 76:e="l";break;case 83:e="s";break;case 74:e="j"}switch(e){case" ":s("#simControl").trigger("click"),t.preventDefault();break;case"l":s("#rcjLoP").trigger("click"),t.preventDefault();break;case"s":s("#rcjStartStop").trigger("click"),t.preventDefault();break;case"j":s("#rcjNextCP").trigger("click"),t.preventDefault()}},t.prototype.init=function(){this.path=0,this.lastPath=0,this.line=!0,this.wasOnLineOnce=!0,clearInterval(this.stopWatch),this.mins=0,this.secs=0,this.csecs=0,this.running=!0,this.stopWatch=setInterval(this.timer.bind(this),100);var t=this.configData.tiles[this.configData.startTile.x+","+this.configData.startTile.y+",0"];this.initialPose=r.default.getTilePose(t,this.configData.tiles[t.next],null),this.lastTile=t,this.lastCheckPoint=t,this.setNextCheckPoint(),this.robot&&(this.robot.initialPose=this.initialPose,this.robot.resetPose(),this.wasOnLineOnce=!0),this.loPCounter=0,this.loPSum=0,this.section=0,this.victimsLocated=0,this.linePoints=5,this.obstaclePoints=0,this.totalScore=0,this.inAvoidanceMode=!1,this.countedTileIndices=[0],this.rescueMulti=1},t.prototype.timer=function(){this.running&&(this.csecs++,10===this.csecs&&(this.secs++,this.csecs=0),60===this.secs&&(this.mins++,this.secs=0),s("#rcjTime").text(("00"+this.mins).slice(-2)+":"+("00"+this.secs).slice(-2)+":"+this.csecs),s("#rcjPath").text(-1===this.path?"wrong":"correct"),s("#rcjLastPath").text(this.lastPath),s("#rcjSection").text(this.section),s("#rcjLoPpS").text(this.loPCounter),s("#rcjLoPCount").text(this.loPSum),s("#rcjLine").text(this.line?"yes":"no"),s("#rcjRescueMulti").text(Math.round(100*this.rescueMulti)/100),s("#rcjLinePoints").text(this.linePoints),s("#rcjObstaclePoints").text(this.obstaclePoints),s("#rcjTotalScore").text(this.totalScore),(this.mins>=this.MAX_TIME||this.victimsLocated>=3)&&s("#rcjStartStop").trigger("click"))},t.prototype.countObstaclePoints=function(t){t&&!this.countedTileIndices.includes(t.index[0])&&(t.tileType.gaps>0&&(this.obstaclePoints+=this.POINTS_GAP),t.tileType.intersections>0&&(this.obstaclePoints+=t.tileType.intersections*this.POINTS_INTERSECTION),this.countedTileIndices.push(t.index[0]))},t.prototype.callAutoLoP=function(){s("#autoLoP").prop("checked")&&s("#rcjLoP").trigger("click")},t.prototype.update=function(t){var e=this;if(this.running)if(t instanceof n.RobotBaseMobile){var r=t;if(this.robot!=r&&this.setRobot(r),this.robot.interpreter.isTerminated())return void(this.programPaused=!0);this.programPaused&&(s("#rcjLoP").removeClass("disabled"),s("#rcjNextCP").addClass("disabled"),this.nextCheckPoint&&this.loPCounter>=3&&s("#rcjNextCP").removeClass("disabled"),this.programPaused=!1),this.pose=r.pose;var a=Math.floor((this.pose.x-10)/90),c=Math.floor((this.pose.y-10)/90),h=this.configData.tiles[a+","+c+",0"],l=h&&h.index[0];if(l==this.lastPath||l==this.lastPath+1){if(this.path=l,this.lastPath=l,this.line=function(){for(var t=0,i=e.lineSensors;t0&&1===this.configData.tiles[this.lastTile.next].items.obstacles)this.inAvoidanceMode=!0,this.path+=1,this.lastPath=this.path,this.avoidanceGoalIndex=this.lastTile.index[0]+2;else if(this.lastTile.items.obstacles>0)this.inAvoidanceMode=!0,this.avoidanceGoalIndex=this.lastTile.index[0]+1;else{if(-1!=this.path&&l)return void this.callAutoLoP();this.path=-1}this.line=!1}this.totalScore=(this.linePoints+this.obstaclePoints)*this.rescueMulti,this.totalScore=i.round(this.totalScore,2)}else if(t instanceof o.CircleSimulationObject){var g=t,p=Math.max(this.POINTS_VICTIM_MULTI-.05*this.loPCounter,1.25);g.inEvacuationZone&&"#33B8CA"===g.color&&(g.selected=!0,s("#simDeleteObject").trigger("click"),this.rescueMulti*=p,this.victimsLocated+=1),g.inEvacuationZone&&"#000000"===g.color&&(g.selected=!0,s("#simDeleteObject").trigger("click"),this.victimsLocated>1?this.rescueMulti*=p:this.rescueMulti*=this.POINTS_DEADONLY_VICTIM_MULTI,this.victimsLocated+=1)}},t.prototype.setNextCheckPoint=function(){for(var t=this.configData.tiles[this.lastCheckPoint.next];t&&this.configData.tiles[t.next]&&(this.prevNextCheckPoint=t,!(t=this.configData.tiles[t.next]).checkPoint););t&&t.checkPoint?this.nextCheckPoint=t:(this.nextCheckPoint=null,this.prevNextCheckPoint=null)},t.prototype.openClose=function(){var t=s("#simDiv").position();t.left=12,s("#rcjScoringWindow").toggleSimPopup(t)},t.prototype.destroy=function(){s("#rcjStartStop").html("Start
Scoring Run"),s("#rcjStartStop").removeClass("running"),s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),clearInterval(this.stopWatch),this.stopWatch=null,s("#rcjPath").text(""),s("#rcjLastPath").text(""),s("#rcjSection").text(""),s("#rcjLoPpS").text(""),s("#rcjLoPCount").text(""),s("#rcjLine").text(""),s("#rcjName").text(""),s("#rcjTeam").text(""),s("#rcjTime").text("00:00:0"),s("#rcjRescueMulti").text("")},t.prototype.setRobot=function(t){for(var e in this.robot=t,this.initialPose=this.robot.initialPose,this.lineSensors=[],t)t.hasOwnProperty(e)&&t[e]instanceof c.ColorSensorHex&&this.lineSensors.push(t[e])},t}();e.RcjScoringTool=h;var l=function(){function t(t){this.DEFAULT_TRAIL_WIDTH=10,this.DEFAULT_TRAIL_COLOR="#000000",this.customBackgroundLoaded=!1,this.ground=new o.Ground(0,0,0,0),this.imgBackgroundList=[],this.imgPath="/css/img/simBackgrounds/",this.playground={x:0,y:0,w:0,h:0},this._colorAreaList=[],this._obstacleList=[],this._rcjList=[],this._markerList=[],this._redrawColorAreas=!1,this._redrawObstacles=!1,this._redrawMarkers=!1,this._robots=[],this._uniqueObjectId=0,this._scoring=!1,this.sim=t,this.uCanvas=document.createElement("canvas"),this.uCtx=this.uCanvas.getContext("2d",{willReadFrequently:!0}),this.udCanvas=document.createElement("canvas"),this.udCtx=this.udCanvas.getContext("2d",{willReadFrequently:!0}),this.bCtx=s("#backgroundLayer")[0].getContext("2d"),this.dCtx=s("#drawLayer")[0].getContext("2d"),this.aCtx=s("#arucoMarkerLayer")[0].getContext("2d"),this.oCtx=s("#objectLayer")[0].getContext("2d"),this.rCtx=s("#robotLayer")[0].getContext("2d"),this.rcjCtx=s("#rcjLayer")[0].getContext("2d")}return Object.defineProperty(t.prototype,"scoring",{get:function(){return this._scoring},set:function(t){this._scoring=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"uniqueObjectId",{get:function(){return++this._uniqueObjectId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"robots",{get:function(){return this._robots},set:function(t){this.clearList(this._robots),this._robots=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"obstacleList",{get:function(){return this._obstacleList},set:function(t){this.clearList(this._obstacleList),this._obstacleList=t,this.redrawObstacles=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rcjList",{get:function(){return this._rcjList},set:function(t){this.clearList(this._rcjList),this._rcjList=t,this.redrawObstacles=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"colorAreaList",{get:function(){return this._colorAreaList},set:function(t){this.clearList(this._colorAreaList),this._colorAreaList=t,this.redrawColorAreas=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"markerList",{get:function(){return this._markerList},set:function(t){this.clearList(this._markerList),this._markerList=t,this.redrawMarkers=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawObstacles",{get:function(){return this._redrawObstacles},set:function(t){this._redrawObstacles=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawColorAreas",{get:function(){return this._redrawColorAreas},set:function(t){this._redrawColorAreas=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawMarkers",{get:function(){return this._redrawMarkers},set:function(t){this._redrawMarkers=t},enumerable:!1,configurable:!0}),t.prototype.addColorArea=function(t){this.addSimulationObject(this.colorAreaList,t,o.SimObjectType.ColorArea),this.redrawColorAreas=!0},t.prototype.addImportColorAreaList=function(t){var e=this,i=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,e,e.sim.selectionListener,t.shape,o.SimObjectType.ColorArea,t.p,null,t.color],t.params,!1));i.push(s)})),this.colorAreaList=i},t.prototype.addImportObstacle=function(t){var e=this,i=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,e,e.sim.selectionListener,t.shape,o.SimObjectType.Obstacle,t.p,null,t.color],t.params,!1));i.push(s)})),this.obstacleList=i},t.prototype.addSomeObstacles=function(t){var e=this,i=this;t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,e,e.sim.selectionListener,t.shape,o.SimObjectType.Obstacle,t.p,null,t.color],t.params,!1));i.obstacleList.push(s)}))},t.prototype.addImportRcjLabel=function(t){var e=this,i=[];t.forEach((function(t){var s=new o.RcjSimulationLabel(e.uniqueObjectId,e,e.sim.selectionListener,o.SimObjectType.ColorArea,t.x,t.y,t.checkPoint?"checkPoint":t.start?"start":null,t.index[0]);i.push(s)})),this.rcjList=i},t.prototype.addImportMarkerList=function(t){var e=this,i=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,e,e.sim.selectionListener,t.shape,o.SimObjectType.Marker,t.p,null,t.color],t.params,!1));s.markerId=t.markerId,i.push(s)})),this.markerList=i},t.prototype.addObstacle=function(t){this.addSimulationObject(this.obstacleList,t,o.SimObjectType.Obstacle),this.redrawObstacles=!0},t.prototype.addSimulationObject=function(t,e,i,r){var a=s("#robotLayer");a.attr("tabindex",0),a.trigger("focus");var n=Math.random()*(this.ground.w-300)+100,c=Math.random()*(this.ground.h-200)+100,h=o.SimObjectFactory.getSimObject(this.uniqueObjectId,this,this.sim.selectionListener,e,i,{x:n,y:c},this.backgroundImg.width);e==o.SimObjectShape.Marker&&r&&(h.markerId=r),t.push(h),h.selected=!0},t.prototype.changeColorWithColorPicker=function(t){var e=this.obstacleList.concat(this.colorAreaList).filter((function(t){return t.selected}));1==e.length&&(e[0].color=t,e[0].type===o.SimObjectType.Obstacle?this.redrawObstacles=!0:this.redrawColorAreas=!0)},t.prototype.clearList=function(t){t.forEach((function(t){t.destroy()})),t.length=0},t.prototype.deleteSelectedObject=function(){var t=this;function e(e){for(var i=0;i.pace").show(),this.robots=[],a.RobotFactory.createRobots(r,n,c,this.sim.selectionListener,this.robotType).then((function(t){if(d.robots=t.robots,d.robotClass=t.robotClass,d.setRobotPoses(h),d.initViews(),u){d.removeRcjScoringTool(),g.imgBackgroundList=[],g.currentBackground=0,g.obstacleList.length>0&&(g.obstacleList=[]),g.colorAreaList.length>0&&(g.colorAreaList=[]);var e=".svg";i.isIE()&&(e=".png"),g.loadBackgroundImages((function(){g.robots[0].mobile?(s(".simMobile").show(),g.images=g.loadImages(["roadWorks","pattern"],["roadWorks"+e,"wallPattern.png"],(function(){g.ground=new o.Ground(10,10,g.imgBackgroundList[g.currentBackground].width,g.imgBackgroundList[g.currentBackground].height),g.backgroundImg=g.imgBackgroundList[0];var t=new o.RectangleSimulationObject(0,g,g.sim.selectionListener,o.SimObjectType.Obstacle,{x:7*g.backgroundImg.width/9,y:g.backgroundImg.height-2*g.backgroundImg.width/9},g.backgroundImg.width);g.obstacleList.push(t),g.centerBackground(!0),g.initEvents(),g.sim.initColorPicker(a.RobotBase.colorRange),g.showFullyLoadedSim(l),g.sim.start()}))):(s(".simMobile").hide(),g.images={},g.ground=new o.Ground(10,10,g.imgBackgroundList[g.currentBackground].width,g.imgBackgroundList[g.currentBackground].height),g.backgroundImg=g.imgBackgroundList[0],g.centerBackground(!0),g.initEvents(),g.showFullyLoadedSim(l),g.sim.start())}))}d.showFullyLoadedSim(l),d.sim.start()}))):(this.robots.forEach((function(t,e){g.rcjScoringTool&&t.addObserver(g.rcjScoringTool),t.replaceState(r[e]),t.reset()})),this.showFullyLoadedSim(l)),this.robots.forEach((function(t,e){t.time=0}))},t.prototype.showFullyLoadedSim=function(t){this.obstacleList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),this.markerList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),this.colorAreaList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),s("#canvasDiv").fadeIn("slow"),s("#simDiv>.pace").fadeOut("fast"),"function"==typeof t&&t()},t.prototype.initViews=function(){var t=s("#systemValuesView"),e=s("#robotIndex");t.html("");var i="",o=this.robots[0]instanceof n.RobotBaseMobile?this.robots[0].chassis.geom.color:"#ffffff";if(i+='",t.append('
'+i+"
"),e.off("change.sim"),this.robots.length>1){var r=this;e.on("change.sim",(function(){var t=Number(s(this).val());r.robots[t].selected=!0,r.sim.selectionListener.fire(null)}))}},t.prototype.initEvents=function(){var t=this,e=0;s(window).off("resize.sim").on("resize.sim",(function(i,s){e>3||"loaded"==s?(t.centerBackground(!1),e=0):e++})),s("#robotLayer").off("keydown.sim").on("keydown.sim",this.handleKeyEvent.bind(this))},t.prototype.loadBackgroundImages=function(t){var e,s;s=i.isIE()?".png":".svg";for(var o=(e=this.robots[0].mobile?this.robots[0].imgList.map((function(t){return t.endsWith("jpg")?t:"".concat(t).concat(s)})):[this.robotType+"Background"+s]).length,r=this,a=function(){if(0==--o&&(t(),i.isLocalStorageAvailable()&&r.robots[0].mobile)){var e=localStorage.getItem("customBackground");if(e){try{JSON.parse(e)}catch(t){localStorage.setItem("customBackground",JSON.stringify({image:e,timestamp:(new Date).getTime()})),e=localStorage.getItem("customBackground")}var s=JSON.parse(e);if((new Date).getTime()-s.timestamp>54432e5)localStorage.removeItem("customBackground");else{var a=s.image,n=new Image;n.src="data:image/png;base64,"+a,r.imgBackgroundList.push(n),r.customBackgroundLoaded=!0}}}},n=0;n0;){a[0].updateSensor(i.uCtx,r,a),a.shift()}})),this.draw(t,e)},t.prototype.toggleTrail=function(){this.robots.forEach((function(t){t.hasTrail=!t.hasTrail,t.pose.xOld=t.pose.x,t.pose.yOld=t.pose.y}))},t.prototype.resetPoseAndDrawings=function(){this.robots.forEach((function(t){return t.resetPose()})),this.dCtx.canvas.width=this.dCtx.canvas.width,this.udCtx.canvas.width=this.udCtx.canvas.width},t.prototype.addMarker=function(t){this.addSimulationObject(this.markerList,o.SimObjectShape.Marker,o.SimObjectType.Marker,t),this._redrawMarkers=!0},t.prototype.setRcjScoringTool=function(t,e,i){this.rcjScoringTool=new h(t,e,i),this.scoring=!0;var o=this;s("#simCompetition").show(),s("#simCompetition").off(),s("#simCompetition").onWrap("click",(function(){o.rcjScoringTool.openClose()})),this.obstacleList.forEach((function(t){t.addObserver&&"function"==typeof t.addObserver&&t.addObserver(o.rcjScoringTool)}))},t.prototype.removeRcjScoringTool=function(){this.rcjScoringTool&&this.rcjScoringTool.destroy(),this.rcjScoringTool=null,this.scoring=!1,s("#simCompetition").hide(),s("#simCompetition").off()},t}();e.SimulationScene=l})); +var __spreadArray=this&&this.__spreadArray||function(t,e,i){if(i||2===arguments.length)for(var s,o=0,r=e.length;o=0)return s(this).html("Stop
Scoring Run"),a.init(),a.resetObstaclesCallback(),s("#rcjStartStop").addClass("running"),!1;a.programPaused=!0,clearInterval(a.stopWatch);for(var e=Math.max(a.POINTS_VICTIM_MULTI-.05*a.loPCounter,1.25),o=0;o0?a.rescueMulti*=e:a.rescueMulti*=a.POINTS_DEADONLY_VICTIM_MULTI;return a.totalScore=(a.linePoints+a.obstaclePoints)*a.rescueMulti,a.totalScore=i.round(a.totalScore,2),s("#rcjLoPpS").text(a.loPCounter),s("#rcjLoPCount").text(a.loPSum),s("#rcjRescueMulti").text(Math.round(100*a.rescueMulti)/100),s("#rcjLinePoints").text(a.linePoints),s("#rcjObstaclePoints").text(a.obstaclePoints),s("#rcjTotalScore").text(a.totalScore),s(this).html("Start
Scoring Run"),s("#rcjStartStop").removeClass("running"),s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),a.robot&&a.robot.interpreter.terminate(),!1})),s("#rcjLoP").off().on("click",(function(t){if(!s("#rcjLoP").hasClass("disabled")){t.preventDefault(),a.robot.interpreter.terminate(),a.programPaused=!0,s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled");var i=r.default.getTilePose(a.lastCheckPoint,e.tiles[a.lastCheckPoint.next],a.prevCheckPointTile);a.robot.pose=new n.Pose(i.x,i.y,i.theta),a.robot.initialPose=new n.Pose(i.x,i.y,i.theta),a.wasOnLineOnce=!0,a.line=!0,a.path=a.lastCheckPoint.index[0],a.lastPath=a.path;var o=Math.floor((a.robot.pose.x-10)/90),c=Math.floor((a.robot.pose.y-10)/90);return a.lastTile=a.configData.tiles[o+","+c+",0"],a.loPCounter+=1,a.loPSum+=1,a.nextCheckPoint&&a.loPCounter>=3&&s("#rcjNextCP").removeClass("disabled"),!1}})),s("#rcjNextCP").off().on("click",(function(t){if(!s("#rcjNextCP").hasClass("disabled")){if(t.preventDefault(),a.robot.interpreter.terminate(),a.programPaused=!0,s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),a.nextCheckPoint){var i=r.default.getTilePose(a.nextCheckPoint,e.tiles[a.nextCheckPoint.next],a.prevNextCheckPoint);a.robot.pose=new n.Pose(i.x,i.y,i.theta),a.robot.initialPose=new n.Pose(i.x,i.y,i.theta);var o=Math.floor((a.robot.pose.x-10)/90),c=Math.floor((a.robot.pose.y-10)/90);a.lastTile=a.configData.tiles[o+","+c+",0"],a.wasOnLineOnce=!0,a.line=!0,a.path=a.nextCheckPoint.index[0],a.lastPath=a.path,a.loPCounter=0,a.section+=1,a.lastCheckPoint=a.nextCheckPoint,a.setNextCheckPoint()}return!1}})),s("#rcjName").text(e.name),s("#rcjTeam").text(t.interpreter.name),s("#rcjTime").text("00:00:0")}return t.prototype.handleShortCuts=function(t){var e="";if(void 0!==t.key)e=t.key;else if(void 0!==t.which)switch(t.which){case 32:e=" ";break;case 76:e="l";break;case 83:e="s";break;case 74:e="j"}switch(e){case" ":s("#simControl").trigger("click"),t.preventDefault();break;case"l":s("#rcjLoP").trigger("click"),t.preventDefault();break;case"s":s("#rcjStartStop").trigger("click"),t.preventDefault();break;case"j":s("#rcjNextCP").trigger("click"),t.preventDefault()}},t.prototype.init=function(){this.path=0,this.lastPath=0,this.line=!0,this.wasOnLineOnce=!0,clearInterval(this.stopWatch),this.mins=0,this.secs=0,this.csecs=0,this.running=!0,this.stopWatch=setInterval(this.timer.bind(this),100);var t=this.configData.tiles[this.configData.startTile.x+","+this.configData.startTile.y+",0"];this.initialPose=r.default.getTilePose(t,this.configData.tiles[t.next],null),this.lastTile=t,this.lastCheckPoint=t,this.setNextCheckPoint(),this.robot&&(this.robot.initialPose=this.initialPose,this.robot.resetPose(),this.wasOnLineOnce=!0),this.loPCounter=0,this.loPSum=0,this.section=0,this.victimsLocated=0,this.victimsLiveLocated=0,this.linePoints=5,this.obstaclePoints=0,this.totalScore=0,this.inAvoidanceMode=!1,this.countedTileIndices=[0],this.rescueMulti=1},t.prototype.timer=function(){this.running&&(this.csecs++,10===this.csecs&&(this.secs++,this.csecs=0),60===this.secs&&(this.mins++,this.secs=0),s("#rcjTime").text(("00"+this.mins).slice(-2)+":"+("00"+this.secs).slice(-2)+":"+this.csecs),s("#rcjPath").text(-1===this.path?"wrong":"correct"),s("#rcjLastPath").text(this.lastPath),s("#rcjSection").text(this.section),s("#rcjLoPpS").text(this.loPCounter),s("#rcjLoPCount").text(this.loPSum),s("#rcjLine").text(this.line?"yes":"no"),s("#rcjRescueMulti").text(Math.round(100*this.rescueMulti)/100),s("#rcjLinePoints").text(this.linePoints),s("#rcjObstaclePoints").text(this.obstaclePoints),s("#rcjTotalScore").text(this.totalScore),(this.mins>=this.MAX_TIME||this.victimsLocated>=3)&&s("#rcjStartStop").trigger("click"))},t.prototype.countObstaclePoints=function(t){t&&!this.countedTileIndices.includes(t.index[0])&&(t.tileType.gaps>0&&(this.obstaclePoints+=this.POINTS_GAP),t.tileType.intersections>0&&(this.obstaclePoints+=t.tileType.intersections*this.POINTS_INTERSECTION),this.countedTileIndices.push(t.index[0]))},t.prototype.callAutoLoP=function(){s("#autoLoP").prop("checked")&&s("#rcjLoP").trigger("click")},t.prototype.update=function(t){var e=this;if(this.running)if(t instanceof n.RobotBaseMobile){var r=t;if(this.robot!=r&&this.setRobot(r),this.robot.interpreter.isTerminated())return void(this.programPaused=!0);this.programPaused&&(s("#rcjLoP").removeClass("disabled"),s("#rcjNextCP").addClass("disabled"),this.nextCheckPoint&&this.loPCounter>=3&&s("#rcjNextCP").removeClass("disabled"),this.programPaused=!1),this.pose=r.pose;var a=Math.floor((this.pose.x-10)/90),c=Math.floor((this.pose.y-10)/90),h=this.configData.tiles[a+","+c+",0"],l=h&&h.index[0];if(l==this.lastPath||l==this.lastPath+1){if(this.path=l,this.lastPath=l,this.line=function(){for(var t=0,i=e.lineSensors;t0&&1===this.configData.tiles[this.lastTile.next].items.obstacles)this.inAvoidanceMode=!0,this.path+=1,this.lastPath=this.path,this.avoidanceGoalIndex=this.lastTile.index[0]+2;else if(this.lastTile.items.obstacles>0)this.inAvoidanceMode=!0,this.avoidanceGoalIndex=this.lastTile.index[0]+1;else{if(-1!=this.path&&l)return void this.callAutoLoP();this.path=-1}this.line=!1}this.totalScore=(this.linePoints+this.obstaclePoints)*this.rescueMulti,this.totalScore=i.round(this.totalScore,2)}else if(t instanceof o.CircleSimulationObject){var g=t;g.inEvacuationZone&&"#33B8CA"===g.color&&(g.selected=!0,s("#simDeleteObject").trigger("click"),this.victimsLocated+=1,this.victimsLiveLocated+=1),g.inEvacuationZone&&"#000000"===g.color&&(g.selected=!0,s("#simDeleteObject").trigger("click"),this.victimsLocated+=1)}},t.prototype.setNextCheckPoint=function(){for(var t=this.configData.tiles[this.lastCheckPoint.next];t&&this.configData.tiles[t.next]&&(this.prevNextCheckPoint=t,!(t=this.configData.tiles[t.next]).checkPoint););t&&t.checkPoint?this.nextCheckPoint=t:(this.nextCheckPoint=null,this.prevNextCheckPoint=null)},t.prototype.openClose=function(){var t=s("#simDiv").position();t.left=12,s("#rcjScoringWindow").toggleSimPopup(t)},t.prototype.destroy=function(){s("#rcjStartStop").html("Start
Scoring Run"),s("#rcjStartStop").removeClass("running"),s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),clearInterval(this.stopWatch),this.stopWatch=null,s("#rcjPath").text(""),s("#rcjLastPath").text(""),s("#rcjSection").text(""),s("#rcjLoPpS").text(""),s("#rcjLoPCount").text(""),s("#rcjLine").text(""),s("#rcjName").text(""),s("#rcjTeam").text(""),s("#rcjTime").text("00:00:0"),s("#rcjRescueMulti").text("")},t.prototype.setRobot=function(t){for(var e in this.robot=t,this.initialPose=this.robot.initialPose,this.lineSensors=[],t)t.hasOwnProperty(e)&&t[e]instanceof c.ColorSensorHex&&this.lineSensors.push(t[e])},t}();e.RcjScoringTool=h;var l=function(){function t(t){this.DEFAULT_TRAIL_WIDTH=10,this.DEFAULT_TRAIL_COLOR="#000000",this.customBackgroundLoaded=!1,this.ground=new o.Ground(0,0,0,0),this.imgBackgroundList=[],this.imgPath="/css/img/simBackgrounds/",this.playground={x:0,y:0,w:0,h:0},this._colorAreaList=[],this._obstacleList=[],this._rcjList=[],this._markerList=[],this._redrawColorAreas=!1,this._redrawObstacles=!1,this._redrawMarkers=!1,this._robots=[],this._uniqueObjectId=0,this._scoring=!1,this.sim=t,this.uCanvas=document.createElement("canvas"),this.uCtx=this.uCanvas.getContext("2d",{willReadFrequently:!0}),this.udCanvas=document.createElement("canvas"),this.udCtx=this.udCanvas.getContext("2d",{willReadFrequently:!0}),this.bCtx=s("#backgroundLayer")[0].getContext("2d"),this.dCtx=s("#drawLayer")[0].getContext("2d"),this.aCtx=s("#arucoMarkerLayer")[0].getContext("2d"),this.oCtx=s("#objectLayer")[0].getContext("2d"),this.rCtx=s("#robotLayer")[0].getContext("2d"),this.rcjCtx=s("#rcjLayer")[0].getContext("2d")}return Object.defineProperty(t.prototype,"scoring",{get:function(){return this._scoring},set:function(t){this._scoring=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"uniqueObjectId",{get:function(){return++this._uniqueObjectId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"robots",{get:function(){return this._robots},set:function(t){this.clearList(this._robots),this._robots=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"obstacleList",{get:function(){return this._obstacleList},set:function(t){this.clearList(this._obstacleList),this._obstacleList=t,this.redrawObstacles=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rcjList",{get:function(){return this._rcjList},set:function(t){this.clearList(this._rcjList),this._rcjList=t,this.redrawObstacles=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"colorAreaList",{get:function(){return this._colorAreaList},set:function(t){this.clearList(this._colorAreaList),this._colorAreaList=t,this.redrawColorAreas=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"markerList",{get:function(){return this._markerList},set:function(t){this.clearList(this._markerList),this._markerList=t,this.redrawMarkers=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawObstacles",{get:function(){return this._redrawObstacles},set:function(t){this._redrawObstacles=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawColorAreas",{get:function(){return this._redrawColorAreas},set:function(t){this._redrawColorAreas=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawMarkers",{get:function(){return this._redrawMarkers},set:function(t){this._redrawMarkers=t},enumerable:!1,configurable:!0}),t.prototype.addColorArea=function(t){this.addSimulationObject(this.colorAreaList,t,o.SimObjectType.ColorArea),this.redrawColorAreas=!0},t.prototype.addImportColorAreaList=function(t){var e=this,i=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,e,e.sim.selectionListener,t.shape,o.SimObjectType.ColorArea,t.p,null,t.color],t.params,!1));i.push(s)})),this.colorAreaList=i},t.prototype.addImportObstacle=function(t){var e=this,i=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,e,e.sim.selectionListener,t.shape,o.SimObjectType.Obstacle,t.p,null,t.color],t.params,!1));i.push(s)})),this.obstacleList=i},t.prototype.addSomeObstacles=function(t){var e=this,i=this;t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,e,e.sim.selectionListener,t.shape,o.SimObjectType.Obstacle,t.p,null,t.color],t.params,!1));i.obstacleList.push(s)}))},t.prototype.addImportRcjLabel=function(t){var e=this,i=[];t.forEach((function(t){var s=new o.RcjSimulationLabel(e.uniqueObjectId,e,e.sim.selectionListener,o.SimObjectType.ColorArea,t.x,t.y,t.checkPoint?"checkPoint":t.start?"start":null,t.index[0]);i.push(s)})),this.rcjList=i},t.prototype.addImportMarkerList=function(t){var e=this,i=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,e,e.sim.selectionListener,t.shape,o.SimObjectType.Marker,t.p,null,t.color],t.params,!1));s.markerId=t.markerId,i.push(s)})),this.markerList=i},t.prototype.addObstacle=function(t){this.addSimulationObject(this.obstacleList,t,o.SimObjectType.Obstacle),this.redrawObstacles=!0},t.prototype.addSimulationObject=function(t,e,i,r){var a=s("#robotLayer");a.attr("tabindex",0),a.trigger("focus");var n=Math.random()*(this.ground.w-300)+100,c=Math.random()*(this.ground.h-200)+100,h=o.SimObjectFactory.getSimObject(this.uniqueObjectId,this,this.sim.selectionListener,e,i,{x:n,y:c},this.backgroundImg.width);e==o.SimObjectShape.Marker&&r&&(h.markerId=r),t.push(h),h.selected=!0},t.prototype.changeColorWithColorPicker=function(t){var e=this.obstacleList.concat(this.colorAreaList).filter((function(t){return t.selected}));1==e.length&&(e[0].color=t,e[0].type===o.SimObjectType.Obstacle?this.redrawObstacles=!0:this.redrawColorAreas=!0)},t.prototype.clearList=function(t){t.forEach((function(t){t.destroy()})),t.length=0},t.prototype.deleteSelectedObject=function(){var t=this;function e(e){for(var i=0;i.pace").show(),this.robots=[],a.RobotFactory.createRobots(r,n,c,this.sim.selectionListener,this.robotType).then((function(t){if(d.robots=t.robots,d.robotClass=t.robotClass,d.setRobotPoses(h),d.initViews(),u){d.removeRcjScoringTool(),g.imgBackgroundList=[],g.currentBackground=0,g.obstacleList.length>0&&(g.obstacleList=[]),g.colorAreaList.length>0&&(g.colorAreaList=[]);var e=".svg";i.isIE()&&(e=".png"),g.loadBackgroundImages((function(){g.robots[0].mobile?(s(".simMobile").show(),g.images=g.loadImages(["roadWorks","pattern"],["roadWorks"+e,"wallPattern.png"],(function(){g.ground=new o.Ground(10,10,g.imgBackgroundList[g.currentBackground].width,g.imgBackgroundList[g.currentBackground].height),g.backgroundImg=g.imgBackgroundList[0];var t=new o.RectangleSimulationObject(0,g,g.sim.selectionListener,o.SimObjectType.Obstacle,{x:7*g.backgroundImg.width/9,y:g.backgroundImg.height-2*g.backgroundImg.width/9},g.backgroundImg.width);g.obstacleList.push(t),g.centerBackground(!0),g.initEvents(),g.sim.initColorPicker(a.RobotBase.colorRange),g.showFullyLoadedSim(l),g.sim.start()}))):(s(".simMobile").hide(),g.images={},g.ground=new o.Ground(10,10,g.imgBackgroundList[g.currentBackground].width,g.imgBackgroundList[g.currentBackground].height),g.backgroundImg=g.imgBackgroundList[0],g.centerBackground(!0),g.initEvents(),g.showFullyLoadedSim(l),g.sim.start())}))}d.showFullyLoadedSim(l),d.sim.start()}))):(this.robots.forEach((function(t,e){g.rcjScoringTool&&t.addObserver(g.rcjScoringTool),t.replaceState(r[e]),t.reset()})),this.showFullyLoadedSim(l)),this.robots.forEach((function(t,e){t.time=0}))},t.prototype.showFullyLoadedSim=function(t){this.obstacleList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),this.markerList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),this.colorAreaList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),s("#canvasDiv").fadeIn("slow"),s("#simDiv>.pace").fadeOut("fast"),"function"==typeof t&&t()},t.prototype.initViews=function(){var t=s("#systemValuesView"),e=s("#robotIndex");t.html("");var i="",o=this.robots[0]instanceof n.RobotBaseMobile?this.robots[0].chassis.geom.color:"#ffffff";if(i+='",t.append('
'+i+"
"),e.off("change.sim"),this.robots.length>1){var r=this;e.on("change.sim",(function(){var t=Number(s(this).val());r.robots[t].selected=!0,r.sim.selectionListener.fire(null)}))}},t.prototype.initEvents=function(){var t=this,e=0;s(window).off("resize.sim").on("resize.sim",(function(i,s){e>3||"loaded"==s?(t.centerBackground(!1),e=0):e++})),s("#robotLayer").off("keydown.sim").on("keydown.sim",this.handleKeyEvent.bind(this))},t.prototype.loadBackgroundImages=function(t){var e,s;s=i.isIE()?".png":".svg";for(var o=(e=this.robots[0].mobile?this.robots[0].imgList.map((function(t){return t.endsWith("jpg")?t:"".concat(t).concat(s)})):[this.robotType+"Background"+s]).length,r=this,a=function(){if(0==--o&&(t(),i.isLocalStorageAvailable()&&r.robots[0].mobile)){var e=localStorage.getItem("customBackground");if(e){try{JSON.parse(e)}catch(t){localStorage.setItem("customBackground",JSON.stringify({image:e,timestamp:(new Date).getTime()})),e=localStorage.getItem("customBackground")}var s=JSON.parse(e);if((new Date).getTime()-s.timestamp>54432e5)localStorage.removeItem("customBackground");else{var a=s.image,n=new Image;n.src="data:image/png;base64,"+a,r.imgBackgroundList.push(n),r.customBackgroundLoaded=!0}}}},n=0;n0;){a[0].updateSensor(i.uCtx,r,a),a.shift()}})),this.draw(t,e)},t.prototype.toggleTrail=function(){this.robots.forEach((function(t){t.hasTrail=!t.hasTrail,t.pose.xOld=t.pose.x,t.pose.yOld=t.pose.y}))},t.prototype.resetPoseAndDrawings=function(){this.robots.forEach((function(t){return t.resetPose()})),this.dCtx.canvas.width=this.dCtx.canvas.width,this.udCtx.canvas.width=this.udCtx.canvas.width},t.prototype.addMarker=function(t){this.addSimulationObject(this.markerList,o.SimObjectShape.Marker,o.SimObjectType.Marker,t),this._redrawMarkers=!0},t.prototype.setRcjScoringTool=function(t,e,i){this.rcjScoringTool=new h(t,e,i),this.scoring=!0;var o=this;s("#simCompetition").show(),s("#simCompetition").off(),s("#simCompetition").onWrap("click",(function(){o.rcjScoringTool.openClose()})),this.obstacleList.forEach((function(t){t.addObserver&&"function"==typeof t.addObserver&&t.addObserver(o.rcjScoringTool)}))},t.prototype.removeRcjScoringTool=function(){this.rcjScoringTool&&this.rcjScoringTool.destroy(),this.rcjScoringTool=null,this.scoring=!1,s("#simCompetition").hide(),s("#simCompetition").off()},t}();e.SimulationScene=l})); //# sourceMappingURL=simulation.scene.js.map //# sourceMappingURL=simulation.scene.js.map diff --git a/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.scene.ts b/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.scene.ts index 78be61bcab..e84a6709e8 100644 --- a/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.scene.ts +++ b/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.scene.ts @@ -66,6 +66,7 @@ export class RcjScoringTool implements IObserver { private prevNextCheckPoint: {}; private programPaused: boolean = true; private victimsLocated: number = 0; + private victimsLiveLocated: number = 0; private linePoints: number = 5; private obstaclePoints: number = 0; private totalScore: number = 0; @@ -96,13 +97,32 @@ export class RcjScoringTool implements IObserver { $('#rcjStartStop').addClass('running'); return false; } else { - $(this).html('Start
Scoring Run'); + rcj.programPaused = true; clearInterval(rcj.stopWatch); + const factor = Math.max(rcj.POINTS_VICTIM_MULTI - 0.05 * rcj.loPCounter, 1.25); + for (let i = 0; i < rcj.victimsLocated; i++) { + if (rcj.victimsLiveLocated > 0) { + rcj.rescueMulti *= factor; + } + else { + rcj.rescueMulti *= rcj.POINTS_DEADONLY_VICTIM_MULTI; + } + } + rcj.totalScore = (rcj.linePoints + rcj.obstaclePoints) * rcj.rescueMulti; + rcj.totalScore = UTIL.round(rcj.totalScore, 2); + + $('#rcjLoPpS').text(rcj.loPCounter); + $('#rcjLoPCount').text(rcj.loPSum); + $('#rcjRescueMulti').text(Math.round(rcj.rescueMulti * 100) / 100); + $('#rcjLinePoints').text(rcj.linePoints); + $('#rcjObstaclePoints').text(rcj.obstaclePoints); + $('#rcjTotalScore').text(rcj.totalScore); + + $(this).html('Start
Scoring Run'); $('#rcjStartStop').removeClass('running'); $('#rcjLoP').addClass('disabled'); $('#rcjNextCP').addClass('disabled'); rcj.robot && rcj.robot.interpreter.terminate(); - rcj.programPaused = true; return false; } }); @@ -245,6 +265,7 @@ export class RcjScoringTool implements IObserver { this.loPSum = 0; this.section = 0; this.victimsLocated = 0; + this.victimsLiveLocated = 0; this.linePoints = 5; this.obstaclePoints = 0; this.totalScore = 0; @@ -397,21 +418,15 @@ export class RcjScoringTool implements IObserver { this.totalScore = UTIL.round(this.totalScore, 2); } else if (simObject instanceof CircleSimulationObject) { let circle: CircleSimulationObject = simObject; - const factor = Math.max(this.POINTS_VICTIM_MULTI - 0.05 * this.loPCounter, 1.25); if (circle.inEvacuationZone && circle.color === '#33B8CA') { circle.selected = true; $('#simDeleteObject').trigger('click'); - this.rescueMulti *= factor; this.victimsLocated += 1; + this.victimsLiveLocated += 1; } if (circle.inEvacuationZone && circle.color === '#000000') { circle.selected = true; $('#simDeleteObject').trigger('click'); - if (this.victimsLocated > 1) { - this.rescueMulti *= factor; - } else { - this.rescueMulti *= this.POINTS_DEADONLY_VICTIM_MULTI; - } this.victimsLocated += 1; } }