Git Product home page Git Product logo

valett's Introduction

Valett

Valett is a Node module for determining the appropriate letter valuations in word games. Valett analyzes the corpus of a game's legal plays and provides point values for the letters in the game based on a desired weighting of their frequency, frequency by length and the entropy of their transition probabilities.

An example script for determining appropriate letter values for Scrabble is in the scrabble/ directory. To run it, navigate to scrabble/ and run (with CoffeeScript installed globally):

coffee scrabble.coffee

One could also use Valett to calculate board difficulty in a game like Boggle (boards with neighboring letters that have a low probability of transitioning to each other are harder).

Installation

Install via NPM:

npm install valett

Usage

valett = require 'valett'

From the Scrabble example (CoffeeScript):

valett.init words, letters

weights = {frequency: .34, frequencyByLength: .33, entropy: .33}
frequencyByLengthWeights = [0, 50, 25, 5, 2.5, 1.25, 0.625, 25, 12.5, 2.5, 1.25, 0, 0, 0, 0]
entropyWeights = [.5, .5]

valett.analyze 10, weights, frequencyByLengthWeights, entropyWeights

console.log "#{letter}: #{valett.values[valett.hash[letter]]}" for letter in letters

Words is an array of acceptable words and letters is a sorted (to your preference) array of the unique letters in the corpus. Valett stores a hash from letters to array indices in valett.hash, and stores the computed corpus statistics in valett.metadata after valett.init. The computed values are in valett.values after valett.analyze:

valett.analyze maxValue, weights, frequencyByLengthWeights, entropyWeights
  • maxValue is a scaling term for determining the highest possible letter value.

  • weights is an object whose fields determine the relative weighting of frequency, frequency by length, and entropy when calculating letter values. The fields should sum to 1.

  • frequencyByLengthWeights should be the length of the longest word in the corpus, and reflects the relative value of a letter's occurrence in words of different length. For example, in Scrabble it is particularly valuable for a letter to appear in 2, 3, 7 and 8 length words.

  • entropyWeights should be length 2, and reflects the relative value of the ease of transitioning into a letter (how evenly the transition probabilities toward a letter are distributed) and out of a letter. For example, Q has a low entropy out since its transition probability distribution is highly peaked at U.

Contact

Contact Joshua Lewis with comments and suggestions. The code is MIT licensed and pull requests with analyses for other games or new corpus metadata are welcome!

valett's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.