From efa4ae001b235226d1f7c20bab20a7d971a360b7 Mon Sep 17 00:00:00 2001 From: Kelly Souza Date: Tue, 16 May 2017 14:58:03 -0700 Subject: [PATCH 1/5] Score function working --- scrabble.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/scrabble.js b/scrabble.js index a7d0745..d900c25 100644 --- a/scrabble.js +++ b/scrabble.js @@ -6,3 +6,72 @@ Scrabble.prototype.helloWorld = function() { }; module.exports = Scrabble; + + +myScrabble = new Scrabble +console.log(myScrabble.helloWorld()); + + +var scoreChart = { + 1: ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], + 2: ["D", "G"], + 3: ["B", "C", "M", "P"], + 4: ["F", "H", "V", "W", "Y"], + 5: ["K"], + 8: ["J", "X"], + 10: ["Q", "Z"] +}; + + +var score = function(word) { + word = word.toUpperCase(); + var points = 0; + if (word.length >= 7){ + points += 50; + } + for (var i = 0, len = word.length; i < len; i++) { + switch (true) { + case scoreChart[1].includes(word[i]): + points += 1; + break; + case scoreChart[2].includes(word[i]): + points += 2; + break; + case scoreChart[3].includes(word[i]): + points += 3; + break; + case scoreChart[4].includes(word[i]): + points += 4; + break; + case scoreChart[5].includes(word[i]): + points += 5; + break; + case scoreChart[8].includes(word[i]): + points += 8; + break; + case scoreChart[10].includes(word[i]): + points += 10; + break; + } + } + return points; +} + +// console.log(scoreChart[1].includes("E")); + +console.log(score("CAT")); +console.log(score("ZZZ")); +console.log(score("zzZ")); +console.log(score("ZFFHW")); +console.log(score("AAAAAAA")); +console.log(score("aaaaaaa")); + + +// Letter Value +// A, E, I, O, U, L, N, R, S, T 1 +// D, G 2 +// B, C, M, P 3 +// F, H, V, W, Y 4 +// K 5 +// J, X 8 +// Q, Z 10 From 9c4fef2498489b2a0470d28aaf812dbc5edc106e Mon Sep 17 00:00:00 2001 From: Kelly Souza Date: Tue, 16 May 2017 15:54:59 -0700 Subject: [PATCH 2/5] Adds highestscore from array function --- scrabble.js | 60 +++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/scrabble.js b/scrabble.js index d900c25..52d336d 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,17 +1,5 @@ var Scrabble = function() {}; -// YOUR CODE HERE -Scrabble.prototype.helloWorld = function() { - return 'hello world!'; -}; - -module.exports = Scrabble; - - -myScrabble = new Scrabble -console.log(myScrabble.helloWorld()); - - var scoreChart = { 1: ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], 2: ["D", "G"], @@ -22,6 +10,7 @@ var scoreChart = { 10: ["Q", "Z"] }; +var arrayOfWords = []; var score = function(word) { word = word.toUpperCase(); @@ -54,24 +43,41 @@ var score = function(word) { break; } } + arrayOfWords.push(word) + // console.log(arrayOfWords) return points; } -// console.log(scoreChart[1].includes("E")); +var highestScoreFrom = function(arrayOfWords) { + var highestScoringWord; + var highestScore = 0; + for (var i = 0; i < arrayOfWords.length; i++) { + if (score(arrayOfWords[i]) > highestScore) { + highestScoringWord = arrayOfWords[i]; + highestScore = score(arrayOfWords[i]); + } else if (score(arrayOfWords[i]) == highestScore) { + if (highestScoringWord.length == 7) { + return highestScoringWord; + } else if (arrayOfWords[i].length == 7) { + highestScoringWord = arrayOfWords[i]; + highestScore = score(arrayOfWords[i]); + } else if (arrayOfWords.length < highestScoringWord.length){ + highestScoringWord = arrayOfWords[i]; + highestScore = score(arrayOfWords[i]); + } + } + } + return highestScoringWord; +} + +// console.log(highestScoreFrom(["CAT", "DOG", "AAAAAA", "AAAAD" ])); + +Scrabble.prototype.helloWorld = function() { + return 'hello world!'; +}; -console.log(score("CAT")); -console.log(score("ZZZ")); -console.log(score("zzZ")); -console.log(score("ZFFHW")); -console.log(score("AAAAAAA")); -console.log(score("aaaaaaa")); +module.exports = Scrabble; +myScrabble = new Scrabble; -// Letter Value -// A, E, I, O, U, L, N, R, S, T 1 -// D, G 2 -// B, C, M, P 3 -// F, H, V, W, Y 4 -// K 5 -// J, X 8 -// Q, Z 10 +console.log(myScrabble.helloWorld()); From 96bb3b44dae5340d18070f0ec2ad704d5339d9c8 Mon Sep 17 00:00:00 2001 From: Kelly Souza Date: Tue, 16 May 2017 16:42:46 -0700 Subject: [PATCH 3/5] Changing score object format, simplifying score method --- scrabble.js | 92 ++++++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/scrabble.js b/scrabble.js index 52d336d..b07d33d 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,76 +1,70 @@ var Scrabble = function() {}; var scoreChart = { - 1: ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], - 2: ["D", "G"], - 3: ["B", "C", "M", "P"], - 4: ["F", "H", "V", "W", "Y"], - 5: ["K"], - 8: ["J", "X"], - 10: ["Q", "Z"] + A: 1, + E: 1, + I: 1, + O: 1, + U: 1, + L: 1, + N: 1, + R: 1, + S: 1, + T: 1, + D: 2, + G: 2, + B: 3, + C: 3, + M: 3, + P: 3, + F: 4, + H: 4, + V: 4, + W: 4, + Y: 4, + K: 5, + J: 8, + X: 8, + Q: 10, + Z: 10 }; var arrayOfWords = []; -var score = function(word) { +Scrabble.prototype.score = function(word) { word = word.toUpperCase(); var points = 0; - if (word.length >= 7){ + if (word.length == 7){ points += 50; } for (var i = 0, len = word.length; i < len; i++) { - switch (true) { - case scoreChart[1].includes(word[i]): - points += 1; - break; - case scoreChart[2].includes(word[i]): - points += 2; - break; - case scoreChart[3].includes(word[i]): - points += 3; - break; - case scoreChart[4].includes(word[i]): - points += 4; - break; - case scoreChart[5].includes(word[i]): - points += 5; - break; - case scoreChart[8].includes(word[i]): - points += 8; - break; - case scoreChart[10].includes(word[i]): - points += 10; - break; + points += scoreChart[word[i]]; } - } arrayOfWords.push(word) - // console.log(arrayOfWords) return points; } -var highestScoreFrom = function(arrayOfWords) { + Scrabble.prototype.highestScoreFrom = function(arrayOfWords) { var highestScoringWord; var highestScore = 0; for (var i = 0; i < arrayOfWords.length; i++) { - if (score(arrayOfWords[i]) > highestScore) { + if (this.score(arrayOfWords[i]) > highestScore) { highestScoringWord = arrayOfWords[i]; - highestScore = score(arrayOfWords[i]); - } else if (score(arrayOfWords[i]) == highestScore) { + highestScore = this.score(arrayOfWords[i]); + } else if (this.score(arrayOfWords[i]) == highestScore) { if (highestScoringWord.length == 7) { - return highestScoringWord; } else if (arrayOfWords[i].length == 7) { highestScoringWord = arrayOfWords[i]; - highestScore = score(arrayOfWords[i]); + highestScore = this.score(arrayOfWords[i]); } else if (arrayOfWords.length < highestScoringWord.length){ highestScoringWord = arrayOfWords[i]; - highestScore = score(arrayOfWords[i]); + highestScore = this.score(arrayOfWords[i]); } } } return highestScoringWord; } -// console.log(highestScoreFrom(["CAT", "DOG", "AAAAAA", "AAAAD" ])); Scrabble.prototype.helloWorld = function() { return 'hello world!'; @@ -78,6 +72,18 @@ Scrabble.prototype.helloWorld = function() { module.exports = Scrabble; -myScrabble = new Scrabble; - +myScrabble = new Scrabble(); console.log(myScrabble.helloWorld()); +// +console.log(myScrabble.score("CAT")); + +console.log(myScrabble.score("DOG")); + +console.log(myScrabble.score("ZZZZZZ")); + +console.log(myScrabble.score("AAAAADC")); + +console.log(myScrabble.highestScoreFrom([ "AAAAACD", "QQQQQQQ", "ZZZZZZ"])); + + +var Player = function() {}; From 9fbad426f2d381ae8bb3c377308d8faf18ef5044 Mon Sep 17 00:00:00 2001 From: Kelly Souza Date: Wed, 17 May 2017 14:37:40 -0700 Subject: [PATCH 4/5] Wave 2 done --- scrabble.js | 149 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 103 insertions(+), 46 deletions(-) diff --git a/scrabble.js b/scrabble.js index b07d33d..21f301b 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,37 +1,16 @@ -var Scrabble = function() {}; - +// HELPER METHODS var scoreChart = { - A: 1, - E: 1, - I: 1, - O: 1, - U: 1, - L: 1, - N: 1, - R: 1, - S: 1, - T: 1, - D: 2, - G: 2, - B: 3, - C: 3, - M: 3, - P: 3, - F: 4, - H: 4, - V: 4, - W: 4, - Y: 4, - K: 5, - J: 8, - X: 8, - Q: 10, + A: 1, E: 1, I: 1, O: 1, U: 1, + L: 1, N: 1, R: 1, S: 1, T: 1, + D: 2, G: 2, B: 3, C: 3, M: 3, + P: 3, F: 4, H: 4, V: 4, W: 4, + Y: 4, K: 5, J: 8, X: 8, Q: 10, Z: 10 }; var arrayOfWords = []; -Scrabble.prototype.score = function(word) { +var scoreHelper = function (word) { word = word.toUpperCase(); var points = 0; if (word.length == 7){ @@ -42,48 +21,126 @@ Scrabble.prototype.score = function(word) { } arrayOfWords.push(word) return points; -} +}; - Scrabble.prototype.highestScoreFrom = function(arrayOfWords) { +var highestScoringWordHelper = function(arrayOfWords) { var highestScoringWord; var highestScore = 0; for (var i = 0; i < arrayOfWords.length; i++) { - if (this.score(arrayOfWords[i]) > highestScore) { + if (scoreHelper(arrayOfWords[i]) > highestScore) { highestScoringWord = arrayOfWords[i]; - highestScore = this.score(arrayOfWords[i]); - } else if (this.score(arrayOfWords[i]) == highestScore) { + highestScore = scoreHelper(arrayOfWords[i]); + } else if (scoreHelper(arrayOfWords[i]) == highestScore) { if (highestScoringWord.length == 7) { } else if (arrayOfWords[i].length == 7) { highestScoringWord = arrayOfWords[i]; - highestScore = this.score(arrayOfWords[i]); + highestScore = scoreHelper(arrayOfWords[i]); } else if (arrayOfWords.length < highestScoringWord.length){ highestScoringWord = arrayOfWords[i]; - highestScore = this.score(arrayOfWords[i]); + highestScore = scoreHelper(arrayOfWords[i]); } } } return highestScoringWord; -} +}; + +var highestWordScoreHelper = function (arrayOfWords) { + var word = highestScoringWordHelper(arrayOfWords); + return scoreHelper(word); +}; + +// SCRABBLE METHODS + + +var Scrabble = function() {}; + +Scrabble.prototype.score = function(word) { + return scoreHelper(word); +}; + + + Scrabble.prototype.highestScoreFrom = function(arrayOfWords) { + return highestScoringWordHelper(arrayOfWords); +}; Scrabble.prototype.helloWorld = function() { return 'hello world!'; }; -module.exports = Scrabble; +// PLAYER METHODS -myScrabble = new Scrabble(); -console.log(myScrabble.helloWorld()); -// -console.log(myScrabble.score("CAT")); +var Player = function (name) { + this.name = name; + this.playerWords = []; +} + +Player.prototype.plays = function () { + console.log("My turn!"); +}; + +Player.prototype.play = function (word) { + console.log(this.hasWon()) + if (this.hasWon()) { + return console.log("Cannot play that word", this.name, "has already won!"); + } else { + this.playerWords.push(word); + console.log(this.playerWords); + } +}; + +Player.prototype.totalScore = function () { + var playerScore = 0; + var scrabble = new Scrabble(); + for (var i = 0; i < this.playerWords.length; i++) { + playerScore += scrabble.score(this.playerWords[i]); + } + return playerScore; +}; + +Player.prototype.hasWon = function () { + if (this.totalScore() >= 100) { + return true; + } else { + return false; + } +}; + +Player.prototype.highestScoringWord = function () { + return highestScoringWordHelper(this.playerWords); +}; -console.log(myScrabble.score("DOG")); +Player.prototype.highestWordScore = function () { + return highestWordScoreHelper(this.playerWords); +}; -console.log(myScrabble.score("ZZZZZZ")); -console.log(myScrabble.score("AAAAADC")); +module.exports = Scrabble; + +myScrabble = new Scrabble(); -console.log(myScrabble.highestScoreFrom([ "AAAAACD", "QQQQQQQ", "ZZZZZZ"])); +p = new Player("Kelly"); +console.log(p.name); -var Player = function() {}; +p.plays(); +p.play("Hello"); +p.play("World"); +console.log(p.totalScore()); +p.play("cat"); +console.log(p.totalScore()); +p.play("ZZZZZ"); +console.log(p.totalScore()); +p.play("AA"); +console.log(p.totalScore()); +p.play("ZZZZZ"); +console.log(p.totalScore()); +p.play("ZZZZZ"); +console.log(p.totalScore()); +p.play("ZZZZZ"); +console.log(p.totalScore()); +console.log(p.highestScoringWord()); +console.log(p.highestWordScore()); +p.play("ZZZZZZZ"); +console.log(p.highestScoringWord()); +console.log(p.highestWordScore()); From ad898ab943ecea76573276fe9d8889d0531f35f4 Mon Sep 17 00:00:00 2001 From: Kelly Souza Date: Thu, 18 May 2017 09:12:00 -0700 Subject: [PATCH 5/5] can call highest scroing word on player or game --- scrabble.js | 73 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/scrabble.js b/scrabble.js index 21f301b..1f1e19a 100644 --- a/scrabble.js +++ b/scrabble.js @@ -19,7 +19,6 @@ var scoreHelper = function (word) { for (var i = 0, len = word.length; i < len; i++) { points += scoreChart[word[i]]; } - arrayOfWords.push(word) return points; }; @@ -52,15 +51,18 @@ var highestWordScoreHelper = function (arrayOfWords) { // SCRABBLE METHODS -var Scrabble = function() {}; +var Scrabble = function() { + this.arrayOfWords = []; +}; Scrabble.prototype.score = function(word) { + this.arrayOfWords.push(word); return scoreHelper(word); }; - Scrabble.prototype.highestScoreFrom = function(arrayOfWords) { - return highestScoringWordHelper(arrayOfWords); +Scrabble.prototype.highestScoreFrom = function() { + return highestScoringWordHelper(this.arrayOfWords); }; @@ -70,25 +72,33 @@ Scrabble.prototype.helloWorld = function() { // PLAYER METHODS -var Player = function (name) { +var Player = function (name, game) { this.name = name; this.playerWords = []; -} + this.game = game; +}; Player.prototype.plays = function () { console.log("My turn!"); }; + +// refactor to include a save word to game method Player.prototype.play = function (word) { - console.log(this.hasWon()) if (this.hasWon()) { return console.log("Cannot play that word", this.name, "has already won!"); } else { this.playerWords.push(word); + this.saveWordToGameWordArray(word); console.log(this.playerWords); } }; + +Player.prototype.saveWordToGameWordArray = function (word) { + this.game.arrayOfWords.push(word); +} + Player.prototype.totalScore = function () { var playerScore = 0; var scrabble = new Scrabble(); @@ -119,28 +129,33 @@ module.exports = Scrabble; myScrabble = new Scrabble(); -p = new Player("Kelly"); +p = new Player("Kelly", myScrabble); +q = new Player("Kevin", myScrabble); console.log(p.name); - -p.plays(); +console.log(q.name); + + +// p.plays(); +// p.play("Hello"); +// p.play("World"); +// console.log(p.totalScore()); +// p.play("cat"); +// console.log(p.totalScore()); +// p.play("ZZZZZ"); +// console.log(p.totalScore()); +// p.play("AA"); +// console.log(p.totalScore()); +// p.play("ZZZZZ"); +// console.log(p.totalScore()); p.play("Hello"); -p.play("World"); -console.log(p.totalScore()); -p.play("cat"); -console.log(p.totalScore()); -p.play("ZZZZZ"); -console.log(p.totalScore()); -p.play("AA"); -console.log(p.totalScore()); -p.play("ZZZZZ"); -console.log(p.totalScore()); -p.play("ZZZZZ"); -console.log(p.totalScore()); -p.play("ZZZZZ"); -console.log(p.totalScore()); -console.log(p.highestScoringWord()); -console.log(p.highestWordScore()); -p.play("ZZZZZZZ"); -console.log(p.highestScoringWord()); -console.log(p.highestWordScore()); +p.play("WorldZ"); +// p.play("ZZZZZZZ"); +// console.log(p.highestScoringWord()); +// console.log(p.highestWordScore()); +q.play("Hello"); +q.play("world"); +console.log(q.totalScore()); +console.log(myScrabble.helloWorld()); +console.log(myScrabble.score("cat")); +console.log(myScrabble.highestScoreFrom());