41305f8505f5a0127f51cbd9863f1c8e1d5c00fd
Dev Ghai Removed the contorted conce...

Dev Ghai authored 11 years ago

1) #define DEVELOPING
Dev Ghai Revert "Removing byte order...

Dev Ghai authored 11 years ago

2) 
3) using System;
4) using System.Collections.Generic;
5) using System.IO;
6) using System.Diagnostics;
7) 
8) namespace Boggle
9) {
10)     public class Boggle
11)     {
12)         static void PrintWords(HashSet<WordOnBoard> words)
13)         {
14)             int score = 0;
15)             foreach (WordOnBoard word in words)
16)             {
17)                 Console.Write("{0} [{1}], ", word.Word, word.Score);
18)                 score += word.Score;
19)             }
20)             Console.WriteLine("\n\nTotal score for this board: {0}", score);
21)         }
22)         static void Main(string[] args)
23)         {
24)             Stopwatch st = new Stopwatch();
25)             BoggleList bl = new BoggleList();
26)             Console.WriteLine("Current directory: {0}", Directory.GetCurrentDirectory());
27) #if !DEVELOPING
28)             string input;
29)             bool isError = false;
30) #endif
31)             int boardSideLength = 3;
32)             int minWordLength = 4;
33) 
34)             char wordListInput = 'Z';
Dev Ghai Removed the contorted conce...

Dev Ghai authored 11 years ago

35)             SupportedLists listToUseForLookup;
Dev Ghai Revert "Removing byte order...

Dev Ghai authored 11 years ago

36)             
37) #if !DEVELOPING
38)             do
39)             {
40)                 isError = false;
41)                 Console.WriteLine("Please enter the word list that you wish to use [Z for Zingarelli, T for TWS or standard scrabble list]: ");
42)                 input = Console.ReadLine();
43)                 if (!char.TryParse(input, out wordListInput))
44)                 {
45)                     Console.WriteLine("Invalid Input. Couldn't parse character");
46)                     isError = true;
47)                 }
48)                 wordListInput = char.ToUpper(wordListInput);
49)                 if (wordListInput != 'T' && wordListInput != 'Z')
50)                 {
51)                     Console.WriteLine("Please enter only T or Z.");
52)                     isError = true;
53)                 }
54)             } while (isError);
55) #endif
56)             switch (wordListInput)
57)             {
58)                 case 'T':
Dev Ghai Removed the contorted conce...

Dev Ghai authored 11 years ago

59)                     listToUseForLookup = SupportedLists.TWS;
Dev Ghai Revert "Removing byte order...

Dev Ghai authored 11 years ago

60)                     break;
61) 
62)                 case 'Z':
Dev Ghai Removed the contorted conce...

Dev Ghai authored 11 years ago

63)                     listToUseForLookup = SupportedLists.ZINGARELLI;
Dev Ghai Revert "Removing byte order...

Dev Ghai authored 11 years ago

64)                     break;
65)                 default:
66)                     throw new Exception("Unexpected!!");
67)             }
68) 
69) #if !DEVELOPING
70)             do
71)             {
72)                 isError = false;
73)                 Console.WriteLine("Please enter number of tiles that make up one side of the board: ");
74)                 input = Console.ReadLine();
75)                 if (!int.TryParse(input, out boardSideLength))
76)                 {
77)                     Console.WriteLine("Invalid Input.");
78)                     isError = true;
79)                 }
80)             } while (isError);
81) 
82)             do
83)             {
84)                 isError = false;
85)                 Console.WriteLine("Please enter number of ALPHABETS that should be there in shortest word: ");
86)                 input = Console.ReadLine();
87)                 if (!int.TryParse(input, out minWordLength))
88)                 {
89)                     Console.WriteLine("Invalid Input.");
90)                     isError = true;
91)                 }
92)             } while (isError);
93) #endif
94)             st.Start();
95)             bl.LoadList(listToUseForLookup, boardSideLength, minWordLength, Directory.GetCurrentDirectory());
96)             st.Stop();
97)             Console.WriteLine("Loaded list in {0} ms.", st.ElapsedMilliseconds);
98) 
99)             string boardString = "qwertyuio";
100) #if !DEVELOPING
101)             do
102)             {
103)                 isError = false;
104)                 Console.WriteLine("Please enter the characters on board in row first fashion ({0} expected characters): ", boardSideLength*boardSideLength);
105)                 boardString = Console.ReadLine();
106)                 if (boardString.Length != boardSideLength*boardSideLength)
107)                 {
108)                     Console.WriteLine("Invalid Input. Q will be translated to QU internally. Please enter only Q if you want to enter the QU tile.");
109)                     isError = true;
110)                 }
111)             } while (isError);
112) #endif
113)             boardString = boardString.ToUpper();
114) 
115)             BoggleBoard board = new BoggleBoard(boardSideLength, boardString);
116)             board.Print();
Dev Ghai Re-enabled code to run in b...

Dev Ghai authored 11 years ago

117)             BoggleSolver solver = new BoggleSolver(board, bl, minWordLength);
118)             st.Reset();
119)             st.Start();
120)             HashSet<WordOnBoard> wordsUnThreaded = solver.GetWordsOnBoard(false);
121)             st.Stop();
122)             PrintWords(wordsUnThreaded);
123) 
124)             Console.WriteLine("Got solution in {0} ms. Number of words (UNTHREADED): {1}\n\n", st.ElapsedMilliseconds, wordsUnThreaded.Count);
125)             st.Reset();
Dev Ghai Revert "Removing byte order...

Dev Ghai authored 11 years ago

126)             st.Start();
Dev Ghai Re-enabled code to run in b...

Dev Ghai authored 11 years ago

127)             HashSet<WordOnBoard> wordsThreaded = solver.GetWordsOnBoard(true);
Dev Ghai Revert "Removing byte order...

Dev Ghai authored 11 years ago

128)             st.Stop();
Dev Ghai Re-enabled code to run in b...

Dev Ghai authored 11 years ago

129)             st.Reset();
Dev Ghai Revert "Removing byte order...

Dev Ghai authored 11 years ago

130)             PrintWords(wordsThreaded);
Dev Ghai Re-enabled code to run in b...

Dev Ghai authored 11 years ago

131)             Console.WriteLine("\nGot solution in {0} ms. Number of words (THREADED): {1}.", st.ElapsedMilliseconds, wordsThreaded.Count);
132) 
133)             Console.WriteLine("Time for sanity checks... comparing solutions from threaded and non-threaded mode.");
134)             if (wordsThreaded.Count == wordsUnThreaded.Count)
135)             {
136)                 Console.WriteLine("\nALL GOOD!");
137)             }
138)             if (wordsUnThreaded.Count > wordsThreaded.Count)
139)             {
140)                 wordsUnThreaded.ExceptWith(wordsThreaded);
141)                 Console.WriteLine("Words in unthreaded collection that are not in threaded collection:");
142)                 PrintWords(wordsUnThreaded);
143)             }
144)             if (wordsThreaded.Count > wordsUnThreaded.Count)
145)             {
146)                 wordsThreaded.ExceptWith(wordsUnThreaded);
147)                 Console.WriteLine("Words in threaded collection that are not in unthreaded collection:");
148)                 PrintWords(wordsThreaded);
149)             }
150) 
151)             Console.WriteLine("\nPress any key to exit.");