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

@cheezitman @pilgrimmemoirs #32

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
308 changes: 308 additions & 0 deletions scrabble-wave12opts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
// DONE ---- score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter.
// DONE ---- highestScoreFrom(arrayOfWords): returns the word in the array with the highest score.
// DONE ---- Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters.
// DONE ---- Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles.
// DONE ---- If the there are multiple words that are the same score and same length, pick the first one in supplied list.

// ARRAYS FOR TESTING
wordPointArray = [5, 10, 13]

wordArray = ["GATO", "RABBIT", "VACUUM"]

shortWordArray = ["AEI", "MAP", "ZAP" ]

shortWordPointArray = [3, 7, 14]

sevenWordArray = ['LOCKBOX', 'QUIZ', 'JAZZMEN', 'GATO', 'ZAP', 'JACUZZI', 'JAZZMAN']

sevenWordPointArray = [72, 22, 5, 14, 84, 84]

// /ARRAYS FOR TESTING


var Scrabble = function() {}

Scrabble.letterPoints = {
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 };



maggie = new Scrabble()
// console.log( Scrabble.letterPoints );

// console.log( Scrabble.letterPoints.A );



Scrabble.assign = function(letter) {
return Number( Scrabble.letterPoints[ letter ] );
};

Scrabble.score = function(word) {
word = word.toUpperCase();

if( word.length == 7 ) {
var wordScore = 50 }

else wordScore = 0;

var ltr_array = word.split( '' );

ltr_array.forEach( function( element ) {
wordScore += Scrabble.assign( element );}
);

return wordScore;
};

// sassa = new Scrabble();
// console.log( Scrabble.score('GATO'));
// console.log( '**** 5 ****' )

// // ********************************

Scrabble.showScores = function( array ) {

array.forEach( function( element ) {
console.log( Scrabble.score( element ));});
};


// Scrabble.showScores( wordArray );
// console.log( '*****' + wordPointArray + '*****');


// // ********************************
Scrabble.highestScore = function( array ) {
var maxScore = 0

var word = ''

array.forEach( function( element ) {
var points = Scrabble.score( element );

if( points > maxScore ) {
word = element;
maxScore = points;}
});

return word;
}

// console.log( Scrabble.highestScore( wordArray ) )
// console.log( '***VACUUM***')

// // ********************************

Scrabble.highestScoreShortestWord = function( array ) {
var maxScore = 0

var word = ''

array.forEach( function( element ) {
var points = Scrabble.score(element);

if( points > maxScore ) {
word = element;
maxScore = points; }

else if( points == maxScore ) {
if( element.length < word.length ) {
word = element;
maxScore = points; }
}
});

return [ word, maxScore ];
}



// console.log( Scrabble.highestScoreShortestWord( shortWordArray ))
// console.log( '*** [ZAP, 14] ***')

// // ********************************

Scrabble.highestScoreShortestWordSevenLetters = function( array ) {
var maxScore = 0

var word = ''

array.forEach( function( element ) {
var points = Scrabble.score( element );

if( points > maxScore ) {
word = element;
maxScore = points;}

else if( ( points == maxScore ) && ( element.length != word.length ) ) {
if( element.length == 7 ) {
word = element;
maxScore = points;}

else if( ( element.length < word.length ) && ( word.length != 7 ) ) {
word = element;
maxScore = points;}
};
});

return [ word, maxScore ];
}

// console.log( Scrabble.highestScoreShortestWordSevenLetters( sevenWordArray ) )
// console.log( '*** [JAZZMEN, 84] ***')


module.exports = Scrabble;


// Wave 2

// Primary Requirements

// Create a new Player object. The object should have the following functions:

// DONE ---- Constructor: Called when you use new Player(name), sets up an instance with the instance variable name assigned
// DONE ---- name: property which returns the value of the player's name
// DONE plays: property which returns an Array of the words played by the player
// DONE play(word): Function which adds the input word to the plays Array
// Returns false if player has already won
// DONE totalScore(): Function which sums up and returns the score of the players words
// DONE hasWon(): Function which returns true if the player has over 100 points, otherwise returns false
// DONE highestScoringWord(): Function which returns the highest scoring word the user has played
// DONE highestWordScore(): Function which returns the highestScoringWord score


var Player = function( name ) {
this.name = name,
this.plays = []};

Player.prototype.play = function( word ) {
console.log( 'doing something ' + word );
this.plays.push( word );
return this.hasWon(); };

Player.prototype.hasWon = function() {
return this.totalScore() >= 100 };

Player.prototype.totalScore = function() {
var playerScore = 20;

this.plays.forEach( function( element ) {
playerScore += Scrabble.score( element ) } );

return playerScore;};

Player.prototype.highestScoringWord = function( array ) {
var bestWordScoreArray = Scrabble.highestScoreShortestWordSevenLetters( this.plays );
return bestWordScoreArray[0];
};

Player.prototype.highestWordScore = function( array ) {
var bestWordScoreArray = Scrabble.highestScoreShortestWordSevenLetters( this.plays );
return bestWordScoreArray[1];
};


// sassa = new Player( 'Sassa ')

// console.log( sassa.name )

// sassa.play( 'GATO' )


// sassa.play( 'quiz' )

// console.log( sassa.plays )

// console.log( '*** [GATO, quiz] ***')


// console.log( sassa.totalScore() )

// console.log( '*** 27 ***')

// console.log( sassa.highestScoringWord() )

// console.log( '*** quiz ***')

// console.log( sassa.highestWordScore())

// console.log( '*** 22 ***')

// console.log( sassa.totalScore() )

// console.log( sassa.play( 'WIN' ) )

// console.log( sassa.totalScore() )

// console.log( sassa.plays )

// console.log( sassa.totalScore() )


var TileBag = function() {}

TileBag.prototype.tiles = {
A: 9,
E: 12,
I: 9,
O: 8,
U: 4,
L: 1,
N: 6,
R: 6,
S: 4,
T: 6,
D: 4,
G: 3,
B: 2,
C: 2,
M: 2,
P: 2,
F: 2,
H: 2,
V: 2,
W: 2,
Y: 2,
K: 1,
J: 1,
X: 1,
Q: 1,
Z: 1 };


var TileBag.drawTiles = function( letter ) {
map.put(TileBag[ letter ], map.get(TileBag[ letter ]) -1 );
}

test = new TileBag

console.log( test.tiles )


Loading