I'm currently writing a scrabble-like game in C#. I can get the computer to find the highest point开发者_Go百科 value word that can be made using the current rack, however I have no idea how to check if that word is "Placeable" on the 15*15 Gameboard(2D Array: string[,]).
In it's default state(with no Letters on the board) all elements are set to 0.
Is allowed
---------------
-------H-------
-------E-------
-----FILL------
-------L-------
-------O-------
---------------
How can I check if the word is not For example:
Is Not Allowed
---------------
-H-------------
-E-------------
FILL------------ <-- F is out of bounds
-L-------------
-O-------------
---------------
Is Not Allowed
---------------
-H-------------
-E-W-----------
-L-O-----------
-L-R-----------
FOLL----------- <-- Fill is overlapping with O
---D-----------
The paper, "The worlds fastest Scrabble engine" (PDF), is from 1988 and describes an efficient Scrabble engine. It's short and surprisingly readable!
I learned how to do this based on the F# SharpScrabble project. Even if you don't know F# (like me), you'll get a feel for how the author decided to do this.
The big things to me were:
- Using a
Coordinate
system to findTiles
- Populating the
Board
withSquares
that can hold a tile (letter) but also hold score information Tile
represents a letter, both in the player's letter bank and also on the boardMove
that represents a player's placement of letters- Implementing the
IComparable
on coordinates and tiles to make sorting easier - Computing
Runs
which represent the words a move would place, to compute score
Overall, a really good primer on beginning to wrap your head around a Scrabble engine. I was able to port much of that code into C# without knowing F# a lick, so it shouldn't be terrible for anyone else.
精彩评论