#################################################
# team-hw5-starter-file.py
#################################################

# This file can be shared with all students on the team.

import random, string

#################################################
# monte carlo: deMeres problem
#################################################

'''
Question:  which is the better bet (which is more likely):

  Option A: Rolling a 6 in 4 rolls of 1 die

  or

  Option B: Rolling double-6's in 24 rolls of 2 dice

Use Monte Carlo Methods to determine the answer.
'''

#################################################
# mode(L)
#################################################

'''
Write the function mode(L) that takes a list L and returns its mode,
that is, the most-common value in L.  If the list is empty, return None.
If the list has more than one mode, return a sorted list of all of them.
See the test function for some examples.
'''

def mode(L):
    return 42

def testMode():
    print('Testing mode()...', end='')
    assert(mode([]) == None)
    assert(mode([1]) == 1)
    assert(mode([1,3,2]) == [1,2,3])
    assert(mode([1,3,2,3,4]) == 3)
    assert(mode([1,4,2,3,4,5,3]) == [3, 4])
    # make sure mode is non-destructive!
    a1 = [1,4,2,3,4,5,3]
    a2 = a1 + [ ] # a copy
    assert(mode(a2) == [3, 4])
    if (a1 != a2): raise Exception('Your mode() function should be non-destructive!')
    print('Passed!')

testMode()

#################################################
# Modified Perquackey
#################################################

'''
This is based on the game of Perquackey
See https://en.wikipedia.org/wiki/Perquackey

In our modified version, we'll generate a random list of letters
(instead of rolling dice to get the letters), then the player can
repeatedly enter a word. If it's in the dictionary and is legal
(that is, is at least 3 characters long and can be made out of the letters
in the list), then the player scores a point, otherwise they lose a
point.  The player can also enter 's' to show all the legal answers.
Finally, the player can enter 'q' to quit.

To write this game, first download this file:
    http://kosbie.net/cmu/spring-07/15-111/handouts/words.txt
Save that file to words.txt, and place it in the same folder as the
Python file you are editing.

1. Write this game.
2. Play the game for a while.  Have fun!
3. Thought questions:
   A. Words.txt is good but not great, leaving out a lot of valid words,
      especially plurals and other derived forms of words.
      Can you find a better dictionary (words.txt) to use?
   B. How can we be sure we get enough (and not too many) vowels?
   C. How can we use the letter-dice in the actual game?
'''

def readFile(path):
    # This makes a very modest attempt to deal with unicode if present
    with open(path, 'rt', encoding='ascii', errors='surrogateescape') as f:
        return f.read()

def playModifiedPerquackey():
    pass

playModifiedPerquackey()
