J
Josue
Background:
I am writing a word game in which you have a 4*4 grid of random letter,
and you find words within the grid using adjacent letters. I'm using
this project to help learn the .net cf as well as sqlce, but at the same
time, I'd like the game to start quickly.
Problem:
After I've created the game grid, I have to figure out all the available
words in the grid. I have two functions (see below), one to check if
the current string is the start of a word, and another function to check
if the current string is a word. On my test grid, IsWord is called 272,
StartWord is called 1435. The game takes 1 minute and 45 seconds to
find all of the possible words. I was hoping to tap into someone's
expertise in these forums, and see if I could tweak these functions to
be leaner and meaner. The database the wordlist is on is 26 tables (one
for each letter), with one column Primary Key column which is the word.
Other info:
I'm testing this application on an iPaq 3850 Pocket PC 2002 device.
..net cf 1.1 sp1. The database is over 15,000 words.
***IsWord Function***
Private Function IsWord(ByVal strWordToCheck As String) As Boolean
Try
Dim strSql As String = "SELECT word FROM word_" & _
Mid(strWordToCheck, 1, 1) & " WHERE word = '" & _
strWordToCheck & "'"
Dim strStuff As String
cmd.CommandText = strSql 'cmd is a module level object
strStuff = cmd.ExecuteScalar
If strStuff Is Nothing Then
Return False
Else
Return True
End If
Catch ex As SqlCeException
MessageBox.Show(ex.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
***StartWord***
Private Function StartWord(ByVal strWordToCheck As String) As Boolean
If (strWordToCheck.Length > 1) Then
Try
Dim strStuff As String
Dim strSql As String = "SELECT word FROM word_" & _
Mid(strWordToCheck, 1, 1) & " WHERE word LIKE '" & _
strWordToCheck & "%'"
intStartWord = intStartWord + 1
cmd.CommandText = strSql
cmd.CommandType = CommandType.Text
strStuff = cmd.ExecuteScalar
If strStuff Is Nothing Then
Return False
Else
Return True
End If
Catch ex As SqlCeException
MessageBox.Show(ex.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
Return True
End If
End Function
I know it's an involving question, but if anyone has any tips to share,
I would be all ears.
I am writing a word game in which you have a 4*4 grid of random letter,
and you find words within the grid using adjacent letters. I'm using
this project to help learn the .net cf as well as sqlce, but at the same
time, I'd like the game to start quickly.
Problem:
After I've created the game grid, I have to figure out all the available
words in the grid. I have two functions (see below), one to check if
the current string is the start of a word, and another function to check
if the current string is a word. On my test grid, IsWord is called 272,
StartWord is called 1435. The game takes 1 minute and 45 seconds to
find all of the possible words. I was hoping to tap into someone's
expertise in these forums, and see if I could tweak these functions to
be leaner and meaner. The database the wordlist is on is 26 tables (one
for each letter), with one column Primary Key column which is the word.
Other info:
I'm testing this application on an iPaq 3850 Pocket PC 2002 device.
..net cf 1.1 sp1. The database is over 15,000 words.
***IsWord Function***
Private Function IsWord(ByVal strWordToCheck As String) As Boolean
Try
Dim strSql As String = "SELECT word FROM word_" & _
Mid(strWordToCheck, 1, 1) & " WHERE word = '" & _
strWordToCheck & "'"
Dim strStuff As String
cmd.CommandText = strSql 'cmd is a module level object
strStuff = cmd.ExecuteScalar
If strStuff Is Nothing Then
Return False
Else
Return True
End If
Catch ex As SqlCeException
MessageBox.Show(ex.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
***StartWord***
Private Function StartWord(ByVal strWordToCheck As String) As Boolean
If (strWordToCheck.Length > 1) Then
Try
Dim strStuff As String
Dim strSql As String = "SELECT word FROM word_" & _
Mid(strWordToCheck, 1, 1) & " WHERE word LIKE '" & _
strWordToCheck & "%'"
intStartWord = intStartWord + 1
cmd.CommandText = strSql
cmd.CommandType = CommandType.Text
strStuff = cmd.ExecuteScalar
If strStuff Is Nothing Then
Return False
Else
Return True
End If
Catch ex As SqlCeException
MessageBox.Show(ex.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
Return True
End If
End Function
I know it's an involving question, but if anyone has any tips to share,
I would be all ears.