var canvas; const WAITING = 0; const RUNNING = 1; const REVIEWING = 2; const TESTING = 3; const FINISH = 4; const UP = 0; const RIGHT = 1; const DOWN = 2; const LEFT = 3; const RED = "R"; const BLUE = "B"; const GREEN = "G"; const YELLOW = "Y"; const PURPLE = "P"; const PINK = "PI"; const BLACK = "BL"; const GRAY = "GR"; const ALIVE = 0; const DEAD = 1; const DONE = 2; var BOT_X = -1 var BOT_Y = -1 var BOT_DIR = RIGHT var BOT_STATE = ALIVE var BOT_TAPE = "RB" var BOT_QUEUE = [] var BELTDOWN = {type:"BELT",direction:DOWN/*,direction2 - defines a secondary direction. For two belts at once.*/} var BELTRIGHT = {type:"BELT",direction:RIGHT} var BELTUP = {type:"BELT",direction:UP} var BELTLEFT = {type:"BELT",direction:LEFT} var BRANCHDOWN = {type:"BRANCH",direction:DOWN,color1:RED,color2:BLUE} //color 1 points clockwise(right), color 2 points counter-clockwise(left) var BRANCHLEFT = {type:"BRANCH",direction:LEFT,color1:RED,color2:BLUE} var BRANCHRIGHT = {type:"BRANCH",direction:RIGHT,color1:RED,color2:BLUE} var BRANCHUP = {type:"BRANCH",direction:UP,color1:RED,color2:BLUE} var WRITERDOWN = {type:"WRITER",direction:DOWN,color:RED/*overwrite - if turned on, the writer overwrites the current tape position instead of appending.*/} var WRITERLEFT = {type:"WRITER",direction:LEFT,color:RED} var WRITERRIGHT = {type:"WRITER",direction:RIGHT,color:RED} var WRITERUP = {type:"WRITER",direction:UP,color:RED} var DEF_BRANCHDOWN_RB = {img:IMAGE_BRANCH,color1:RED,color2:BLUE} var DEF_BRANCHDOWN_BR = {img:IMAGE_BRANCH,color1:BLUE,color2:RED} var DEF_BRANCHDOWN_GY = {img:IMAGE_BRANCH,color1:GREEN,color2:YELLOW} var DEF_BRANCHDOWN_YG = {img:IMAGE_BRANCH,color1:YELLOW,color2:GREEN} var DEF_BRANCHDOWN_PPI = {img:IMAGE_BRANCH,color1:PURPLE,color2:PINK} var DEF_BRANCHDOWN_PIP = {img:IMAGE_BRANCH,color1:PINK,color2:PURPLE} var DEF_BRANCHDOWN_BLGR = {img:IMAGE_BRANCH,color1:BLACK,color2:GRAY} var DEF_BRANCHDOWN_GRBL = {img:IMAGE_BRANCH,color1:GRAY,color2:BLACK} var GRID_W = 32 var GRID_H = 32 var GRID_X = 20 var GRID_Y = 20 var LAST_MOUSE_X=0; var LAST_MOUSE_Y=0; var SUBMENU = { visible:true, width:0, height:0, buttons:[] } var BUTTON_SELECTED = undefined var CONVEYOR_BUILD_BUTTON = {img:IMAGE_CONVEYOR,x:-1,y:-1,w:-1,h:-1} var BRANCH_BUILD_BUTTON = {img:IMAGE_BRANCH,x:-1,y:-1,w:-1,h:-1} var WRITER_BUILD_BUTTON = {img:IMAGE_WRITER,x:-1,y:-1,w:-1,h:-1} var MENU = { visible:true, buttons:[CONVEYOR_BUILD_BUTTON,BRANCH_BUILD_BUTTON,WRITER_BUILD_BUTTON] } var lastGameUpdate = 0; var gameSpeed = 1000/1; var gameState=RUNNING; var gameStage=0; var LEVEL0 = [ [{},{},{},{},{},], [{},{},{},{},{},], [{},{},{},{},{},], [{},{},{},{},{},], [{},{},{},{},{},],] var LEVEL1 = [ [{},{},{...BELTDOWN},{...BELTLEFT},{...BELTLEFT},], [{},{},{},{},{...BELTUP},], [{},{...BELTDOWN},{},{},{...BELTUP},], [{},{...BELTRIGHT},{...BELTRIGHT},{...BELTRIGHT},{...BELTUP},], [{},{},{},{},{},],] var LEVEL2 = [ [{},{},{},{},{},], [{},{...BELTRIGHT},{},{},{},], //BLUE [{},{...BRANCHRIGHT},{},{},{},], [{},{...BELTRIGHT},{},{},{},], //RED [{},{},{},{},{},],] var LEVEL3 = [ [{},{},{},{},{},], [{},{...WRITERUP,overwrite:true},{},{},{},], [{},{...WRITERDOWN},{},{},{},], [{},{...BELTRIGHT},{},{},{},], [{},{},{},{},{},],] var LEVEL4 = [ [{},{},{},{},{},], [{},{},{},{},{},], [{},{...BELTRIGHT,direction2:DOWN},{},{},{},], [{},{},{...BELTUP,direction2:LEFT},{},{},], [{},{},{},{},{},],] var STAGE1 = { name:"The First Stage!", objective:"Accept all bots", level:createGrid(5,5,4,2), start:{x:0,y:2}, accept:(tape)=>true} var STAGE2 = { name:"Blue Blue", objective:"Accept only Blue Bots", level:createGrid(5,5,4,2), start:{x:0,y:2}, accept:(tape)=>{ for (var i=0;i0) { var mask = remainingVal&1 if (mask===1) { tape="B"+tape } else { tape="R"+tape } remainingVal=remainingVal>>>1 } return tape; } function runBot(testing) { //console.log(new Date().getTime()) if (lastGameUpdate