diff --git a/game.js b/game.js
index 4570206..806f3a1 100644
--- a/game.js
+++ b/game.js
@@ -95,10 +95,19 @@ const TITLE = 7;
const STARTUP = 8;
const INFO = 9;
+var WAITINGTOFINISH=false
+
const ONE_TEST = -1;
const BLANK_TEST = -2;
const NORMAL_TEST = 0;
const EVEN_LENGTH_TEST = 1; //Only generate even length tapes.
+const ODD_LENGTH_TEST = 3; //Only generates odd length tapes.
+const BINARY_TEST = 4; //Generates valid binary numbers (never has a trailing R)
+const BSTAGE2_TEST = 2;
+const TWO_NUMBERS_TEST = 5; //Generates two binary numbers separated by a green dot.
+const SUBSTRING_TEST = 6; //Generates two yellow dots to indicate a substring to cut out.
+const UPPERCASE_CHARACTER_TEST = 7; //Generates uppercase letters separated by yellow.
+const TWO_UNEQUAL_NUMBERS_TEST = 8; //Two unequal numbers will be generated separated by a green.
const NONE = 0;
const BINARY = 1;
@@ -130,6 +139,7 @@ var BOT_Y = -1
var BOT_DIR = RIGHT
var BOT_STATE = ALIVE
var BOT_TAPE = "RB"
+var GHOST_BOT_TAPE = "RB"
var BOT_START_TAPE = BOT_TAPE
var BOT_QUEUE = []
var DELETEMODE = 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=new Date().getTime()+3000
- for (var i=0;i
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=new Date().getTime()+3000
+ for (var i=0;i{
+ var finalTape=""
+ for (var i=0;i{
+ var finalTape=""
+ for (var i=0;i{
+ var finalTape=""
+ for (var i=0;i{
+ var finalTape = tape.substring(0,tape.length-1)
+ finalTape+=YELLOW
+ return finalTape
+ },
+ //generator:BLANK_TEST,
+ //display:STRING
+}
+var BSTAGE5 = {
+ name:"Back and Forth",
+ objective:`Accept robots that have alternating colors.`,
+ level:createGrid(7,7,6,6),
+ start:{x:0,y:0},
+ accept:(tape)=>{
+ var finalTape=""
+ var lastCol=""
+ for (var i=0;i{
+ return {string:"#olcCodeJam2020"}
+ },
+ generator:BLANK_TEST,
+ display:STRING
+}
+var BSTAGE7 = {
+ 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)=>{
+ var first=""
+ var last=""
+ if (tape.length>0) {
+ first=tape[0]
+ last=tape[tape.length-1]
+ }
+ return first===last
+ },
+ //generator:BLANK_TEST,
+ //display:STRING
+}
+var BSTAGE8 = {
+ 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)=>{
+ var blues = ""
+ var reds = ""
+ for (var i=0;ireds.length)?blues:reds
+ },
+ generator:ODD_LENGTH_TEST,
+ //display:STRING
+}
+var ISTAGE2 = {
+ 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)=>{
+ return tape.length%2===0
+ },
+ //generator:BLANK_TEST,
+ //display:STRING
+}
+var ISTAGE3 = {
+ 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)=>{
+ var answer = tapeToBinary(tape)+1
+ return binaryToTape(answer)
+ },
+ generator:BINARY_TEST,
+ display:BINARY
+}
+var ISTAGE4 = {
+ 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)=>{
+ var reds = 0
+ for (var i=0;i{
+ var blues = ""
+ var reds = ""
+ for (var i=0;i{
+ for (var i=0;i{
+ var temp = ""
+ var number1 = -1
+ var number2 = -1
+ for (var i=0;i{
+ var found = ""
+ var start = false
+ for (var i=0;i ${BLUE}${BLUE}${RED}${BLUE}${BLUE}${RED}${RED}${RED}`,
+ level:createGrid(11,11,10,10),
+ start:{x:0,y:0},
+ accept:(tape)=>{
+ return tape.split("").reverse().join("")
+ },
+ //generator:SUBSTRING_TEST,
+ //display:BINARY
+}
+var ASTAGE1 = {
+ name:"Right in the Center",
+ objective:`Given an even length tape, add a ${YELLOW} marker in the middle of it.`,
+ level:createGrid(10,10,9,9),
+ start:{x:0,y:0},
+ accept:(tape)=>{
+ return tape.substring(0,tape.length/2)+"Y"+tape.substring(tape.length/2,tape.length)
+ },
+ generator:EVEN_LENGTH_TEST,
+ //display:STRING
+}
+var ASTAGE2 = {
+ name:"toLowerCase",
+ 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)=>{
+ var chars=tape.split(YELLOW)
+ var finalString = ""
+ for (var i=0;i{
+ var temp = ""
+ var number1 = -1
+ var number2 = -1
+ for (var i=0;i ${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)=>{
+ var first=false;
+ var newString=""
+ var found=true
+ var limit=2
+ while (found&&limit-->0) {
+ found=false
+ first=false
+ //Red->Blue-Green
+ for (var i=0;i RR
+ var last = ""
+ for (var i=0;i24)`,
+ level:createGrid(17,17,16,16),
+ start:{x:0,y:0},
+ accept:(tape)=>{
+ var temp = ""
+ var number1 = -1
+ var number2 = -1
+ for (var i=0;inumber2)?number1:number2)
+ },
+ generator:TWO_UNEQUAL_NUMBERS_TEST,
+ display:BINARY
+}
var TUTORIAL1 = {
name:"Conveyors!",
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 = {
return newTape
}
}
+var SANDBOX = {
+ name:"The Sandbox",
+ objective:"You may experiment freely in this very large room.",
+ level:createGrid(50,50,24,24),
+ start:{x:0,y:0},
+ accept:(tape)=>{
+ return true
+ }
+ }
var TUTORIALMENU={
title:"Introduction to Conversion",
@@ -550,19 +987,25 @@ var TUTORIALMENU={
}
var EASYMENU={
title:"Beginner Stages",
- levels:[STAGE1,STAGE2],
+ levels:[BSTAGE1,BSTAGE2,BSTAGE3,BSTAGE4,BSTAGE5,BSTAGE6,BSTAGE7,BSTAGE8],
cols:1,
width:568*0.33
}
var MEDIUMMENU={
title:"Intermediate Stages",
- levels:[STAGE3,STAGE2],
+ levels:[ISTAGE1,ISTAGE2,ISTAGE3,ISTAGE4,ISTAGE5,ISTAGE6,ISTAGE7,ISTAGE8],
cols:1,
width:568*0.33
}
var HARDMENU={
title:"Advanced Stages",
- levels:[STAGE1,STAGE2],
+ levels:[ASTAGE1,ASTAGE2,ASTAGE3,ASTAGE4,ASTAGE5],
+ cols:1,
+ width:568*0.33
+}
+var SANDBOXMENU={
+ title:"Sandbox",
+ levels:[SANDBOX],
cols:1,
width:568*0.33
}
@@ -620,10 +1063,39 @@ function resetGame() {
MENU.visible=false
}
+function convertStringToTape(str) {
+ var finalTape=""
+ for (var i=0;i0) {
+ var mask = numb&7
+ switch (mask) {
+ case 0:{
+ newTape+=GREEN
+ }break;
+ case 1:{
+ newTape+=YELLOW
+ }break;
+ case 2:{
+ newTape+=PURPLE
+ }break;
+ case 3:{
+ newTape+=PINK
+ }break;
+ case 4:{
+ newTape+=BLACK
+ }break;
+ case 5:{
+ newTape+=GRAY
+ }break;
+ default:{
+ newTape+=GREEN
+ }
+ }
+ numb=numb>>>3
+ }
+ tests.push(newTape)
+ }
+ }break;
case EVEN_LENGTH_TEST:{
while (tests.length<2000) {
- var newTape = ConvertNumberToTape(startingValue++)
+ var newTape = binaryToTape(startingValue++)
if (newTape.length%2===0) {
tests.push(newTape)
tests.push(newTape.split("").reverse().join(""))
}
}
}break;
+ case ODD_LENGTH_TEST:{
+ while (tests.length<2000) {
+ var newTape = binaryToTape(startingValue++)
+ if (newTape.length%2===1) {
+ tests.push(newTape)
+ tests.push(newTape.split("").reverse().join(""))
+ }
+ }
+ }break;
+ case BINARY_TEST:{
+ while (tests.length<2000) {
+ var newTape = binaryToTape(startingValue++)
+ if (newTape[newTape.length-1]!==RED) {
+ tests.push(newTape)
+ }
+ }
+ }break;
+ case TWO_NUMBERS_TEST:{
+ while (tests.length<2000) {
+ var newTape = binaryToTape(startingValue++)
+ var newTape2 = binaryToTape(startingValue++)
+ if (Math.random()<=0.5) {
+ newTape2=newTape
+ }
+ if (newTape[newTape.length-1]!==RED&&newTape2[newTape2.length-1]!==RED) {
+ tests.push(newTape+GREEN+newTape2)
+ }
+ }
+ }break;
+ case SUBSTRING_TEST:{
+ startingValue=1000
+ while (tests.length<2000) {
+ var tape = binaryToTape(startingValue)
+ var pos1 = Math.floor(Math.random()*(tape.length/2))
+ var pos2 = (tape.length/2)+Math.floor(Math.random()*(tape.length/2))
+ tests.push(tape.substring(0,pos1)+YELLOW+tape.substring(pos1,pos2)+YELLOW+tape.substring(pos2,tape.length-1))
+ startingValue+=141
+ }
+ }break;
+ case UPPERCASE_CHARACTER_TEST:{
+ while (tests.length<2000) {
+ var length=Math.floor(Math.random()*15)
+ var word = ""
+ for (var i=0;i0) {
var mask = remainingVal&1
if (mask===1) {
- tape=BLUE+tape
+ tape=tape+BLUE
} else {
- tape=RED+tape
+ tape=tape+RED
}
remainingVal=remainingVal>>>1
}
@@ -777,10 +1340,9 @@ function setNextSquare(offsetX,offsetY) {
}
function runBot(testing) {
- //console.log(new Date().getTime())
if ((lastGameUpdate=0;i--) {
+ if (tape[i]===RED) {
+ numb=numb<<1;
+ numb=numb|0
+ } else
+ if (tape[i]===BLUE) {
+ numb=numb<<1;
+ numb=numb|1
+ }
+ }
+ return numb
+}
function RenderTape(x,y,width,ctx,tape) {
var xOffset=width-24
@@ -1784,37 +2350,35 @@ function RenderTape(x,y,width,ctx,tape) {
}
}
- function interpretBinary(tape) {
- var numb = 0;
- for (var i=tape.length-1;i>=0;i--) {
- if (tape[i]===RED) {
- numb=numb<<1;
- numb=numb|0
- } else
- if (tape[i]===BLUE) {
- numb=numb<<1;
- numb=numb|1
- }
- }
- return numb
- }
-
if (gameStage.display!==undefined) {
switch (gameStage.display) {
case BINARY:{
+ ctx.fillStyle="gray"
+ ctx.globalAlpha=0.8
+ ctx.fillRect(x,y+60,width,14)
+ ctx.globalAlpha=1
ctx.fillStyle="white"
- ctx.fillText(interpretBinary(tape),x+xOffset+16,y+yOffset+16+4)
+ if (tape.includes(GREEN)) {
+ var numbs = tape.split(GREEN)
+ ctx.fillText(tapeToBinary(numbs[0])+","+tapeToBinary(numbs[1]),x+width/2,y+70)
+ } else {
+ ctx.fillText(tapeToBinary(tape),x+width/2,y+70)
+ }
}break;
case STRING:{
+ ctx.fillStyle="gray"
+ ctx.globalAlpha=0.8
+ ctx.fillRect(x,y+60,width,14)
+ ctx.globalAlpha=1
ctx.fillStyle="white"
var splitString=tape.split(YELLOW)
var finalString="\""
for (var i=0;i0) {if (HasRelativeConnection(grid.x+0,grid.y-1,DOWN)){connections[UP]=true}}
if (grid.y{
- expect(ConvertNumberToTape(4),"BRR","4=100=\"BRR\"")
- expect(ConvertNumberToTape(24),"BBRRR","24=11000=\"BBRRR\"")
- expect(ConvertNumberToTape(167),"BRBRRBBB","167=10100111=\"BRBRRBBB\"")
+ expect(binaryToTape(4),"RRB","4=100=\"BRR\"")
+ expect(binaryToTape(24),"RRRBB","24=11000=\"BBRRR\"")
+ expect(binaryToTape(167),"BBBRRBRB","167=10100111=\"BRBRRBBB\"")
}).showResults()
@@ -353,11 +353,53 @@ function runTests() {
expect(BOT_QUEUE.length===0,true,"Bot queue should be empty.")
gameState=TESTING
generateBotQueue()
- //console.log(BOT_QUEUE)
expect(BOT_QUEUE.length===0,true,"There should be 0 bots in queue for a good level, as all bots are supposed to pass.")
})
.showResults()
+ TestSuite = new describe("Basic Stage 5 - Back and Forth")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ })
+ .it("accepts valid results",()=>{
+ loadStage(BSTAGE5)
+ expect(gameStage.accept("BBB"),false)
+ expect(gameStage.accept("BRB"),true)
+ expect(gameStage.accept("RBRBRB"),true)
+ expect(gameStage.accept("RBRBRBR"),true)
+ expect(gameStage.accept("RBRRRBR"),false)
+ })
+
+ TestSuite = new describe("Basic Stage 7 - End-to-End")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ })
+ .it("accepts valid results",()=>{
+ loadStage(BSTAGE7)
+ expect(gameStage.accept("BBB"),true)
+ expect(gameStage.accept("BRB"),true)
+ expect(gameStage.accept("RBRBRB"),false)
+ expect(gameStage.accept("RBRBRBR"),true)
+ expect(gameStage.accept("RBRRRBR"),true)
+ expect(gameStage.accept("BBBBRBBR"),false)
+ })
+
+ TestSuite = new describe("Basic Stage 8 - Greatest Count")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ })
+ .it("accepts valid results",()=>{
+ loadStage(BSTAGE8)
+ expect(gameStage.accept("BBBRR"),"BBB")
+ expect(gameStage.accept("BBRRR"),"RRR")
+ expect(gameStage.accept("RBRBRBR"),"RRRR")
+ expect(gameStage.accept("RBRBRBB"),"BBBB")
+ expect(gameStage.accept("RBRRRBR"),"RRRRR")
+ expect(gameStage.accept("BBBBRBBR"),"BBBBBB")
+ })
TestSuite = new describe("Stage 2")
TestSuite
@@ -451,7 +493,6 @@ function runTests() {
expect(BOT_QUEUE.length===0,true,"Bot queue should be empty.")
gameState=TESTING
generateBotQueue()
- //console.log(BOT_QUEUE)
expect(BOT_QUEUE.length===0,true,"There should be 0 bots in queue for a good level, as all bots are supposed to pass.")
})
.showResults()
@@ -465,6 +506,248 @@ function runTests() {
expect(colorToHex(58, 79, 55),"#3a4f37")
}).showResults()
+ TestSuite = new describe("Intermediate Stage 1 - Blue In Blue Out")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ISTAGE1)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("BBBRR"),"BBBRR")
+ expect(gameStage.accept("BBRRR"),"BBRRR")
+ expect(gameStage.accept("RBRBRBR"),"BBBRRRR")
+ expect(gameStage.accept("RBRBRBB"),"BBBBRRR")
+ expect(gameStage.accept("RBRRRBR"),"BBRRRRR")
+ expect(gameStage.accept("BBBBRBBR"),"BBBBBBRR")
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Intermediate Stage 2 - Blue In Blue Out")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ISTAGE2)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("BBBRR"),false)
+ expect(gameStage.accept("BBRRR"),false)
+ expect(gameStage.accept("RBRBRBR"),false)
+ expect(gameStage.accept("RBRBRB"),true)
+ expect(gameStage.accept("RBRRRBRB"),true)
+ expect(gameStage.accept(""),true)
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Intermediate Stage 3 - Add One")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ISTAGE3)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("RRBBB"),"BRBBB")
+ expect(gameStage.accept("RRRBB"),"BRRBB")
+ expect(gameStage.accept("RRBRBB"),"BRBRBB")
+ expect(gameStage.accept("BRBRB"),"RBBRB")
+ expect(gameStage.accept("BRRRBRB"),"RBRRBRB")
+ expect(gameStage.accept(""),"B")
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Intermediate Stage 4 - String Length")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ISTAGE4)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("RRBBB"),"RB")
+ expect(gameStage.accept("RRRBB"),"BB")
+ expect(gameStage.accept("RRBRBB"),"BB")
+ expect(gameStage.accept("BRBRB"),"RB")
+ expect(gameStage.accept("BRRRBRB"),"RRB")
+ expect(gameStage.accept(""),"")
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Intermediate Stage 5 - NoLemonsNoMelon")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ISTAGE5)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("RRBBB"),false)
+ expect(gameStage.accept("BBRBB"),true)
+ expect(gameStage.accept("RRBRBB"),false)
+ expect(gameStage.accept("BRBRB"),true)
+ expect(gameStage.accept("BRRRBRB"),false)
+ expect(gameStage.accept("BBBRRBBB"),true)
+ expect(gameStage.accept(""),true)
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Intermediate Stage 6 - Is Equal To")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ISTAGE6)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("RRBGBB"),false)
+ expect(gameStage.accept("BBGBB"),true) //
+ expect(gameStage.accept("RRBGRBB"),false)
+ expect(gameStage.accept("BRGRB"),false) //
+ expect(gameStage.accept("BRBGBRB"),true) //
+ expect(gameStage.accept("BBBGRBBB"),false)
+ expect(gameStage.accept("G"),true) //
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Intermediate Stage 7 - Substring")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ISTAGE7)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("RYRBBYB"),"RBB")
+ expect(gameStage.accept("BBYBYB"),"B") //
+ expect(gameStage.accept("RYRBRBBY"),"RBRBB")
+ expect(gameStage.accept("BRYYRB"),"") //
+ expect(gameStage.accept("BRYBBRYB"),"BBR") //
+ expect(gameStage.accept("BBBYRBBYB"),"RBB")
+ expect(gameStage.accept("YY"),"") //
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Intermediate Stage 8 - Reversal")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ISTAGE8)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("RRBBB"),"BBBRR")
+ expect(gameStage.accept("BBBB"),"BBBB") //
+ expect(gameStage.accept("RRBRBB"),"BBRBRR")
+ expect(gameStage.accept("BRRBRR"),"RRBRRB") //
+ expect(gameStage.accept("BRBRRBRB"),"BRBRRBRB") //
+ expect(gameStage.accept("BBBBBRBBB"),"BBBRBBBBB")
+ expect(gameStage.accept(""),"") //
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Advanced Stage 1 - Right in the Center")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ASTAGE1)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("RRBB"),"RRYBB")
+ expect(gameStage.accept("BBBB"),"BBYBB")
+ expect(gameStage.accept("RRBRBB"),"RRBYRBB")
+ expect(gameStage.accept("BRRBRR"),"BRRYBRR")
+ expect(gameStage.accept("BRBRRBRB"),"BRBRYRBRB")
+ expect(gameStage.accept("BBBBBRBBBB"),"BBBBBYRBBBB")
+ expect(gameStage.accept(""),"Y")
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Advanced Stage 2 - toLowerCase")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ASTAGE2)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("RRRBRRBYBRRBRRB"),"RRRBRBBYBRRBRBB")
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Advanced Stage 3 - Addition")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ASTAGE3)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("BRBBGRB"),"BBBB")
+ expect(gameStage.accept("RBGRB"),"RRB")
+ expect(gameStage.accept("BGR"),"B")
+ expect(gameStage.accept("RGBB"),"BB")
+ expect(gameStage.accept("BRBGRRBRB"),"BRRBB")
+ expect(gameStage.accept("BBBBBGRBBBB"),"BRBBBB")
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Advanced Stage 4 - The Great Conversion")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ASTAGE4)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("RRBBRBBBR"),"RBGBBGRBBBBG")
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
+ TestSuite = new describe("Advanced Stage 5 - Compare")
+ TestSuite
+ .beforeEach(()=>{
+ resetGame()
+ loadStage(ASTAGE5)
+ })
+ .it("accepts valid results",()=>{
+ expect(gameStage.accept("BRBBGRB"),"BRBB")
+ expect(gameStage.accept("RBGRBB"),"RBB")
+ expect(gameStage.accept("BGR"),"B")
+ expect(gameStage.accept("RGBB"),"BB")
+ expect(gameStage.accept("BRBGRRBRB"),"RRBRB")
+ expect(gameStage.accept("BBBBBGRBBBB"),"BBBBB")
+ })
+ .it("the generator doesn't fail",()=>{
+ gameState=TESTING
+ generateBotQueue()
+ })
+
console.log("----------------------")
console.log("ALL TESTS: "+totalTestsPassed+" passed, "+(totalTests-totalTestsPassed)+" failed, "+totalTests+" total")
if (testsPass===undefined) {
@@ -482,10 +765,9 @@ function runGame() {
step()
draw()
},1000/60)
- console.log("Running")
}
-var RUNTESTS = true;
+var RUNTESTS = false;
loadScript("image_data.js",gameLoader)