Find the longest word.
★☆☆A popular word game has sixteen six-sided dice. Each dice is unique with a single letter of the alphabet on each face. The dice are rolled and arranged in a 4x4 grid. The players try to create valid words using the dice. Any dice can be chosen as a starting letter, but subsequent letters must adjacent horizontally, vertically or diagonally to the previous dice. The object of the game is to find a valid word with the most letters.
The six faces of the sixteen dice can be seen in the dice.txt file below. It is important that the grid is stored in a 2D array for each dice position to be processed easily. The program does not need to determine who wins.
R,I,F,O,B,X
I,F,E,H,E,Y
D,E,N,O,W,S
U,T,O,K,N,D
H,M,S,R,A,O
L,U,P,E,T,S
A,C,I,T,O,A
Y,L,G,K,U,E
Qu,B,M,J,O,A
E,H,I,S,P,N
V,E,T,I,G,N
B,A,L,I,Y,T
E,Z,A,V,N,D
R,A,L,E,S,C
U,W,I,L,R,G
P,A,C,E,M,D
Write a program that reads in the faces of the sixteen dice, picks a random face from each die and outputs the letter from the face in a 4x4 grid.
Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.
shuffle_letters that:dice.txt file.show_letters that:BISN
ASCY
ASIT
NEUA
Restricted automated feedback
Automated feedback for this assignment is still under construction. Submitted programs are checked for syntax errors and their source code is checked for potential errors, bugs, stylistic issues, and suspicious constructs. However, no checks are performed yet to see if the program correctly implements the behaviour specified in the assignment.
# Word game program
# -------------------------
# Import libraries
# -------------------------
---
import random
---
# -------------------------
# Subprograms
# -------------------------
---
# Shuffle the letter grid
def shuffle_letters():
---
grid = [["" for column in range(4)] for row in range(4)]
---
# Read the letters
file = open("dice.txt", "r")
---
# Roll for each dice in a row
for row in range(4):
---
# Roll for each dice in a column
for column in range(4):
---
# Read the faces of each dice
dice = file.readline()
---
dice = dice.strip()
---
face_list = dice.split(",")
---
# Pick a random dice face
face_chosen = random.randint(0, 5)
---
letter = face_list[face_chosen]
---
# Put the dice face in the grid
grid[row][column] = letter
---
file.close()
---
return grid
---
# Show the grid of letters
def show_letters(grid):
---
# Show each row
for row in range(4):
---
# Show each column
for column in range(4):
---
print(grid[row][column], end = "")
---
print()
---
# -------------------------
# Main program
# -------------------------
---
grid = shuffle_letters()
---
show_letters(grid)