From 5bdeb122124e599c5ebbb4f9f6e624e8e87efe47 Mon Sep 17 00:00:00 2001 From: aguevara1 Date: Sat, 18 Aug 2018 20:14:37 -0500 Subject: [PATCH 1/8] more changes to file --- 05week/checkers.js | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/05week/checkers.js b/05week/checkers.js index 8f33a089c..c8d7feeca 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -7,13 +7,25 @@ const rl = readline.createInterface({ output: process.stdout }); +class Checkers { + constructor(letter) { + this.letter= letter; + } +} + +//const symbol= new Checkers("A"); + +/* function Checker() { - // Your code here + // Your code here + } +*/ function Board() { this.grid = []; + // creates an 8x8 array, filled with null values this.createGrid = function() { // loop to create the 8 rows @@ -21,13 +33,23 @@ function Board() { this.grid[row] = []; // push in 8 columns of nulls for (let column = 0; column < 8; column++) { - this.grid[row].push(null); + if ((row + column) % 2 === 0) { + this.grid[row].push(null); + } else { + this.grid[row].push('valid'); + } + // this.grid[row].push('X'); + //console.log(this.grid[row]); } } }; + // prints out the board this.viewGrid = function() { + // console.log(this); + this.symbol='A'; + // console.log(this.symbol); // add our column numbers let string = " 0 1 2 3 4 5 6 7\n"; for (let row = 0; row < 8; row++) { @@ -37,11 +59,14 @@ function Board() { for (let column = 0; column < 8; column++) { // if the location is "truthy" (contains a checker piece, in this case) if (this.grid[row][column]) { + console.log('in with symbol'); // push the symbol of the check in that location into the array rowOfCheckers.push(this.grid[row][column].symbol); + console.log(this.grid[row][column].symbol); } else { // just push in a blank space rowOfCheckers.push(' '); + console.log(this.grid[row][column]); } } // join the rowOfCheckers array to a string, separated by a space @@ -54,8 +79,10 @@ function Board() { // Your code here } -function Game() { + + +function Game() { this.board = new Board(); this.start = function() { @@ -64,6 +91,11 @@ function Game() { }; } +function moveChecker(piece1, piece2) { + console.log("hello i'm in moveChecker function"); +} + + function getPrompt() { game.board.viewGrid(); rl.question('which piece?: ', (whichPiece) => { @@ -74,12 +106,13 @@ function getPrompt() { }); } + const game = new Game(); game.start(); +//game.moveChecker(); // Tests - if (typeof describe === 'function') { describe('Game', () => { it('should have a board', () => { @@ -90,8 +123,8 @@ if (typeof describe === 'function') { }); }); - describe('Game.moveChecker()', function () { - it('should move a checker', function () { + describe('Game.moveChecker()', function() { + it('should move a checker', function() { assert(!game.board.grid[4][1]); game.moveChecker('50', '41'); assert(game.board.grid[4][1]); From fc0d105c0e85c144782a799cfd318d04b8dbceb2 Mon Sep 17 00:00:00 2001 From: aguevara1 Date: Sun, 19 Aug 2018 22:51:20 -0500 Subject: [PATCH 2/8] editing the program --- 05week/checkers.js | 86 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/05week/checkers.js b/05week/checkers.js index c8d7feeca..a3e8324b2 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -7,25 +7,55 @@ const rl = readline.createInterface({ output: process.stdout }); -class Checkers { - constructor(letter) { - this.letter= letter; - } -} +class Checker1{ + constructor( symbol){ + this.symbol='R'; + } -//const symbol= new Checkers("A"); +} -/* -function Checker() { - // Your code here +class Checker2{ + constructor(symbol){ + this.symbol='B'; + } } -*/ function Board() { this.grid = []; + this.checkers=[]; + //place or push checkers in their starting position + this.makeTheCheckers= function() { + let theRs= [[0,1],[0,3],[0,5],[0,7],[1,0],[1,2],[1,4],[1,6],[2,1],[2,3], + [2,5],[2,7]]; + let theBs=[[5,0],[5,2],[5,4],[5,6],[6,1],[6,3],[6,5],[6,7],[7,0],[7,2], + [7,4],[7,6]]; + // for( let i=0; i<=11 ; i++){ + theRs.forEach( (item,index)=>{ + let theReds=new Checker1; + let coordinate= theRs[index]; + // console.log(theReds); + this.checkers.push(coordinate); + + this.grid[coordinate[0]][coordinate[1]]=theReds; + + }); + + theBs.forEach( (item,index)=>{ + let theBlacks=new Checker2; + let coordinate1= theBs[index]; + // console.log(theReds); + this.checkers.push(coordinate1); + //console.log(this); + this.grid[coordinate1[0]][coordinate1[1]]=theBlacks; + }); + + console.log(this.checkers.length); +} + + // creates an 8x8 array, filled with null values this.createGrid = function() { // loop to create the 8 rows @@ -33,8 +63,8 @@ function Board() { this.grid[row] = []; // push in 8 columns of nulls for (let column = 0; column < 8; column++) { - if ((row + column) % 2 === 0) { - this.grid[row].push(null); + if ((row + column) % 2 === 0) { + this.grid[row].push(null); } else { this.grid[row].push('valid'); } @@ -47,9 +77,9 @@ function Board() { // prints out the board this.viewGrid = function() { - // console.log(this); - this.symbol='A'; - // console.log(this.symbol); + // console.log(this); + const symbol = 'A'; + // console.log(this.symbol); // add our column numbers let string = " 0 1 2 3 4 5 6 7\n"; for (let row = 0; row < 8; row++) { @@ -59,14 +89,14 @@ function Board() { for (let column = 0; column < 8; column++) { // if the location is "truthy" (contains a checker piece, in this case) if (this.grid[row][column]) { - console.log('in with symbol'); + //console.log('in with symbol'); // push the symbol of the check in that location into the array rowOfCheckers.push(this.grid[row][column].symbol); - console.log(this.grid[row][column].symbol); + // console.log(this.grid[row][column].symbol); } else { // just push in a blank space rowOfCheckers.push(' '); - console.log(this.grid[row][column]); + //console.log(this.grid[row][column]); } } // join the rowOfCheckers array to a string, separated by a space @@ -77,24 +107,22 @@ function Board() { console.log(string); }; - // Your code here } - function Game() { + //this.moveChecker(whichPiece,toWhere); this.board = new Board(); this.start = function() { this.board.createGrid(); + + this.board.makeTheCheckers(); + // Your code here }; } -function moveChecker(piece1, piece2) { - console.log("hello i'm in moveChecker function"); -} - function getPrompt() { game.board.viewGrid(); @@ -109,7 +137,15 @@ function getPrompt() { const game = new Game(); game.start(); -//game.moveChecker(); + +game.moveChecker= (piece1, piece2)=> { + + console.log(this); + + console.log("hello i'm in moveChecker function"); + +} + // Tests From 79f8787ef431c2a01cf23096ed1ff2704737e29f Mon Sep 17 00:00:00 2001 From: aguevara1 Date: Tue, 21 Aug 2018 19:32:01 -0500 Subject: [PATCH 3/8] more edits --- 05week/checkers.js | 133 +++++++++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 52 deletions(-) diff --git a/05week/checkers.js b/05week/checkers.js index a3e8324b2..425f3cfb5 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -8,16 +8,16 @@ const rl = readline.createInterface({ }); -class Checker1{ - constructor( symbol){ - this.symbol='R'; - } +class Checker1 { + constructor(symbol) { + this.symbol = 'R'; + } } -class Checker2{ - constructor(symbol){ - this.symbol='B'; +class Checker2 { + constructor(symbol) { + this.symbol = 'B'; } } @@ -25,35 +25,58 @@ class Checker2{ function Board() { this.grid = []; - this.checkers=[]; - //place or push checkers in their starting position - this.makeTheCheckers= function() { - let theRs= [[0,1],[0,3],[0,5],[0,7],[1,0],[1,2],[1,4],[1,6],[2,1],[2,3], - [2,5],[2,7]]; - let theBs=[[5,0],[5,2],[5,4],[5,6],[6,1],[6,3],[6,5],[6,7],[7,0],[7,2], - [7,4],[7,6]]; + this.checkers = []; + //place or push checkers in their starting position + this.makeTheCheckers = function() { + let theRs = [ + [0, 1], + [0, 3], + [0, 5], + [0, 7], + [1, 0], + [1, 2], + [1, 4], + [1, 6], + [2, 1], + [2, 3], + [2, 5], + [2, 7] + ]; + let theBs = [ + [5, 0], + [5, 2], + [5, 4], + [5, 6], + [6, 1], + [6, 3], + [6, 5], + [6, 7], + [7, 0], + [7, 2], + [7, 4], + [7, 6] + ]; // for( let i=0; i<=11 ; i++){ - theRs.forEach( (item,index)=>{ - let theReds=new Checker1; - let coordinate= theRs[index]; - // console.log(theReds); - this.checkers.push(coordinate); - - this.grid[coordinate[0]][coordinate[1]]=theReds; - - }); - - theBs.forEach( (item,index)=>{ - let theBlacks=new Checker2; - let coordinate1= theBs[index]; - // console.log(theReds); - this.checkers.push(coordinate1); - //console.log(this); - this.grid[coordinate1[0]][coordinate1[1]]=theBlacks; - }); - - console.log(this.checkers.length); -} + theRs.forEach((item, index) => { + let theReds = new Checker1; + let coordinate = theRs[index]; + // console.log(theReds); + this.checkers.push(coordinate); + this.grid[coordinate[0]][coordinate[1]] = theReds; + + }); + + theBs.forEach((item, index) => { + let theBlacks = new Checker2; + let coordinate1 = theBs[index]; + // console.log(theReds); + this.checkers.push(coordinate1); + //console.log(this); + this.grid[coordinate1[0]][coordinate1[1]] = theBlacks; + }); + + console.log(this.checkers.length); + } // creates an 8x8 array, filled with null values @@ -63,8 +86,8 @@ function Board() { this.grid[row] = []; // push in 8 columns of nulls for (let column = 0; column < 8; column++) { - if ((row + column) % 2 === 0) { - this.grid[row].push(null); + if ((row + column) % 2 === 0) { + this.grid[row].push(null); } else { this.grid[row].push('valid'); } @@ -92,7 +115,7 @@ function Board() { //console.log('in with symbol'); // push the symbol of the check in that location into the array rowOfCheckers.push(this.grid[row][column].symbol); - // console.log(this.grid[row][column].symbol); + // console.log(this.grid[row][column].symbol); } else { // just push in a blank space rowOfCheckers.push(' '); @@ -109,18 +132,29 @@ function Board() { } +class Game { + constructor() { + this.board = new Board(); -function Game() { - //this.moveChecker(whichPiece,toWhere); - this.board = new Board(); + this.start = function() { + this.board.createGrid(); + this.board.makeTheCheckers(); - this.start = function() { - this.board.createGrid(); + } + } + moveChecker(piece1, piece2) { - this.board.makeTheCheckers(); + let whatPiece = piece1.split(''); + let moveTo = piece2.split(''); + + console.log(whatPiece); + console.log(moveTo); + console.log("hello i'm in moveChecker function"); + console.log(this.board.grid); + this.board.grid[whatPiece[0]][whatPiece[1]]=this.board.grid[moveTo[0]][moveTo[1]]; + + } - // Your code here - }; } @@ -137,14 +171,9 @@ function getPrompt() { const game = new Game(); game.start(); +game.moveChecker('50','41'); -game.moveChecker= (piece1, piece2)=> { - - console.log(this); - console.log("hello i'm in moveChecker function"); - -} From fef443b19cab907e9b842645c5d40f4a8c6366cc Mon Sep 17 00:00:00 2001 From: aguevara1 Date: Wed, 22 Aug 2018 17:24:07 -0500 Subject: [PATCH 4/8] still working on it --- 05week/checkers.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/05week/checkers.js b/05week/checkers.js index 425f3cfb5..39566b44a 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -9,18 +9,16 @@ const rl = readline.createInterface({ class Checker1 { - constructor(symbol) { - this.symbol = 'R'; + constructor(color) { + if(color==='red'){ + this.symbol='R'; + }else{ + this.symbol='B'; + } } } -class Checker2 { - constructor(symbol) { - this.symbol = 'B'; - } - -} function Board() { this.grid = []; @@ -58,7 +56,7 @@ function Board() { ]; // for( let i=0; i<=11 ; i++){ theRs.forEach((item, index) => { - let theReds = new Checker1; + let theReds = new Checker1('red'); let coordinate = theRs[index]; // console.log(theReds); this.checkers.push(coordinate); @@ -67,7 +65,7 @@ function Board() { }); theBs.forEach((item, index) => { - let theBlacks = new Checker2; + let theBlacks = new Checker1('black'); let coordinate1 = theBs[index]; // console.log(theReds); this.checkers.push(coordinate1); @@ -150,8 +148,11 @@ class Game { console.log(whatPiece); console.log(moveTo); console.log("hello i'm in moveChecker function"); - console.log(this.board.grid); - this.board.grid[whatPiece[0]][whatPiece[1]]=this.board.grid[moveTo[0]][moveTo[1]]; + //console.log(this.board.grid); + + + this.board.grid[moveTo[0]][moveTo[1]]=this.board.grid[whatPiece[0]][whatPiece[1]]; + this.board.grid[whatPiece[0]][whatPiece[1]]=''; } @@ -171,7 +172,7 @@ function getPrompt() { const game = new Game(); game.start(); -game.moveChecker('50','41'); +//game.moveChecker('50','41'); From a7cc29859dc58c3913c23b8831304ae99fd1a1d2 Mon Sep 17 00:00:00 2001 From: aguevara1 Date: Thu, 23 Aug 2018 18:07:14 -0500 Subject: [PATCH 5/8] kept editing --- 05week/checkers.js | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/05week/checkers.js b/05week/checkers.js index 39566b44a..a3ec43145 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -8,12 +8,12 @@ const rl = readline.createInterface({ }); -class Checker1 { +class Checker { constructor(color) { - if(color==='red'){ - this.symbol='R'; - }else{ - this.symbol='B'; + if (color === 'red') { + this.symbol = 'R'; + } else { + this.symbol = 'B'; } } @@ -56,7 +56,7 @@ function Board() { ]; // for( let i=0; i<=11 ; i++){ theRs.forEach((item, index) => { - let theReds = new Checker1('red'); + let theReds = new Checker('red'); let coordinate = theRs[index]; // console.log(theReds); this.checkers.push(coordinate); @@ -65,7 +65,7 @@ function Board() { }); theBs.forEach((item, index) => { - let theBlacks = new Checker1('black'); + let theBlacks = new Checker('black'); let coordinate1 = theBs[index]; // console.log(theReds); this.checkers.push(coordinate1); @@ -148,14 +148,34 @@ class Game { console.log(whatPiece); console.log(moveTo); console.log("hello i'm in moveChecker function"); - //console.log(this.board.grid); + + // is move valid + if (isValid(piece1, piece2)) { + + + + + this.board.grid[moveTo[0]][moveTo[1]] = this.board.grid[whatPiece[0]][whatPiece[1]]; + this.board.grid[whatPiece[0]][whatPiece[1]] = ''; + + } else { + return "invalid move"; + } + + - this.board.grid[moveTo[0]][moveTo[1]]=this.board.grid[whatPiece[0]][whatPiece[1]]; - this.board.grid[whatPiece[0]][whatPiece[1]]=''; } + + + + + + + + } From 6903eda222bffdb2e41fa447d7b8055f9554d635 Mon Sep 17 00:00:00 2001 From: aguevara1 Date: Sat, 25 Aug 2018 13:36:40 -0500 Subject: [PATCH 6/8] keep working on it --- 05week/checkers.js | 60 ++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/05week/checkers.js b/05week/checkers.js index a3ec43145..db388cbed 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -20,12 +20,15 @@ class Checker { } -function Board() { - this.grid = []; +class Board { + constructor() { + this.grid = []; + + this.checkers = []; - this.checkers = []; - //place or push checkers in their starting position - this.makeTheCheckers = function() { + } + //place or push checkers in theistarting position + makeTheCheckers() { let theRs = [ [0, 1], [0, 3], @@ -78,7 +81,7 @@ function Board() { // creates an 8x8 array, filled with null values - this.createGrid = function() { + createGrid() { // loop to create the 8 rows for (let row = 0; row < 8; row++) { this.grid[row] = []; @@ -93,11 +96,11 @@ function Board() { //console.log(this.grid[row]); } } - }; + } // prints out the board - this.viewGrid = function() { + viewGrid() { // console.log(this); const symbol = 'A'; // console.log(this.symbol); @@ -126,7 +129,7 @@ function Board() { string += "\n"; } console.log(string); - }; + } } @@ -139,43 +142,40 @@ class Game { this.board.makeTheCheckers(); } + + + } + + + isValid(whatPiece, moveTo) { + //console.log(this.board.grid[moveTo[0]][moveTo[1]]); + + let result = this.board.grid[moveTo[0]][moveTo[1]] !== null; + return result; } + + moveChecker(piece1, piece2) { let whatPiece = piece1.split(''); let moveTo = piece2.split(''); - console.log(whatPiece); - console.log(moveTo); + //console.log(whatPiece); + //console.log(moveTo); console.log("hello i'm in moveChecker function"); - // is move valid - if (isValid(piece1, piece2)) { - - - + if (this.isValid(whatPiece, moveTo)) { this.board.grid[moveTo[0]][moveTo[1]] = this.board.grid[whatPiece[0]][whatPiece[1]]; this.board.grid[whatPiece[0]][whatPiece[1]] = ''; } else { - return "invalid move"; + console.log('invalid move'); } - - - } - - - - - - - - } @@ -195,9 +195,6 @@ game.start(); //game.moveChecker('50','41'); - - - // Tests if (typeof describe === 'function') { describe('Game', () => { @@ -226,6 +223,7 @@ if (typeof describe === 'function') { assert.equal(game.board.checkers.length, 23); }); }); + } else { getPrompt(); } From 10fbd6df5a10d11cf340879b99fb37ec1d92f798 Mon Sep 17 00:00:00 2001 From: aguevara1 Date: Sat, 25 Aug 2018 19:40:08 -0500 Subject: [PATCH 7/8] still editing again --- 05week/checkers.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/05week/checkers.js b/05week/checkers.js index db388cbed..b510d9a66 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -147,24 +147,31 @@ class Game { } - isValid(whatPiece, moveTo) { - //console.log(this.board.grid[moveTo[0]][moveTo[1]]); + isValidInput(piece1, piece2) { + //console.log(this.b.grid[moveTo[0]][moveTo[1]]); + // let whatPiece = piece1.split(''); + // let moveTo = piece2.split(''); + const + return moveTo[0] && moveTo[1] && whatPiece[0] && whatPiece[1] <8 ; + + //return moveTo[0]][moveTo[1]] !== null; - let result = this.board.grid[moveTo[0]][moveTo[1]] !== null; - return result; } moveChecker(piece1, piece2) { - let whatPiece = piece1.split(''); - let moveTo = piece2.split(''); + //console.log(whatPiece); //console.log(moveTo); console.log("hello i'm in moveChecker function"); // is move valid - if (this.isValid(whatPiece, moveTo)) { + //isLeega + if (this.isValidInput(piece1, piece2)) { + let whatPiece = piece1.split(''); + let moveTo = piece2.split(''); + this.board.grid[moveTo[0]][moveTo[1]] = this.board.grid[whatPiece[0]][whatPiece[1]]; this.board.grid[whatPiece[0]][whatPiece[1]] = ''; From d921e43a6d01fa48680d7b6415f62aab48373743 Mon Sep 17 00:00:00 2001 From: aguevara1 Date: Sun, 26 Aug 2018 23:19:19 -0500 Subject: [PATCH 8/8] still editing --- 05week/checkers.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/05week/checkers.js b/05week/checkers.js index b510d9a66..22a1a1e0c 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -140,44 +140,51 @@ class Game { this.start = function() { this.board.createGrid(); this.board.makeTheCheckers(); - } + } - } + isValidMove(whatPiece, moveTo) { + this.board.grid[moveTo[0]][moveTo[1]] = this.board.grid[whatPiece[0]][whatPiece[1]]; + this.board.grid[whatPiece[0]][whatPiece[1]] = ''; - isValidInput(piece1, piece2) { - //console.log(this.b.grid[moveTo[0]][moveTo[1]]); - // let whatPiece = piece1.split(''); - // let moveTo = piece2.split(''); - const - return moveTo[0] && moveTo[1] && whatPiece[0] && whatPiece[1] <8 ; + } - //return moveTo[0]][moveTo[1]] !== null; + isValidInput(whatPiece, moveTo) { + return moveTo[0] < 8 && moveTo[1] < 8 && whatPiece[0] < 8 && whatPiece[1] < 8; } - moveChecker(piece1, piece2) { + moveChecker(piece1, piece2) { + let whatPiece = piece1.split(''); + let moveTo = piece2.split(''); //console.log(whatPiece); //console.log(moveTo); console.log("hello i'm in moveChecker function"); // is move valid //isLeega - if (this.isValidInput(piece1, piece2)) { - let whatPiece = piece1.split(''); - let moveTo = piece2.split(''); + if (this.isValidInput(whatPiece, moveTo)) { + + if (this.isValidMove(whatPiece, moveTo)) { + + this.board.grid[moveTo[0]][moveTo[1]] = this.board.grid[whatPiece[0]][whatPiece[1]]; + this.board.grid[whatPiece[0]][whatPiece[1]] = ''; + + } else { + + console.log("invalid move"); + + } - this.board.grid[moveTo[0]][moveTo[1]] = this.board.grid[whatPiece[0]][whatPiece[1]]; - this.board.grid[whatPiece[0]][whatPiece[1]] = ''; } else { - console.log('invalid move'); + console.log('invalid input'); }