Scrabble
The Scrabble entry in Wikipedia gives the point values of each letter in the game.
[
](https://parade.com/327792/scrabble-winning-board/)Your job is to create the game of Scrabble.
This page should be broken into multiple pages once we start working on it.
Data Structures
We will use the type
command to create “aliases” - a shorthand ways of
referring to another type.
Advanced students should read about
Haskell’s
structs
and more.
-
Represent the state of the board as a list of tuples
(Char,(Int,Int))
with the first integer giving the x-coordinate of the letter and the second integer the y-coordinate.type Place = (Int,Int) type PlacedLetter = (Char,Place) type Board = [PlacedLetter]
-
A play will given by the word, its starting place, and
True
if horizontal.type Play = (String,Place,Bool)
-
A particular special letter will denote blank spaces on the board when you ask for the contents of a square:
'*'
.
Functions
-
Create variable holding the letter-valuations. You could just type everything, but instead make a list of
(String,Int)
pairs that lists the letters and then the value they have. For example, the entry("BCMP",3)
indicates that each of the letters'B'
,'C'
,'M'
and'P'
are worth 3 points. Use a space for the blank. -
Write a function
valueLetter1 :: Char -> Int
that finds the value of a single letter. It should fail with an error when asked about an unknown letter. -
Write a function
valueWord :: String -> Int
that finds the “simple” value of a word (without considering its placement on the board). -
Write a function
letterPlace :: Play -> [PlacedLetter]
that generates the list of places where the letters are played. -
The
getLetter :: Board Place -> Char
gets the letter at the given place, or'*'
if the space is empty. -
Drawing the board happens in several steps:
- Make a string for a single row using
renderRow :: Board Int -> String
. - Make a list of strings, one for each row using
renderBoard1 :: Board -> [String]
. - Join everything into one long string using
renderBoard :: Board -> String
.
- Make a string for a single row using
-
The
legalPlay1
function determines whether a singlePlacedLetter
conflicts with any letters that are already on the board. It is OK if a letter is already in the desired position, but not of a different letter is there.legalPlay1 :: Board -> PlacedLetter -> Bool
-
The
legalPlay :: Board -> [PlacedLetter] -> Bool
function determines whether the result of theletterPlace
function can legally be played (every letter should be ok to play).1 -
The
updateBoard :: Board -> [PlacedLetter] -> Board
function creates a new board that includes all of the additional letters from its second argument. -
The
usedLetters :: Board -> [PlacedLetter] -> [Char]
function gives a list of the letters actually used to make a given play. This may not be every letter in the list because some of them may already be on the board.
User Interface
Eventually, this section will contain code so you can interact with your game.
Further Work
That’s probably enough work. Continuing to make the whole game includes a lot more details:
- Create a way of denoting the double and triple letter score squares as well as the double and triple word squares.
- The
valuePlay :: Board -> [PlacedLetter] -> Int
function determines the value of a particular play on the board. Note that bonuses (double/triple letter/word score) only count for the first player to use them. - Count all of the words formed by a given play - see the “MAR” play next to “FLORIGEN” in the example at the top of the page. Four words are created by that play: “MAR”, “MI”, “AG”, and “RE”. They would all be scored. The triple word score counts for both “MAR” and “AG”.
- A dictionary of legal words?!
-
Ignore the requirement that a word connect somehow with another play on the board. That is quite challenging since the played word can form other words with letters adjacent to the play. ↩︎