Source

spelltower-scoring / value.py

Full commit
letters = dict( a = 1,
        d = 2,
        e = 1,
        f = 4,
        g = 2,
        h = 4,
        i = 1,
        m = 3,
        n = 1,
        o = 1,
        p = 3,
        r = 1,
        s = 1,
        t = 1,
        w = 4,
        x = 24,
        y = 4,
        z = 22,
        )

def score(word):
  """
  Returns the Spelltower score for a word.
  """
  total = 0
  for letter in word:
    total += letters[letter]
  return total * len(word)

def guess_letters(word, score, surrounding=0):
  if len(word) >= 5:
    print "Not even trying to guess long words like %s right now." % word
    return
  total = score/len(word)
  unknown = ""
  #print "%(points)d points in the letters of '%(word)s'." % dict(points=total, word=word)
  for letter in word:
    try:
      total -= letters[letter]
      #print "%(points)d points for %(letter)s" % dict(points=letters[letter], 
      #    letter=letter)
    except KeyError:
      #print "No score known for %(letter)s." % dict(letter=letter)
      unknown += letter
  if len(unknown) == 0 and total == 0:
    print "Solved for the word: %s" % word
  else:
    print "Remaining: %(total)d points for '%(unknown)s' from %(word)s." % dict(total=total, unknown=unknown, word=word)

if __name__ == "__main__":
  for word, value in dict(
        quod=92,
        wqer=0, tyui=0, opl=0,
        asdf=0, ghjk=0,
        zxcv=0, bnm=0,
      ).items():
    guess_letters(word, value)
  if False: # Ignore the long words for now.
    guess_letters("queer", 245)
    guess_letters("sulker", 216, 13)
    guess_letters("sulker", 234, 13)
    guess_letters("greet", 180, 7)
    guess_letters("greet", 170, 8)
    guess_letters("greed", 160, 7)