Scrabble, puting chars into a 2d array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Scrabble, puting chars into a 2d array

  1. #1
    Join Date
    Aug 2004
    Posts
    17

    Scrabble, puting chars into a 2d array

    OK im making a game of scrabble in java for Computer Science.

    The thing I can't work out, is how when given a string for a word and its direction (horizontal, vertical) can I check whether it goes there ( 1 char per cell-thingo without leaving the 15x15 array, and whether it will be allowed, must have a common letter with a word already placed (unless first word).

    This is important so I can implement the scoring method.

    Thanks in advance

    llama009

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    int[] grid = new grid[15][15];

    I assume the user is putting the pieces in the grid 1 letter at a time.

    using the piece's coordinates as index numbers, plug it in the array. The array could hold "0" for an empty spot and "1" for an already occupied spot. Then you can check for combinations of letters around it. This would probably be a recursive method.
    For instance, lets say the word "dog" takes up spots (1,1), (1,2),(1,3). Now the user puts in an "s" at (x,y), where x=1 and y=4. Now check surrounding tiles. Eventually, it'll see there's a letter at (1,y-1), the "g". Have it continue searching for letters in that direction, the Y-direction. Eventually, it'll either find a blank spot, or in this case hit the edge of the board. So now you have letters from (1,1) to (1,4). Combine the 4 letters into a String and check the word against known words in your dictionary. The dictionary is needed to make sure the words exists in the language. Using a binary search, you can make this check perform relatively quickly.

  3. #3
    Join Date
    Aug 2004
    Posts
    17
    thanks, never thought about it that way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center