From fa37f623f1f7c9bcc9e365b3fecb8af2859f9882 Mon Sep 17 00:00:00 2001 From: "PolicyChanges1@gmail.com" Date: Mon, 22 Mar 2021 20:33:47 -0400 Subject: [PATCH] bt cannon --- dist/tetrion.js | 138 ++++++++++++++++++++++-------------------------- index.html | 4 ++ src/main.js | 35 ++++++++---- src/openers.js | 70 +++++++++++++----------- src/shapes.js | 33 ------------ 5 files changed, 132 insertions(+), 148 deletions(-) diff --git a/dist/tetrion.js b/dist/tetrion.js index 44b0efb..6a44fe9 100644 --- a/dist/tetrion.js +++ b/dist/tetrion.js @@ -959,26 +959,40 @@ Tetris.prototype = { document.getElementById("Openers").appendChild(newOpener); + // Print Sequence Data to console - console.log("this.hintQueue = new Array("); - this.shapeQueue.slice().reverse().forEach( function(shape, idx, arr) { console.log("shapes.getShape("+shape.nType()+ ((idx === arr.length-1) ? "));" : "),") ); } ); + // console.log("this.hintQueue = new Array("); + // this.shapeQueue.slice().reverse().forEach( function(shape, idx, arr) { console.log("shapes.getShape("+shape.nType()+ ((idx === arr.length-1) ? "));" : "),") ); } ); + - var shapes = []; - this.shapeQueue.slice().reverse().forEach( function(shape, idx) { shapes.push(shape.x); shapes.push(shape.y); shapes.push(shape.state); } ); + var shapes = []; + this.shapeQueue.slice().reverse().forEach( function(shape, idx) { shapes.push(shape.x); shapes.push(shape.y); shapes.push(shape.state); } ); - console.log("var hintDataList = [" + shapes.join(",") + "];"); - console.log("this.createHintQueue(hintDataList);"); + // console.log("var hintDataList = [" + shapes.join(",") + "];"); + // console.log("this.createHintQueue(hintDataList);"); - openers.addSequence(this.shapeQueue); + var sequenceCode = []; + + var shapeArrayStr = []; + this.shapeQueue.slice().reverse().forEach( function(shape, idx, arr) { shapeArrayStr += "shapes.getShape("+shape.nType() + ((idx === arr.length-1) ? "));" : "), ") } ); + sequenceCode += "case :\n\tthis.shapeQueue = new Array(" + shapeArrayStr + "\nbreak;" + "\n\n"; + + sequenceCode += "case :\n\tthis.hintQueue = new Array(" + shapeArrayStr; + sequenceCode += "\n\nvar hintDataList = [" + shapes.join(",") + "];" + "\nthis.createHintQueue(hintDataList);" + "\nbreak;"; + + prompt("Generated Code:", sequenceCode); + + + //openers.addSequence(this.shapeQueue); //this.setFreePlay(); - this.gameState = consts.GAMESTATES[1]; + //this.gameState = consts.GAMESTATES[1]; this.currentMinoInx = 0; //this.setCurrentOpener(99999);//this.currentMinoInx); clearMatrix(this.matrix); this.currentOpener = 9999; this.shapeQueue = []; this.hintQueue = []; - this._recurseGameState(); + //this._recurseGameState(); }, setSettings: function() { var newVal = document.getElementById("setting_value").value; @@ -1003,8 +1017,7 @@ Tetris.prototype = { this.levelTime = this.startTime; this.prevInputTime = this.startTime; // current tetrino index gets set to 0 at the end of opener sequence - //if(this.currentMinoInx == undefined || this.currentMinoInx < 1000) // todo: refactor -- seppuku worthy - this.currentMinoInx = 0; + this.currentMinoInx = 0; this.shapeQueue = []; this.hintQueue = []; this.holdStack = []; @@ -1711,36 +1724,36 @@ var openerGenerator = { break; case 11: this.shapeQueue = new Array( - shapes.getShape(0), - shapes.getShape(1), - shapes.getShape(4), - shapes.getShape(5), - shapes.getShape(6), - shapes.getShape(2), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(5), - shapes.getShape(6), - shapes.getShape(0), - shapes.getShape(1), - shapes.getShape(2), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(5), - shapes.getShape(6), - shapes.getShape(3), - shapes.getShape(0), - shapes.getShape(2), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(5), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(1), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(0), - shapes.getShape(6)); + shapes.getShape(0), + shapes.getShape(1), + shapes.getShape(4), + shapes.getShape(5), + shapes.getShape(6), + shapes.getShape(2), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(5), + shapes.getShape(6), + shapes.getShape(0), + shapes.getShape(1), + shapes.getShape(2), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(5), + shapes.getShape(6), + shapes.getShape(3), + shapes.getShape(0), + shapes.getShape(2), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(5), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(1), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(0), + shapes.getShape(6)); break; case 12: this.shapeQueue = new Array( @@ -1749,6 +1762,10 @@ var openerGenerator = { shapes.getShape(2), shapes.getShape(3)); break; + case 13: + this.shapeQueue = new Array(shapes.getShape(4), shapes.getShape(6), shapes.getShape(1), shapes.getShape(2), shapes.getShape(3), shapes.getShape(5), shapes.getShape(0), shapes.getShape(1), shapes.getShape(0), shapes.getShape(6), shapes.getShape(0), shapes.getShape(5), shapes.getShape(4), shapes.getShape(3), shapes.getShape(4), shapes.getShape(3), shapes.getShape(4)); + break; + default: this.shapeQueue.unshift(utils.deepClone(shapes.randomShape())); return; @@ -2070,6 +2087,12 @@ var openerGenerator = { var hintDataList = [3,17,1,6,18,0,5,17,2,1,18,0]; this.createHintQueue(hintDataList); break; + case 13: + this.hintQueue = new Array(shapes.getShape(4), shapes.getShape(6), shapes.getShape(1), shapes.getShape(2), shapes.getShape(3), shapes.getShape(5), shapes.getShape(0), shapes.getShape(1), shapes.getShape(0), shapes.getShape(6), shapes.getShape(0), shapes.getShape(5), shapes.getShape(4), shapes.getShape(3), shapes.getShape(4), shapes.getShape(3), shapes.getShape(4)); + + var hintDataList = [0,18,0,3,18,0,-1,17,0,7,18,0,3,17,0,8,16,3,0,15,2,-2,14,0,3,15,2,3,14,0,1,13,3,8,14,3,7,12,2,5,16,2,3,14,3,6,17,3,5,18,0]; + this.createHintQueue(hintDataList); + break; default: this.hintQueue.unshift(utils.deepClone(shapes.randomShape())); return; @@ -2375,38 +2398,7 @@ function ShapeO() { } function ShapeI() { -/* // North - var state1 = [ - [1, 0, 0, 0], - [1, 0, 0, 0], - [1, 0, 0, 0], - [1, 0, 0, 0] - ]; - // East - var state2 = [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [1, 1, 1, 1], - [0, 0, 0, 0] - ]; - - // South - var state3 = [ - [0, 0, 1, 0], - [0, 0, 1, 0], - [0, 0, 1, 0], - [0, 0, 1, 0] - ]; - - // West - var state4 = [ - [0, 0, 0, 0], - [1, 1, 1, 1], - [0, 0, 0, 0], - [0, 0, 0, 0] - ]; - */ // North var state1 = [ [0, 0, 0, 0], @@ -3120,8 +3112,6 @@ function randomShape() { } - - function getShape(shapei) { var result = shapei var shape; diff --git a/index.html b/index.html index 6277ced..68d29de 100644 --- a/index.html +++ b/index.html @@ -194,6 +194,10 @@ this.resizebg(); document.getElementById("setDTCannonTSZbaseVar").addEventListener("click", function() { tetrion.setCurrentOpener(10); } ); document.getElementById("setDTCannonLHVar").addEventListener("click", function() { tetrion.setCurrentOpener(11); } ); document.getElementById("TestSequence").addEventListener("click", function() { tetrion.setCurrentOpener(12); } ); + //document.getElementById("setStdPCOpenerVar").addEventListener("click", function() { tetrion.setCurrentOpener(13); } ); + document.getElementById("setBTCannonVar").addEventListener("click", function() { tetrion.setCurrentOpener(13); } ); + + document.getElementById("enablegamepad").addEventListener("click", function() { tetrion.toggleGamepad(); } ); diff --git a/src/main.js b/src/main.js index 33a0bfc..9506031 100644 --- a/src/main.js +++ b/src/main.js @@ -275,26 +275,40 @@ Tetris.prototype = { document.getElementById("Openers").appendChild(newOpener); + // Print Sequence Data to console - console.log("this.hintQueue = new Array("); - this.shapeQueue.slice().reverse().forEach( function(shape, idx, arr) { console.log("shapes.getShape("+shape.nType()+ ((idx === arr.length-1) ? "));" : "),") ); } ); + // console.log("this.hintQueue = new Array("); + // this.shapeQueue.slice().reverse().forEach( function(shape, idx, arr) { console.log("shapes.getShape("+shape.nType()+ ((idx === arr.length-1) ? "));" : "),") ); } ); + - var shapes = []; - this.shapeQueue.slice().reverse().forEach( function(shape, idx) { shapes.push(shape.x); shapes.push(shape.y); shapes.push(shape.state); } ); + var shapes = []; + this.shapeQueue.slice().reverse().forEach( function(shape, idx) { shapes.push(shape.x); shapes.push(shape.y); shapes.push(shape.state); } ); - console.log("var hintDataList = [" + shapes.join(",") + "];"); - console.log("this.createHintQueue(hintDataList);"); + // console.log("var hintDataList = [" + shapes.join(",") + "];"); + // console.log("this.createHintQueue(hintDataList);"); - openers.addSequence(this.shapeQueue); + var sequenceCode = []; + + var shapeArrayStr = []; + this.shapeQueue.slice().reverse().forEach( function(shape, idx, arr) { shapeArrayStr += "shapes.getShape("+shape.nType() + ((idx === arr.length-1) ? "));" : "), ") } ); + sequenceCode += "case :\n\tthis.shapeQueue = new Array(" + shapeArrayStr + "\nbreak;" + "\n\n"; + + sequenceCode += "case :\n\tthis.hintQueue = new Array(" + shapeArrayStr; + sequenceCode += "\n\nvar hintDataList = [" + shapes.join(",") + "];" + "\nthis.createHintQueue(hintDataList);" + "\nbreak;"; + + prompt("Generated Code:", sequenceCode); + + + //openers.addSequence(this.shapeQueue); //this.setFreePlay(); - this.gameState = consts.GAMESTATES[1]; + //this.gameState = consts.GAMESTATES[1]; this.currentMinoInx = 0; //this.setCurrentOpener(99999);//this.currentMinoInx); clearMatrix(this.matrix); this.currentOpener = 9999; this.shapeQueue = []; this.hintQueue = []; - this._recurseGameState(); + //this._recurseGameState(); }, setSettings: function() { var newVal = document.getElementById("setting_value").value; @@ -319,8 +333,7 @@ Tetris.prototype = { this.levelTime = this.startTime; this.prevInputTime = this.startTime; // current tetrino index gets set to 0 at the end of opener sequence - //if(this.currentMinoInx == undefined || this.currentMinoInx < 1000) // todo: refactor -- seppuku worthy - this.currentMinoInx = 0; + this.currentMinoInx = 0; this.shapeQueue = []; this.hintQueue = []; this.holdStack = []; diff --git a/src/openers.js b/src/openers.js index 3510900..a1f3074 100644 --- a/src/openers.js +++ b/src/openers.js @@ -174,36 +174,36 @@ var openerGenerator = { break; case 11: this.shapeQueue = new Array( - shapes.getShape(0), - shapes.getShape(1), - shapes.getShape(4), - shapes.getShape(5), - shapes.getShape(6), - shapes.getShape(2), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(5), - shapes.getShape(6), - shapes.getShape(0), - shapes.getShape(1), - shapes.getShape(2), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(5), - shapes.getShape(6), - shapes.getShape(3), - shapes.getShape(0), - shapes.getShape(2), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(5), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(1), - shapes.getShape(3), - shapes.getShape(4), - shapes.getShape(0), - shapes.getShape(6)); + shapes.getShape(0), + shapes.getShape(1), + shapes.getShape(4), + shapes.getShape(5), + shapes.getShape(6), + shapes.getShape(2), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(5), + shapes.getShape(6), + shapes.getShape(0), + shapes.getShape(1), + shapes.getShape(2), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(5), + shapes.getShape(6), + shapes.getShape(3), + shapes.getShape(0), + shapes.getShape(2), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(5), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(1), + shapes.getShape(3), + shapes.getShape(4), + shapes.getShape(0), + shapes.getShape(6)); break; case 12: this.shapeQueue = new Array( @@ -212,6 +212,10 @@ var openerGenerator = { shapes.getShape(2), shapes.getShape(3)); break; + case 13: + this.shapeQueue = new Array(shapes.getShape(4), shapes.getShape(6), shapes.getShape(1), shapes.getShape(2), shapes.getShape(3), shapes.getShape(5), shapes.getShape(0), shapes.getShape(1), shapes.getShape(0), shapes.getShape(6), shapes.getShape(0), shapes.getShape(5), shapes.getShape(4), shapes.getShape(3), shapes.getShape(4), shapes.getShape(3), shapes.getShape(4)); + break; + default: this.shapeQueue.unshift(utils.deepClone(shapes.randomShape())); return; @@ -533,6 +537,12 @@ var openerGenerator = { var hintDataList = [3,17,1,6,18,0,5,17,2,1,18,0]; this.createHintQueue(hintDataList); break; + case 13: + this.hintQueue = new Array(shapes.getShape(4), shapes.getShape(6), shapes.getShape(1), shapes.getShape(2), shapes.getShape(3), shapes.getShape(5), shapes.getShape(0), shapes.getShape(1), shapes.getShape(0), shapes.getShape(6), shapes.getShape(0), shapes.getShape(5), shapes.getShape(4), shapes.getShape(3), shapes.getShape(4), shapes.getShape(3), shapes.getShape(4)); + + var hintDataList = [0,18,0,3,18,0,-1,17,0,7,18,0,3,17,0,8,16,3,0,15,2,-2,14,0,3,15,2,3,14,0,1,13,3,8,14,3,7,12,2,5,16,2,3,14,3,6,17,3,5,18,0]; + this.createHintQueue(hintDataList); + break; default: this.hintQueue.unshift(utils.deepClone(shapes.randomShape())); return; diff --git a/src/shapes.js b/src/shapes.js index 2a84937..336d42d 100644 --- a/src/shapes.js +++ b/src/shapes.js @@ -209,38 +209,7 @@ function ShapeO() { } function ShapeI() { -/* // North - var state1 = [ - [1, 0, 0, 0], - [1, 0, 0, 0], - [1, 0, 0, 0], - [1, 0, 0, 0] - ]; - // East - var state2 = [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [1, 1, 1, 1], - [0, 0, 0, 0] - ]; - - // South - var state3 = [ - [0, 0, 1, 0], - [0, 0, 1, 0], - [0, 0, 1, 0], - [0, 0, 1, 0] - ]; - - // West - var state4 = [ - [0, 0, 0, 0], - [1, 1, 1, 1], - [0, 0, 0, 0], - [0, 0, 0, 0] - ]; - */ // North var state1 = [ [0, 0, 0, 0], @@ -954,8 +923,6 @@ function randomShape() { } - - function getShape(shapei) { var result = shapei var shape;