Skip to content

Instantly share code, notes, and snippets.

@BinaryMuse
Last active December 18, 2015 22:10
Show Gist options
  • Save BinaryMuse/1eba1fed8eecfcfcc85d to your computer and use it in GitHub Desktop.
Save BinaryMuse/1eba1fed8eecfcfcc85d to your computer and use it in GitHub Desktop.
_ = require("underscore");
# https://github.com/BinaryMuse/trie-hard
dictionary = require "./dictionary"
letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
scores = [ 1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]
scoresByLetter = _.object(letters, scores)
class ScrabbleGame
@RIGHT = 1
@DOWN = 2
playWord: (word, row, column, direction) =>
module.exports = ScrabbleGame
{
"name": "scrabble-scoring",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --compilers coffee:coffee-script/register test/**_test.coffee"
},
"author": "",
"license": "ISC",
"dependencies": {
"chai": "^2.1.2",
"mocha": "^2.2.1",
"prefix-dictionary": "0.0.2",
"sinon": "^1.14.1",
"sinon-chai": "^2.7.0",
"trie-hard": "^0.1.0",
"underscore": "^1.8.2"
},
"devDependencies": {
"coffee-script": "^1.10.0"
}
}
{ expect} = require "chai"
ScrabbleGame = require "../index.coffee"
describe "Scrabble", ->
game = move = null
describe "with no bonus tiles", ->
beforeEach ->
game = new ScrabbleGame()
it "scores the first word", ->
move = game.playWord("button", 7, 7, ScrabbleGame.RIGHT)
expect(move).to.eql({valid: true, score: 8})
# it "doesn't score invalid words", ->
# move = game.playWord("asdf", 7, 7, ScrabbleGame.RIGHT)
# expect(move).to.eql({valid: false, score: 0})
#
# it "requires subsequent moves to share existing tiles", ->
# move = game.playWord("button", 7, 7, ScrabbleGame.RIGHT)
# expect(move).to.eql({valid: true, score: 8})
# move = game.playWord("home", 9, 7, ScrabbleGame.DOWN)
# expect(move).to.eql({valid: false, score: 0})
#
# it "allows and scores crossed words", ->
# move = game.playWord("button", 7, 7, ScrabbleGame.RIGHT)
# expect(move).to.eql({valid: true, score: 8})
#
# move = game.playWord("snow", 6, 12, ScrabbleGame.DOWN)
# expect(move).to.eql({valid: true, score: 7})
#
# it "doesn't allow playing off the edge of the board", ->
# move = game.playWord("button", 7, 7, ScrabbleGame.RIGHT)
# expect(move).to.eql({valid: true, score: 8})
#
# move = game.playWord("snow", 6, 12, ScrabbleGame.DOWN)
# expect(move).to.eql({valid: true, score: 7})
#
# move = game.playWord("winning", 9, 12, ScrabbleGame.RIGHT)
# expect(move).to.eql({valid: false, score: 0})
#
# it "scores correctly when multiple words are crossed", ->
# move = game.playWord("button", 7, 7, ScrabbleGame.RIGHT)
# expect(move).to.eql({valid: true, score: 8})
#
# move = game.playWord("bad", 7, 7, ScrabbleGame.DOWN)
# expect(move).to.eql({valid: true, score: 6})
#
# move = game.playWord("apian", 8, 7, ScrabbleGame.RIGHT)
# expect(move).to.eql({valid: true, score: 17})
describe "with bonus tiles", ->
beforeEach ->
game = new ScrabbleGame
doubleWord: [[ ]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment