I have to write a C++ program that will read the info of the game Scrabble (ie, the column letter, row number, word, and direction) and print out the score of that word.

The user input is in the following order:

<column letter> "space" <row number> "space" <word> "space" <direction>

The direction is either down (D) or across (A)

point values.
(0)--blank (denoted by '_')
(1)--A, E, I, O, U, L, N, S, T, R
(2)-- D, G
(3)--B, C, M, P
(4)--F, H,, V, W, Y
(5)--K
(8)--J,X
(10)--Q, Z

Number of tiles available.. A-9, 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... etc..

I am not asking for the code to this. I just want to know what the best way to go about this using a 2D-array. We barely learned about these arrays, and characters, so this is pretty hard for us.

I guess the first thing is, how would I set up my 2D array? My types of variables of reading in the userinput are..

 ``1234567891011121314151617`` ``````char column; int row; string word; char direction; cout << "Welcome to the Scrabble(R) Word Score Evaluator!" << endl; cout << "Enter data in the form: column row word direction" << endl; cout << " column: letter from 'A' through 'O'" << endl; cout << " row: integer from 1 through 15" << endl; cout << " word: any word - use underscore '_' for a blank tile" << endl; cout << "direction: use the letter 'A' for across or 'D' for down" << endl << endl; cout << "Enter: "; cin >> column; cin >> row; cin >> word; cin >> direction;``````

Columns are from A-0
Rows are from 1-15.

Thanks for ANY help.
Last edited on
Wow, good luck. I think this is going to be pretty complicated.

First of all, I think you'll need a 2D array to store the values of the bonuses on the board (double letter/word and triple letter/word).

You should also make a function to just return the value of a letter.

If it's supposed to be a functional game, I guess you'll need a second 2D array to actually store the placement of the tiles on the board.
Last edited on
Yeah, I'm a beginner, and I'm honestly not the best at programming, but I have to take it.

But the good thing is I don't have to print the board, all words are valid, and for each word we assume that the board is empty.

So do I need two 2D arrays (I don't think I need one to store placement of tiles)?

1) Array of the board
2) Array of the bonuses

Again, we haven't learned much about 2D array's.. Can you store two different types in a two D array? Like for the array of the board, could I use (int) row and (char) column, or is that illegal?
I guess you don't really need an array of the board then.

The index of the elements in an array (the stuff between the brackets) is always a number.
Are you sure I don't need an array of board? How am am I going to check if the word goes off the board then?
A scrabble board is 15x15 spaces.

When the user inputs a word, check the length of the word. If the word is across, and the column + word length is greater than 15, reject it. If the word is down, and the row + word length is greater than 15, reject it.
 ``123456789101112131415161718192021222324`` ``````enum CELL_TYPE { NM, /* NO MULTIPLIER */ DL, /* DOUBLE LETTER */ TL, /* TRIPLE LETER */ DW, /* DOUBLE WORD */ TW /* TRIPLE WORD */ }; /* 0 1 2 3 4 5 6 7 8 9 A B C D E */ const CELL_TYPE multiplier[BOARD_SIZE*BOARD_SIZE] = { /* 0 */ TW,NM,NM,DL,NM,NM,NM,TW,NM,NM,NM,DL,NM,NM,TW, /* 1 */ NM,DW,NM,NM,NM,TL,NM,NM,NM,TL,NM,NM,NM,DW,NM, /* 2 */ NM,NM,DW,NM,NM,NM,DL,NM,DL,NM,NM,NM,DW,NM,NM, /* 3 */ DL,NM,NM,DW,NM,NM,NM,DL,NM,NM,NM,DW,NM,NM,DL, /* 4 */ NM,NM,NM,NM,DW,NM,NM,NM,NM,NM,DW,NM,NM,NM,NM, /* 5 */ NM,TL,NM,NM,NM,TL,NM,NM,NM,TL,NM,NM,NM,TL,NM, /* 6 */ NM,NM,DL,NM,NM,NM,DL,NM,DL,NM,NM,NM,DL,NM,NM, /* 7 */ TW,NM,NM,DL,NM,NM,NM,DW,NM,NM,NM,DL,NM,NM,TW, /* 8 */ NM,NM,DL,NM,NM,NM,DL,NM,DL,NM,NM,NM,DL,NM,NM, /* 9 */ NM,TL,NM,NM,NM,TL,NM,NM,NM,TL,NM,NM,NM,TL,NM, /* A */ NM,NM,NM,NM,DW,NM,NM,NM,NM,NM,DW,NM,NM,NM,NM, /* B */ DL,NM,NM,DW,NM,NM,NM,DL,NM,NM,NM,DW,NM,NM,DL, /* C */ NM,NM,DW,NM,NM,NM,DL,NM,DL,NM,NM,NM,DW,NM,NM, /* D */ NM,DW,NM,NM,NM,TL,NM,NM,NM,TL,NM,NM,NM,DW,NM, /* E */ TW,NM,NM,DL,NM,NM,NM,TW,NM,NM,NM,DL,NM,NM,TW };``````

Remember, you can calculate a 1d index from row and column.
Thanks for your help fg109 and AbstractionAnon!
Last edited on
Also, why isn't it [BOARD_SIZE][BOARD_SIZE] instead of [BOARD_SIZE*BOARD_SIZE] since it's a 2D array?

How would I put this into a function to multiply the word?
a 2d array is in reality a 1d array with an offset. The declaration up there is perfectly valid, but when specifying your position you would need to multiply x by the width and add the row number. So let's say I wanted to find the item I array street[2][4]. The index would be:

// assuming a 5x5 grid
index = x * width + y
index = 2(5) + 4
index = 14;

The key to understanding this is to try and remeber that memory isn't Ina grid like its pictured above. It's all sequential. It's just that the grid up there is easier to look at.
Topic archived. No new replies allowed.