Implement original starting tape display, add writer tape implementation, and show dots instead of letters for expected results

master
sigonasr2 5 years ago
parent f64b313999
commit 65eb842b22
  1. 129
      game.js

@ -117,6 +117,7 @@ var BOT_Y = -1
var BOT_DIR = RIGHT var BOT_DIR = RIGHT
var BOT_STATE = ALIVE var BOT_STATE = ALIVE
var BOT_TAPE = "RB" var BOT_TAPE = "RB"
var BOT_START_TAPE = BOT_TAPE
var BOT_QUEUE = [] var BOT_QUEUE = []
var DELETEMODE = false var DELETEMODE = false
var DRAGGING = false var DRAGGING = false
@ -125,6 +126,7 @@ var LAST_MOUSE_X=0;
var LAST_MOUSE_Y=0; var LAST_MOUSE_Y=0;
var DRAG_X = -1 var DRAG_X = -1
var DRAG_Y = -1 var DRAG_Y = -1
var BOT_DID_NOT_REACH_EXIT = false
var MESSAGETIMER = -1 var MESSAGETIMER = -1
var EXPECTED = true //True means the bot was supposed to accepted, false means the bot was supposed to be rejected. var EXPECTED = true //True means the bot was supposed to accepted, false means the bot was supposed to be rejected.
@ -249,7 +251,12 @@ function runGameSimulation(){
BOT_TAPE=BOT_QUEUE[0] BOT_TAPE=BOT_QUEUE[0]
} else { } else {
BOT_TAPE=ConvertNumberToTape(Math.floor(Math.random()*1000)) BOT_TAPE=ConvertNumberToTape(Math.floor(Math.random()*1000))
if (Math.random()<0.5) {
BOT_TAPE=BOT_TAPE.split("").reverse().join("")
} }
EXPECTED=gameStage.accept(BOT_TAPE)
}
BOT_START_TAPE=BOT_TAPE
BOT_X=gameStage.start.x BOT_X=gameStage.start.x
BOT_Y=gameStage.start.y BOT_Y=gameStage.start.y
BOT_PREVX=BOT_X BOT_PREVX=BOT_X
@ -425,7 +432,7 @@ var TUTORIAL3 = {
start:{x:0,y:2}, start:{x:0,y:2},
tutorial:true, tutorial:true,
accept:(tape)=>{ accept:(tape)=>{
return true; return tape+BLUE+BLUE+BLUE
} }
} }
var TUTORIAL4 = { var TUTORIAL4 = {
@ -434,7 +441,11 @@ var TUTORIAL4 = {
level:createGrid(5,5,4,2), level:createGrid(5,5,4,2),
start:{x:0,y:2}, start:{x:0,y:2},
accept:(tape)=>{ accept:(tape)=>{
return true; var newTape = ""
for (var i=0;i<tape.length;i++) {
newTape+=YELLOW
}
return newTape
} }
} }
@ -515,49 +526,62 @@ function resetGame() {
completedStages={} completedStages={}
} }
function generateBotQueue() { function decideIfWrongBot(wrongBot,isSupposedToBeAccepted,tape) {
BOT_QUEUE=[] var result;
RESULT=true switch (typeof(isSupposedToBeAccepted)) {
TESTSTEPS=0 case "string":{
if (gameState===TESTING) { if (getSimulatedBotResult(tape)) {
//Iterate up to...15 RED/BLUE combinations. result = BOT_TAPE
var MAX_VALUE=1000
var startingValue=0
while (startingValue<MAX_VALUE) {
var tape=ConvertNumberToTape(startingValue++)
//console.log(tape)
var wrongBot=false //Set to true if a bot that's supposed to pass fails, or a bot that's supposed to fail passes.
var isSupposedToBeAccepted=gameStage.accept(tape)
var result=getSimulatedBotResult(tape)
if (result===isSupposedToBeAccepted) { if (result===isSupposedToBeAccepted) {
wrongBot=false; wrongBot=false;
} else { } else {
wrongBot=true; wrongBot=true;
} }
if (wrongBot) { } else {
if (BOT_QUEUE.length===0) { if (BOT_QUEUE.length===0) {
EXPECTED = isSupposedToBeAccepted; BOT_DID_NOT_REACH_EXIT=true
} }
RESULT=false wrongBot=true;
BOT_QUEUE.push(tape)
} }
var reversedTape=tape.split("").reverse().join("") }break;
//console.log(tape) case "boolean":{
var wrongBot=false //Set to true if a bot that's supposed to pass fails, or a bot that's supposed to fail passes. result = getSimulatedBotResult(tape)
var isSupposedToBeAccepted=gameStage.accept(reversedTape)
var result=getSimulatedBotResult(reversedTape)
if (result===isSupposedToBeAccepted) { if (result===isSupposedToBeAccepted) {
wrongBot=false; wrongBot=false;
} else { } else {
wrongBot=true; wrongBot=true;
} }
}break;
}
if (wrongBot) { if (wrongBot) {
if (BOT_QUEUE.length===0) { if (BOT_QUEUE.length===0) {
EXPECTED = isSupposedToBeAccepted; EXPECTED = isSupposedToBeAccepted;
} }
RESULT=false RESULT=false
BOT_QUEUE.push(reversedTape) BOT_QUEUE.push(tape)
} }
}
function generateBotQueue() {
BOT_QUEUE=[]
RESULT=true
TESTSTEPS=0
BOT_DID_NOT_REACH_EXIT=false
if (gameState===TESTING) {
//Iterate up to...15 RED/BLUE combinations.
var MAX_VALUE=1000
var startingValue=0
while (startingValue<MAX_VALUE) {
var tape=ConvertNumberToTape(startingValue++)
//console.log(tape)
var wrongBot=false //Set to true if a bot that's supposed to pass fails, or a bot that's supposed to fail passes.
var isSupposedToBeAccepted=gameStage.accept(tape)
decideIfWrongBot(wrongBot,isSupposedToBeAccepted,tape)
var reversedTape=tape.split("").reverse().join("")
//console.log(tape)
var wrongBot=false //Set to true if a bot that's supposed to pass fails, or a bot that's supposed to fail passes.
var isSupposedToBeAccepted=gameStage.accept(reversedTape)
decideIfWrongBot(wrongBot,isSupposedToBeAccepted,reversedTape)
if (BOT_QUEUE.length>=3) { if (BOT_QUEUE.length>=3) {
break; break;
} }
@ -1260,14 +1284,48 @@ function RenderGameInfo(ctx) {
drawImage(canvas.width-18,14,ID_INCOMPLETE_STAR,ctx,0,0.75) drawImage(canvas.width-18,14,ID_INCOMPLETE_STAR,ctx,0,0.75)
} }
RenderTape(canvas.width*0.75+8,16,canvas.width*0.25-16,ctx) if (gameState===REVIEWING||gameState===FINISH) {
ctx.fillStyle="#20424a"
ctx.globalAlpha=0.6
ctx.fillRect(canvas.width*0.75-canvas.width*0.25,4,canvas.width*0.25,5*12+28)
ctx.globalAlpha=1
ctx.font="bold 16px 'Zilla Slab', serif"
ctx.textAlign = "left"
ctx.strokeStyle="rgb(90, 148, 118)"
ctx.strokeText("Original Tape",canvas.width*0.75-canvas.width*0.25,20)
ctx.fillStyle="black"
ctx.fillText("Original Tape",canvas.width*0.75-canvas.width*0.25,20)
RenderTape(canvas.width*0.75-canvas.width*0.25+8,16,canvas.width*0.25-16,ctx,BOT_START_TAPE)
}
RenderTape(canvas.width*0.75+8,16,canvas.width*0.25-16,ctx,BOT_TAPE)
if (gameState===RUNNING||gameState===REVIEWING||gameState===FINISH||gameState===PAUSED) { if (gameState===RUNNING||gameState===REVIEWING||gameState===FINISH||gameState===PAUSED) {
ctx.font="16px 'Zilla Slab', serif" ctx.font="16px 'Zilla Slab', serif"
ctx.fillStyle="white" ctx.fillStyle="white"
ctx.textAlign = "center" ctx.textAlign = "center"
ctx.fillText("Expected Result: ",canvas.width-canvas.width*0.25/2,canvas.height-120-40)
switch (typeof(EXPECTED)) {
case "string":{
ctx.fillText("Expected Result: ",canvas.width-canvas.width*0.25/2,canvas.height/2-52)
ctx.fillStyle="rgb(52, 235, 140)"
RenderTape(canvas.width*0.75+8,canvas.height/2-52,canvas.width*0.25-16,ctx,EXPECTED)
if (RESULT) {
ctx.fillStyle="rgb(52, 235, 140)"
ctx.fillText("PASSED",canvas.width-canvas.width*0.25/2,canvas.height/2+24)
} else {
if (BOT_DID_NOT_REACH_EXIT) {
ctx.fillStyle="rgb(235, 98, 52)"
ctx.fillText("DID NOT EXIT",canvas.width-canvas.width*0.25/2,canvas.height/2+24)
} else {
ctx.fillStyle="rgb(235, 98, 52)"
ctx.fillText("FAILED",canvas.width-canvas.width*0.25/2,canvas.height/2+24)
}
}
}break;
case "boolean":{
ctx.fillText("Expected Result: ",canvas.width-canvas.width*0.25/2,canvas.height-120-40)
if (EXPECTED) { if (EXPECTED) {
ctx.fillStyle="rgb(52, 235, 140)" ctx.fillStyle="rgb(52, 235, 140)"
ctx.fillText(" ACCEPT",canvas.width-canvas.width*0.25/2,canvas.height-100-40) ctx.fillText(" ACCEPT",canvas.width-canvas.width*0.25/2,canvas.height-100-40)
@ -1275,6 +1333,8 @@ function RenderGameInfo(ctx) {
ctx.fillStyle="rgb(235, 98, 52)" ctx.fillStyle="rgb(235, 98, 52)"
ctx.fillText(" REJECT",canvas.width-canvas.width*0.25/2,canvas.height-100-40) ctx.fillText(" REJECT",canvas.width-canvas.width*0.25/2,canvas.height-100-40)
} }
}break;
}
} }
if (ISTESTING) { if (ISTESTING) {
@ -1331,15 +1391,16 @@ function RenderGameInfo(ctx) {
} }
} }
function RenderTape(x,y,width,ctx) { function RenderTape(x,y,width,ctx,tape) {
var xOffset=0 var xOffset=0
var yOffset=0 var yOffset=0
var ySpacingMult=1 var ySpacingMult=1
if (BOT_TAPE.length>5*5) { var ySpacing=12
ySpacingMult=(24*5)/(Math.ceil(BOT_TAPE.length/5)*24) if (tape.length>5*5) {
ySpacingMult=(ySpacing*5)/(Math.ceil(tape.length/5)*ySpacing)
} }
for (var i=0;i<Math.min(BOT_TAPE.length,1024);i++) { for (var i=0;i<Math.min(tape.length,1024);i++) {
switch (BOT_TAPE[i]) { switch (tape[i]) {
case RED:{ case RED:{
drawImage(x+xOffset+16,y+yOffset+16,ID_DOT_R,ctx,0) drawImage(x+xOffset+16,y+yOffset+16,ID_DOT_R,ctx,0)
}break; }break;
@ -1370,7 +1431,7 @@ function RenderTape(x,y,width,ctx) {
xOffset+=24; xOffset+=24;
if (xOffset>width-24) { if (xOffset>width-24) {
xOffset=0; xOffset=0;
yOffset+=24*ySpacingMult; yOffset+=ySpacing*ySpacingMult;
} }
} }
} }

Loading…
Cancel
Save