In Python, For this assignment, you will write a program that simulates playing a board game with
Question:
In Python,
For this assignment, you will write a program that simulates playing a board game with up to 4 players. The players each have 8 tiles with which to construct words. The object of the game is to see who can construct the most words with their tiles. If two (or more) players can construct an equal number of words, then the game ends in a tie. Write a program that simulates the game.
The file GameTiles.txt contains all of the tiles needed for the game. The file lists a letter and then how many tiles exist that contain that letter. Read the information from the file into a dictionary. Use the information from that dictionary to "deal" a tile to each player (one at a time: first deal a tile to player1, then to player2, then to player3, etc. Only deal to the active players (many games may be played and sometime players will sit out for a round; active players are players who plan on playing this particular game) - repeating the process until all players have 8 tiles each). This means before each game starts, you need to ask how many people are playing the game. The eight tiles represents the players "hand". Remember, you cannot deal out more tiles than exists in the dictionary. For example, there is only one 'X' tile, thus only one person could possibly have this tile in their hand.
Next you need to find all of the words that can be made with the 8 tiles for each player. Because the same tasks will be done for each player's hand, you should create a function called deal_tiles to perform this task. The function can call other functions if you like. The CROSSWD.TXT file contains all of the official words that can be created by the players. You will also need to a dictionary containing all letters and their point values. You can find the letters and their matching scores in the file GameTiles.txt. You will need call a function called build_tile_pool to read in the information from this file and build a tile dictionary. You will also need to read the pickled data from tile_scores.dat into a dictionary called scores which will hold the information on how many points each tile is worth.
Create a function called find_valid_words to find all of the valid words that can be made from the CROSSWD.TXT file using only the tiles available in each players hand. Make sure you are consistent about capitalization. Make sure you handle repeated letters: once a letter from the rack has been used, it can't be used again. Finally, write a function called determine_word_values the code to determine the scores for each valid word, using the scores dictionary from above. Then display each player's hand and list of words (with each word's score).
An example input and output for a player is as follows:
Player 1's hand: ZAEFIEEC
Word Scores and Words 1: feeze - 17 points 2: feaze - 17 points 3: faze - 16 points 4: fiz - 15 points 5: fez - 15 points 6: zee - 12 points 7: fice - 9 points 8: face - 9 points 9: cafe - 9 points 10: fie - 6 points 11: fee - 6 points 12: if - 5 points 13: ice - 5 points 14: fa - 5 points 15: ef - 5 points 16: cee - 5 points 17: ace - 5 points 18: ai - 2 points 19: ae - 2 points
Lastly, you need to determine and congratulate the winner or let the users know if there is a tie. The player who was able to contruct the most words wins. Hint: consider using lists to keep track of wining players.
CROSSWD.TXT
aa aah aahed aahing aahs aal aalii aaliis aals aardvark aardvarks aardwolf aardwolves aas aasvogel aasvogels aba abaca abacas abaci aback abacus abacuses abaft abaka abakas abalone abalones abamp abampere abamperes abamps abandon abandoned abandoning abandonment abandonments abandons abas abase abased abasedly abasement abasements abaser abasers abases abash abashed abashes abashing abasing abatable abate
abated abatement abatements abater abaters abates abating abatis abatises abator abators abattis abattises abattoir abattoirs abaxial abaxile abbacies abbacy abbatial abbe abbes abbess abbesses abbey abbeys abbot abbotcies abbotcy abbots abbreviate abbreviated abbreviates abbreviating abbreviation abbreviations abdicate abdicated abdicates abdicating abdication abdications abdomen abdomens abdomina abdominal abdominally abduce abduced abducens abducent abducentes abduces
GameTiles.txt
A, 10
B, 2
C, 2
D, 4
E, 12
F, 2
G, 3
H, 2
I, 9
J, 1
K, 1
L, 4
M, 2
N, 6
O, 8
P, 2
Q, 1
R, 6
S, 4
T, 6
U, 5
V, 2
W, 2
X, 1
Y, 2
Z, 1
tile_scores.dat
}q(XaqKXcqKXbqKXeqKXdqKXgqKXfqKXiqKXhq KXkq
KXjqKXmq
Starting Out With Java From Control Structures Through Data Structures
ISBN: 9780133957051
6th Edition
Authors: Tony Gaddis