Hang Man and Word Find Games Written in Python:
Using Successive Approximation and Newton Raphson's
Methods:
Links
to files for the Hang
Man and Word Find Games in Python
Successive Approximation:
- We used successive approximation to try to guess the
answer to a problem and then check our guess.
- If guess is wrong, keep improving it in small
increments and checking it, until you determine the
answer is good enough.
- We also looked at Newton's Method, which uses
successive approximation to to find the roots of a
function.
- Polynomials were represented as lists.
- The index of the list was the power, and the value of
the index to represent the coefficient.
- We also had to compute the derivative of
polynomials.
Newton's Method (also known as
Newton-Raphson Method)
- Newton-Raphson is a successive approximation method
for finding the roots of a function, or the values of x
such that f(x) = 0.
- (1) iteration zero - guess some x0.
- (2) check to see if a root by calcuating f(x0) within
some small epsilon of 0.
- (3) If f(x0) not good enough, come up with better
guess of x1. "x1 = x0 - f(x0) / (deriv. of
f(xo))"
- (4) check to see if x1 close enough to a root. If
not, make better guess x2 and check and so on.
- For every x(n), that is not close enough to root,
replace "x(n+1) = x(n) - f(x(n)) / (deriv. of f(x(n)))"
and check.
- Repeat until you have a value close enough to
root.
- Polynomial functions were used for
simplicity.
Hang Man Game in Python
- The last part of this problem set was a hang man word
game.
- The computer selected from a list of available words
read in from a list file.
- The player knows the number of letters at start of
game.
- Player guesses one letter per round.
- Player receives immediate feedback whether letter is
in word.
- Each round the game displays partially guessed word so
far, as well as letters player has not used
yet.
- Player is allowed 8 guesses.
- Player loses a guess only when guessing
incorrectly.
- Error message displayed if same letter guessed twice,
but not counted.
- Game ends when player either guesses word or runs out
of guesses.
Scrabble Game in Python: Rules of the Game
Links
to files for the Scrabble Game in Python
- Player is dealt hand of n letters chosen at
random.
- Player arranges hand into as many words as they want
out of letters, using each letter at most once.
- Some letters remain unused and are not
scored.
- The score for the hand is the sum of the scores for
each word formed.
- The score for a word is the sum of the points for
letters in the word, multiplied by the length of the
word, plus 50 points if all n letters are used on the
first word created.
- Letters are scored as in Scrabble. A=1, B=3, C=3, D=2,
E=1, and so on.
- A dictionary was used (key,value pair entries) to
associate letter to its value for this game.
- A function was used to get the frequency of a letter
in a word.
- When given a string of letters as input, it returns a
dictionary (key,value pairs) of a letter as key, and the
value was the number of occurrences of that letter in
the word.