Player's input in Scrabble?

This is a discussion on Player's input in Scrabble? within the C Programming forums, part of the General Programming Boards category; Argh.. this is getting frustrated. I fix one problem, another one appears. I am now having trouble on how to ...

Player's input in Scrabble?

Argh.. this is getting frustrated. I fix one problem, another one appears. I am now having trouble on how to take in the user's input in a game of Scrabble. Consider the first player already went, and placed down his word:

Code:

R A I D

This word was entered by asking the user for a proper location and the FULL WORD that he wants to make.

Now the next player's turn.

How should I get his input? If I get in terms of location and letters, I can make a new word like this

Code:

R A I D S

(just adding the letter S at location (0,4) for this case)

or like this with location of (1,1)

Code:

R A I D
S

But what if the user wants a word like this:

Code:

D
R A I D
D

then you are not just adding letters to preexisiting words but also adding letter(s) before and after. I looked into entering the whole word and the location but that won't work, if you want to make multiple words using your letters.

I hope you guys understand what I am trying to say. Plz ask for any clarification as required.

Just have them add a letter at a time. If the letters are not in a row, or not in a column, then they're invalid placement. IE:
1) 5,5
2) 5,6 (valid)
3) 5,8 (valid)
4) 6,9 (invalid)

Then once they're done placing valid entries, and do whatever it is that you have be "Ok I'm done.", then you go through the rows and columns surrounding their letters to make sure every letter they place is part of a valid word, and that nothing makes an invalid word.

There is a Scrabble game on my Sharp Zaurus (PDA running linux). To enter words with this, first you arrange the tiles on your rack into the order they will be laid (by dragging), then the letters are "painted" onto the board with the stylus. If you're going to have a graphical interface, this might be worth looking at.

I suspect WaltP and quzah are right tho, sometimes a change of perspective can make code fall into place more neatly.

It's an interesting problem tho (well I think so). I'll see if I can think of something !

Re: Scanning all directions?

Originally posted by vex_helix I like yr idea Quzah regarding entering one at a time. But how do I check all directions for words?

Consider initial words:

Code:

B
G E T
O

And I make both NOT AND BET

Code:

B
G E T
N O T

Since 'T' was the last character typed, I only use 'T' to scan up,down,right,left to find words?

Then don't "only use 'T'." You must use all tiles played. Keep track of the positions played and go back thru them to test for additional words in the 'other' direction.

This may make my suggestion better because with quzah's code, you not only have to enter every single letter being placed, but you have to analyze the placement to figure out the direction. In my solution, you already know the direction.

Originally posted by vex_helix What about this scenario:

Code:

G O T

and I make three words ON, NO, TO respectively:

Code:

G O T
N O

In this case I gotta check all directions for both 'N' and 'O'.

Isn't there just one simple way to scan for words for all direction? Also, do I scan as I enter words?