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
Q,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
// Word game program
using System;
using System.IO;
using System.Collections.Generic;
class Submission
{
---
// -------------------------
// Globals
// -------------------------
---
static Random random_generator = new Random();
---
// -------------------------
// Subprograms
// -------------------------
// Shuffle the letter grid
---
static string[,] shuffle_letters()
{
---
string[,] grid = new string[4, 4];
// Read the letters
StreamReader file = new StreamReader("dice.txt");
---
// Roll for each dice in a row
for (int row = 0; row < 4; row++)
{
---
// Roll for each dice in a column
for (int column = 0; column < 4; column++)
{
---
// Read the faces of each dice
string dice = file.ReadLine().Trim();
string[] face_list = dice.Split(',');
// Pick a random dice face
int face_chosen = random_generator.Next(0, 6);
string 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
static void show_letters(string[,] grid)
{
---
// Show each row
for (int row = 0; row < 4; row++)
{
---
// Show each column
for (int column = 0; column < 4; column++)
{
---
Console.Write(grid[row, column]);
---
}
---
Console.WriteLine();
---
}
---
}
---
// -------------------------
// Main program
// -------------------------
public static void Main(string[] args)
{
---
string[,] grid = shuffle_letters();
show_letters(grid);
---
}
---
}