constBINARY_TEST=4;//Generates valid binary numbers (never has a trailing R)
constBSTAGE2_TEST=2;
constTWO_NUMBERS_TEST=5;//Generates two binary numbers separated by a green dot.
constSUBSTRING_TEST=6;//Generates two yellow dots to indicate a substring to cut out.
constUPPERCASE_CHARACTER_TEST=7;//Generates uppercase letters separated by yellow.
constTWO_UNEQUAL_NUMBERS_TEST=8;//Two unequal numbers will be generated separated by a green.
constNONE=0;
constBINARY=1;
@ -130,6 +139,7 @@ var BOT_Y = -1
varBOT_DIR=RIGHT
varBOT_STATE=ALIVE
varBOT_TAPE="RB"
varGHOST_BOT_TAPE="RB"
varBOT_START_TAPE=BOT_TAPE
varBOT_QUEUE=[]
varDELETEMODE=false
@ -292,6 +302,8 @@ function goHome() {
MENU.visible=false
BRIDGEDBELT=false
setMoveMode(false)
BOT_TAPE=""
GHOST_BOT_TAPE=""
GRID_X=20
GRID_Y=20
ITEM_SELECTED=undefined
@ -312,39 +324,38 @@ function runGameSimulation(){
BOT_PREVX=-100
BOT_PREVY=-100
BOT_TAPE=""
GHOST_BOT_TAPE=""
ITEM_SELECTED=undefined
BOT_START_TAPE=undefined
if(gameSpeed===-1){
gameSpeed=1000/1
}
setMoveMode(false)
generateBotQueue()
//console.log(BOT_QUEUE)
setTimeout(()=>{
ISTESTING=false
if(BOT_QUEUE.length>0){
BOT_TAPE=BOT_QUEUE[0]
}else{
BOT_TAPE=TEST_RANDOM_TAPE
EXPECTED=gameStage.accept(BOT_TAPE)
}
BOT_START_TAPE=BOT_TAPE
BOT_X=gameStage.start.x
BOT_Y=gameStage.start.y
BOT_PREVX=BOT_X
BOT_PREVY=BOT_Y
BOT_STATE=ALIVE
gameState=WAITING
BOT_DIR=RIGHT
gameState=RUNNING
if(gameSpeed===-1){
gameSpeed=1000/1
}
gameState=RUNNING
MESSAGETIMER=newDate().getTime()+3000
for(vari=0;i<MENU.buttons.length;i++){
if(MENU.buttons[i].img===ID_PLAY){
MENU.buttons[i]=PAUSE_BUTTON
break;
}
ISTESTING=false
if(BOT_QUEUE.length>0){
BOT_TAPE=BOT_QUEUE[0]
}else{
BOT_TAPE=TEST_RANDOM_TAPE
EXPECTED=gameStage.accept(BOT_TAPE)
}
BOT_START_TAPE=BOT_TAPE
BOT_X=gameStage.start.x
BOT_Y=gameStage.start.y
BOT_PREVX=BOT_X
BOT_PREVY=BOT_Y
BOT_STATE=ALIVE
gameState=WAITING
BOT_DIR=RIGHT
gameState=RUNNING
gameState=RUNNING
MESSAGETIMER=newDate().getTime()+3000
for(vari=0;i<MENU.buttons.length;i++){
if(MENU.buttons[i].img===ID_PLAY){
MENU.buttons[i]=PAUSE_BUTTON
break;
}
},300)
}
}
gameState=RUNNING
for(vari=0;i<MENU.buttons.length;i++){
@ -489,6 +500,423 @@ var STAGE3 = {
returnblues===reds;
}
}
varBSTAGE1={
name:"Bloody Red",
objective:`Output just the ${RED} markers from a bot.`,
level:createGrid(5,5,4,4),
start:{x:0,y:0},
accept:(tape)=>{
varfinalTape=""
for(vari=0;i<tape.length;i++){
if(tape[i]===RED){
finalTape+=RED
}
}
returnfinalTape
},
//generator:BLANK_TEST,
//display:STRING
}
varBSTAGE2={
name:"Crazy Conversion",
objective:`Given that ${YELLOW}=${RED}, ${GREEN}=${BLUE}${BLUE}${RED}, ${PURPLE}=${BLUE}${RED}, ${PINK}=${RED}${RED}${RED}, ${BLACK}=${RED}${BLUE}, ${GRAY}=${BLUE}, convert all the bots to the correct ${RED} and ${BLUE} values.`,
level:createGrid(11,11,10,0),
start:{x:0,y:10},
accept:(tape)=>{
varfinalTape=""
for(vari=0;i<tape.length;i++){
switch(tape[i]){
caseYELLOW:{
finalTape+=`${RED}`
}break;
caseGREEN:{
finalTape+=`${BLUE}${BLUE}${RED}`
}break;
casePURPLE:{
finalTape+=`${BLUE}${RED}`
}break;
casePINK:{
finalTape+=`${RED}${RED}${RED}`
}break;
caseBLACK:{
finalTape+=`${RED}${BLUE}`
}break;
caseGRAY:{
finalTape+=`${BLUE}`
}break;
}
}
returnfinalTape
},
generator:BSTAGE2_TEST,
//display:STRING
}
varBSTAGE3={
name:"Double Trouble",
objective:`For every dot on the tape, double the output. Ex. ${RED}${RED}${RED}${BLUE} should output ${RED}${RED}${RED}${RED}${RED}${RED}${BLUE}${BLUE}.`,
level:createGrid(5,5,4,4),
start:{x:0,y:0},
accept:(tape)=>{
varfinalTape=""
for(vari=0;i<tape.length;i++){
finalTape+=tape[i]+tape[i]
}
returnfinalTape
},
//generator:BLANK_TEST,
//display:STRING
}
varBSTAGE4={
name:"Back of the line",
objective:`Replace the last marker on the tape with a ${YELLOW} marker.`,
level:createGrid(5,5,4,4),
start:{x:0,y:0},
accept:(tape)=>{
varfinalTape=tape.substring(0,tape.length-1)
finalTape+=YELLOW
returnfinalTape
},
//generator:BLANK_TEST,
//display:STRING
}
varBSTAGE5={
name:"Back and Forth",
objective:`Accept robots that have alternating colors.`,
level:createGrid(7,7,6,6),
start:{x:0,y:0},
accept:(tape)=>{
varfinalTape=""
varlastCol=""
for(vari=0;i<tape.length;i++){
if(tape[i]===lastCol){
returnfalse
}else{
lastCol=tape[i]
}
}
returntrue
},
//generator:BLANK_TEST,
//display:STRING
}
varBSTAGE6={
name:"#olcCodeJam2020",
objective:`Output the string "#olcCodeJam2020", using Binary ASCII characters (${RED}=0 ${BLUE}=1) and using ${YELLOW} markers as a separator. Ex: "A"=65=${BLUE}${RED}${RED}${RED}${RED}${RED}${BLUE}, "b"=98=${RED}${BLUE}${RED}${RED}${RED}${BLUE}${BLUE}`,
level:createGrid(12,12,11,11),
start:{x:0,y:0},
accept:(tape)=>{
return{string:"#olcCodeJam2020"}
},
generator:BLANK_TEST,
display:STRING
}
varBSTAGE7={
name:"End-to-End",
objective:`Accept robots that have the same first and last colors on their tapes. Ex: ${RED}${BLUE}${RED} is accepted, ${RED}${BLUE}${BLUE} is not.`,
level:createGrid(7,7,6,6),
start:{x:0,y:0},
accept:(tape)=>{
varfirst=""
varlast=""
if(tape.length>0){
first=tape[0]
last=tape[tape.length-1]
}
returnfirst===last
},
//generator:BLANK_TEST,
//display:STRING
}
varBSTAGE8={
name:"Greatest Count",
objective:`Given an odd number of ${BLUE}s and ${RED}s, determine if there are more ${BLUE}s or more ${RED}s and only return those markers. Ex: ${BLUE}${BLUE}${BLUE}${RED}${RED} should output as ${BLUE}${BLUE}${BLUE} (3>2)`,
level:createGrid(9,9,8,8),
start:{x:0,y:0},
accept:(tape)=>{
varblues=""
varreds=""
for(vari=0;i<tape.length;i++){
if(tape[i]===BLUE){
blues+=BLUE
}else
if(tape[i]===RED){
reds+=RED
}
}
return(blues.length>reds.length)?blues:reds
},
generator:ODD_LENGTH_TEST,
//display:STRING
}
varISTAGE2={
name:"Oddly Even",
objective:`Accepts bots that have an even length of tape.`,
level:createGrid(7,7,6,6),
start:{x:0,y:0},
accept:(tape)=>{
returntape.length%2===0
},
//generator:BLANK_TEST,
//display:STRING
}
varISTAGE3={
name:"Add One",
objective:`Given a tape representing binary (${RED}=0 ${BLUE}=1), add 1 to the number. Ex: ${BLUE}${RED}${BLUE}(5) should output ${BLUE}${BLUE}${RED}(6)`,
level:createGrid(9,9,8,8),
start:{x:0,y:0},
accept:(tape)=>{
varanswer=tapeToBinary(tape)+1
returnbinaryToTape(answer)
},
generator:BINARY_TEST,
display:BINARY
}
varISTAGE4={
name:"String Length",
objective:`Return the number of ${RED}s from a bot as a binary number (${RED}=0 ${BLUE}=1). Ex: ${RED}${RED}${RED}${BLUE}${RED} should output as ${BLUE}${RED}${RED} (4 ${RED}s)`,
level:createGrid(13,13,12,12),
start:{x:0,y:0},
accept:(tape)=>{
varreds=0
for(vari=0;i<tape.length;i++){
if(tape[i]===RED){
reds++
}
}
returnbinaryToTape(reds)
},
//generator:BINARY_TEST,
display:BINARY
}
varISTAGE1={
name:"Blue In Blue Out",
objective:`Output the tape with all the ${BLUE}s moved to the front.`,
level:createGrid(7,7,6,6),
start:{x:0,y:0},
accept:(tape)=>{
varblues=""
varreds=""
for(vari=0;i<tape.length;i++){
if(tape[i]===BLUE){
blues+=BLUE
}else
if(tape[i]===RED){
reds+=RED
}
}
returnblues+reds
},
//generator:BINARY_TEST,
//display:BINARY
}
varISTAGE5={
name:"NoLemonsNoMelon",
objective:`Accept bots that are a palindrome. Ex: ${BLUE}${RED}${RED}${BLUE} is a palindrome, ${BLUE}${RED}${BLUE} is a palindrome, ${BLUE}${RED}${BLUE}${RED} is not a palindrome.`,
level:createGrid(7,7,6,6),
start:{x:0,y:0},
accept:(tape)=>{
for(vari=0;i<tape.length/2;i++){
if(tape[i]!==tape[tape.length-1-i]){
returnfalse;
}
}
returntrue;
},
//generator:ODD_LENGTH_TEST,
//display:BINARY
}
varISTAGE6={
name:"Is Equal To",
objective:`Given 2 binary numbers (${RED}=0 ${BLUE}=1) separated by a ${GREEN} marker, accept bots where the 2 numbers are equal. Ex. ${RED}${BLUE}${RED}${GREEN}${RED}${BLUE}${RED} (2/2) should be accepted while ${BLUE}${RED}${GREEN}${RED}${BLUE} (2/1) should not be.`,
level:createGrid(11,11,10,10),
start:{x:0,y:0},
accept:(tape)=>{
vartemp=""
varnumber1=-1
varnumber2=-1
for(vari=0;i<tape.length;i++){
if(tape[i]===GREEN){
if(number1===-1){
number1=tapeToBinary(temp)
}
temp=""
}else{
temp+=tape[i]
}
}
number2=tapeToBinary(temp)
returnnumber1===number2
},
generator:TWO_NUMBERS_TEST,
display:BINARY
}
varISTAGE7={
name:"Substring",
objective:`Given a tape with 2 ${YELLOW} markers, return all the contents between the 2 ${YELLOW} markers. Ex: ${BLUE}${RED}${YELLOW}${RED}${RED}${BLUE}${YELLOW}${RED}${RED}${RED} should output ${RED}${RED}${BLUE}`,
level:createGrid(7,7,6,6),
start:{x:0,y:0},
accept:(tape)=>{
varfound=""
varstart=false
for(vari=0;i<tape.length;i++){
if(tape[i]===YELLOW){
if(!start){
start=true
}else{
break;
}
}else{
if(start){
found+=tape[i]
}
}
}
returnfound;
},
generator:SUBSTRING_TEST,
//display:BINARY
}
varISTAGE8={
name:"Reversal",
objective:`Reverse the input string. Ex: ${BLUE}${BLUE}${RED}${BLUE}${BLUE} -> ${BLUE}${BLUE}${RED}${BLUE}${BLUE}${RED}${RED}${RED}`,
level:createGrid(11,11,10,10),
start:{x:0,y:0},
accept:(tape)=>{
returntape.split("").reverse().join("")
},
//generator:SUBSTRING_TEST,
//display:BINARY
}
varASTAGE1={
name:"Right in the Center",
objective:`Given an even length tape, add a ${YELLOW} marker in the middle of it.`,
objective:`Given a string of uppercase ASCII binary characters (${RED}=0 ${BLUE}=1) separated by ${YELLOW}, convert all uppercase to lowercase. Ex: "HI"= ${BLUE}${RED}${RED}${BLUE}${RED}${RED}${RED}Y${BLUE}${RED}${RED}${BLUE}${RED}${RED}${BLUE} output as "hi"= ${BLUE}${BLUE}${RED}${BLUE}${RED}${RED}${RED}Y${BLUE}${BLUE}${RED}${BLUE}${RED}${RED}${BLUE}`,
level:createGrid(25,25,24,24),
start:{x:0,y:0},
accept:(tape)=>{
varchars=tape.split(YELLOW)
varfinalString=""
for(vari=0;i<chars.length;i++){
chars[i]=binaryToTape(tapeToBinary(chars[i])+32)
}
returnchars.join(YELLOW)
},
generator:UPPERCASE_CHARACTER_TEST,
display:STRING
}
varASTAGE3={
name:"Addition",
objective:`Given 2 binary numbers (R=0 B=1) separated by a green dot, output the addition of those two numbers.`,
level:createGrid(15,15,14,14),
start:{x:0,y:0},
accept:(tape)=>{
vartemp=""
varnumber1=-1
varnumber2=-1
for(vari=0;i<tape.length;i++){
if(tape[i]===GREEN){
if(number1===-1){
number1=tapeToBinary(temp)
}
temp=""
}else{
temp+=tape[i]
}
}
number2=tapeToBinary(temp)
returnbinaryToTape(number1+number2)
},
generator:TWO_NUMBERS_TEST,
display:BINARY
}
varASTAGE4={
name:"The Great Conversion",
objective:`Convert every other ${RED} to ${BLUE}${GREEN}, then for every found ${BLUE}${RED} sequence, turn them into ${RED}${RED} and run the checks again. Ex: ${RED}${RED}${BLUE}${BLUE}${RED}${BLUE}${BLUE}${BLUE}${RED} -> ${RED}${BLUE}${GREEN}${BLUE}${BLUE}${RED}${BLUE}${BLUE}${BLUE}${BLUE}${GREEN} -> ${RED}${BLUE}${GREEN}${BLUE}${RED}${RED}${BLUE}${BLUE}${BLUE}${BLUE}${GREEN} -> ${RED}${BLUE}${GREEN}${BLUE}${BLUE}${GREEN}${RED}${BLUE}${BLUE}${BLUE}${BLUE}${GREEN}`,
level:createGrid(13,13,6,6),
start:{x:0,y:6},
accept:(tape)=>{
varfirst=false;
varnewString=""
varfound=true
varlimit=2
while(found&&limit-->0){
found=false
first=false
//Red->Blue-Green
for(vari=0;i<tape.length;i++){
if(tape[i]===RED){
if(first){
found=true
newString+=BLUE+GREEN
first=false
}else{
newString+=RED
first=true
}
}else{
newString+=tape[i]
}
}
tape=newString
newString=""
//BR -> RR
varlast=""
for(vari=0;i<tape.length;i++){
if(tape[i]===BLUE){
if(i+1<tape.length&&tape[i+1]===RED){
newString+=RED+RED
i+=1
}else{
newString+=tape[i]
}
}else
{
newString+=tape[i]
}
}
tape=newString
newString=""
}
returntape
},
//generator:TWO_NUMBERS_TEST,
//display:BINARY
}
varASTAGE5={
name:"Compare",
objective:`Given 2 distinct binary values (${RED}=0 ${BLUE}=1) separated by a green dot, output the greater of the two numbers Ex: ${BLUE}${BLUE}${BLUE}${RED}${BLUE}${GREEN}${BLUE}${BLUE}${RED}${RED}${RED} (29/24) outputs as ${BLUE}${BLUE}${BLUE}${RED}${BLUE} (29>24)`,
objective:"To convert your robots, you must send them from the entrance to the exit. Select a belt and send robots to where they truly belong. Press the Play button to test your machine!",
@ -541,6 +969,15 @@ var TUTORIAL4 = {
returnnewTape
}
}
varSANDBOX={
name:"The Sandbox",
objective:"You may experiment freely in this very large room.",