|
So I play Ruzzle (like Boggle), its kind of fun. As a joke for one of my friends I developed an application to give me the list of longest playable words on the board, down and dirty. Originally, I wanted to do it right, and generic, but alas, I didn't want to spend a lot of time on a joke so I hard-coded the graph. At first it felt dirty and wrong, but then it felt, right?
Here was my approach (warning, code, avert your eyes ye lounge is for no code onliers. Oh, and DD, this isn't a trubechet) This is not presented for critique or questions, merely to illustrate how the hard-code actually worked well enough.
First create an object to hold a letter
public class Node{
public string letter;
public List<Node> nodes;
}
Now take a pen and paper, and number the grid starting left to right, top to bottom, zero through 16 (like an array). Then make a list of 16 elements:
foreach(string letter in lettersInOrder){
allNodes.Add(new Node(letter));
}
Now hard-code the graph:
allNodes[0].Nodes.Add(allNodes[1]);
allNodes[0].Nodes.Add(allNodes[4]);
allNodes[0].Nodes.Add(allNodes[5]);
...
I was surprised at how simple it was, all these years avoiding hard-coding and I just hard-coded a 4x4 grid! Laugh. Also, to keep this post mildly apropos I will not post the traversal code : )
|
|
|
|
|
Now, you make dam funny jokes. I can't wait to see you on stage.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb
|
|
|
|
|
Writing a game that cheats is much more difficult than writing a fair game.
|
|
|
|
|
It might feel good now, but when your friends starts to ask for new features on your joke you're going to have a hard time...
Love the "All users always want Excel" signature by the way. That is so true
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}
|
|
|
|
|
I did something similar for a rules based engine (Drool) to solve Sudoku problems.
I was trying to model the way I like to solve sudoku vs. brute force depth search.
Each number square was "hardcoded" into row, column, and 3x3 square containers.
I stopped working on it when I realized I needed to add more levels of nesting for some tricks I perform with triples and pairs of triples referenced across squares, rows, and columns.
It could solve most 1 star games without trouble and emit a very nice explanation of the squares and the techniques that were used at each step.
There is probably some way to model this idea with an n-dimensional space, but it was starting to look like work instead of play.
I just googled "sudoku tesseract" and found a few discussions that really get into this. I know there was an open source sudoku solver in java that worked very well.
|
|
|
|
|
Hard coding makes sense 99% of the time, if you don't hard code that much, you're doing something terribly wrong...
|
|
|
|