Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP, scrabble.js has all of the methods. See comments below. [Brrrrrrackets] #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,107 @@
we won't be bringing anything into this file. Later, we may make good
use of this file.
*/
var Scrabble = function(){
this.letterScore = {
"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};
this.tiles = ["D","L","S","U","D","L","S","U","D","L","S","U","D","L","S","U","G","G","G","Q","J","K","X","Z","M","B","C","F","H","V","W","Y","P","M","B","C","F","H","V","W","Y","P","E","E","E","E","E","E","E","E","E","E","E","E","I","I","I","I","I","I","I","I","I","O","O","O","O","O","O","O","O","R","R","R","R","R","R","T","T","T","T","T","T","N","N","N","N","N","N"];
};

/////////////////////////tile functions//////////////////////////////////////////////////

//this function shall shuffle the tiles
Scrabble.prototype.shuffle = function(){
for (let i = this.tiles.length; i; i--){
let j = Math.floor(Math.random() * i);
[this.tiles[i - 1], this.tiles[j]] = [this.tiles[j], this.tiles[i - 1]];
}
console.log(this.tiles);
return this.tiles;
};

//this function shall draw tiles from the TileBag after each play
Scrabble.prototype.drawTiles = function(num){
this.tilesDrawn = tilesDrawn;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this tilesDrawn variable coming from?

this.tileBag.pop(num); //'tileBag' comes from the instanciation of a player, in this case scrabble.
return this.tilesDrawn;
};

//this function shall return the number of tiles remaining in the bag
Scrabble.prototype.remainingTiles = function(){
console.log(this.tileBag.length);
return this.tileBag.length;
};

/////////////////////////////Scoring Functions////////////////////////////////////////////

// this function shall allocate a 50pt bonus for words of 7 characters
Scrabble.prototype.bonus = function(word){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this used? It doesn't seem like the score function is calling it

this.word = word;
if(this.word.length === 7){
this.total += 50;}
};


// this function shall score each played word.
Scrabble.prototype.score = function(word) {
var total = 0;
this.word = (word.toUpperCase());
for (let current of this.word){
total = total + this.letterScore[current];
}
console.log(total);
return total;

};

//this method needs a few things before itll actually be functional.
//this function shall determine the highest scoring word of the game
Scrabble.prototype.highestScore = function (arrayOfWords) {
// key = score, value = word
this.scores = {};
//the array all the words are shoveled into once played
this.arrayOfWords = arrayOfWords;
// iterate through the list of words, if the score of the word is already included as a key in the hash, add the word to the array of values, otherwise add the score as a new key and the word as its value.
for (let current of this.arrayOfWords){
//if the score is already a key in scores, shovel the word into the array of its values
if ((score(current) in this.scores)){
this.scores[score(current)].push(current);}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will a word have more than one score?

else {
this.scores[score(word)] = [word];}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By calling the score() method here a few times, you're doing a bit of unnecessary work

}};

arrayOfWords = [30 , 60, 900, 22, -9, 21];
Math.max([array]);

Scrabble.prototype.scoreMax = function (arrayOfWords) {
this.arrayOfWords = arrayOfWords;
console.log(Math.max.apply(null, this.arrayOfWords.keys));
return Math.max.apply(null, this.arrayOfWords.keys);
};


/////////////////////////////// This is the beginning of the player functions ///////////////////////

//this shall be the player Constructor fxn
var Player = function(name){
this.name = name;
this.plays = plays;
this.tiles = tiles;
this.totalScore = 0;
};

Player.prototype.drawTiles = function (tile_bag) {
num_tiles = 7 - this.tiles.length;
};

b = new Scrabble();
b.score("ZazZlE");
b.shuffle();



///////////////////////////////////////////////////////////////////////////////////////////

module.exports = Scrabble;