Skip to content

Commit

Permalink
깜박하고 구현안한 매너 기능 및 고장난 리턴 기능 제대로 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheric0210 committed Apr 3, 2022
1 parent d55e0f6 commit a6e8519
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
Binary file modified .vs/AutoKkutu/v17/.suo
Binary file not shown.
28 changes: 18 additions & 10 deletions DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,28 @@ private static bool CheckElementOnline(string i)
return result;
}

public static List<PathFinder.PathObject> FindWord(CommonHandler.ResponsePresentedWord data, bool preferEndWord)
public static List<PathFinder.PathObject> FindWord(CommonHandler.ResponsePresentedWord data, int endWord)
{
int UseEndWord;
if (preferEndWord)
UseEndWord = 1;
else
UseEndWord = 0;
// endWord
// 0 - All except endword
// 1 - Only endword
// 2 - Don't care
int UseEndWord = endWord <= 1 ? endWord : 0;
var result = new List<PathFinder.PathObject>();
string command;
string condition;
string endWordCondition;

if (data.CanSubstitution)
command = $"SELECT * FROM word_list WHERE (word_index = '{data.Content}' OR word_index = '{data.Substitution}') AND is_endword = {UseEndWord} ORDER BY LENGTH(word) DESC LIMIT {128}";
condition = $"(word_index = '{data.Content}' OR word_index = '{data.Substitution}')";
else
condition = $"word_index = '{data.Content}'";

if (endWord == 2)
endWordCondition = ""; // Don't care about it is endword or not
else
command = $"SELECT * FROM word_list WHERE word_index = '{data.Content}' AND is_endword = {UseEndWord} ORDER BY LENGTH(word) DESC LIMIT {128}";
using (SqliteDataReader reader2 = new SqliteCommand(command, _sqlLiteConnection).ExecuteReader())
endWordCondition = $"AND is_endword = {UseEndWord}";

using (SqliteDataReader reader2 = new SqliteCommand($"SELECT * FROM word_list WHERE {condition} {endWordCondition} ORDER BY LENGTH(word) DESC LIMIT {128}", _sqlLiteConnection).ExecuteReader())
while (reader2.Read())
result.Add(new PathFinder.PathObject(reader2["word"].ToString().Trim(), Convert.ToBoolean(Convert.ToInt32(reader2["is_endword"]))));

Expand Down
File renamed without changes.
Binary file added Example Database/well-made.sqlite
Binary file not shown.
6 changes: 4 additions & 2 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@
Foreground="#FFFFFFFF"
FontSize="14"
IsChecked="False"
RenderTransformOrigin="0.482,1.656" />
RenderTransformOrigin="0.482,1.656"
Click="MannerMode_Click"/>
<Label
Content="한방 단어를 사용하지 않습니다."
FontFamily="/AutoKkutu;component/Resources/Font/#NanumBarunGothic"
Expand All @@ -219,7 +220,8 @@
Foreground="#FFFFFFFF"
FontSize="14"
IsChecked="False"
RenderTransformOrigin="0.482,1.656" />
RenderTransformOrigin="0.482,1.656"
Click="Return_Click"/>
<Label
Content="한 번 사용했던 단어를&#xD;&#xA;제외하지 않고 다시 사용합니다."
FontFamily="/AutoKkutu;component/Resources/Font/#NanumBarunGothic"
Expand Down
14 changes: 12 additions & 2 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ private void KkutuHandler_MyTurnEvent(object sender, EventArgs e)
{
var word = ((CommonHandler.MyTurnEventArgs)e).Word;
bool EndwordChecked = false;
Dispatcher.Invoke(() => EndwordChecked = PreferEndWord.IsChecked.Value);
bool DontUseEndWord = false;
Dispatcher.Invoke(() =>
{
EndwordChecked = PreferEndWord.IsChecked ?? false;
DontUseEndWord = MannerMode.IsChecked ?? false;
});
try
{
if (PathFinder.EndWordList.Contains(word.Content) && (!word.CanSubstitution || PathFinder.EndWordList.Contains(word.Substitution)))
Expand All @@ -202,7 +207,7 @@ private void KkutuHandler_MyTurnEvent(object sender, EventArgs e)
ChangeStatusBar(CurrentStatus.NoPath);
}
else
PathFinder.FindPath(word, EndwordChecked);
PathFinder.FindPath(word, DontUseEndWord, EndwordChecked);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -367,6 +372,11 @@ private void PathList_MouseDoubleClick(object sender, MouseButtonEventArgs e)

private void DBManager_Click(object sender, RoutedEventArgs e) => new DatabaseManagement().Show();

private void MannerMode_Click(object sender, RoutedEventArgs e)
{
PathFinder.Manner = MannerMode.IsChecked ?? false;
}

private void Return_Click(object sender, RoutedEventArgs e)
{
PathFinder.AllowDuplicate = Return.IsChecked ?? false;
Expand Down
27 changes: 18 additions & 9 deletions PathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PathFinder
public static EventHandler UpdatedPath;

public static bool AllowDuplicate = false;
public static bool Manner = false;
public static void Init()
{
try
Expand Down Expand Up @@ -108,7 +109,7 @@ private static List<PathObject> QualifyList(List<PathObject> input)
return result;
}

public static void FindPath(CommonHandler.ResponsePresentedWord i, bool UseEndWord)
public static void FindPath(CommonHandler.ResponsePresentedWord i, bool manner, bool preferEndWord)
{
bool canSubstitution = i.CanSubstitution;
if (canSubstitution)
Expand All @@ -124,13 +125,21 @@ public static void FindPath(CommonHandler.ResponsePresentedWord i, bool UseEndWo
var QualifiedEndList = new List<PathObject>();
try
{
NormalWord = DatabaseManager.FindWord(i, false);
ConsoleManager.Log(ConsoleManager.LogType.Info, string.Format("Find {0} Word.", NormalWord.Count), LOGIN_INSTANCE_NAME);
if (UseEndWord)
if (manner || preferEndWord)
{
ConsoleManager.Log(ConsoleManager.LogType.Info, "Endword priority enabled.", LOGIN_INSTANCE_NAME);
EndWord = DatabaseManager.FindWord(i, true);
ConsoleManager.Log(ConsoleManager.LogType.Info, string.Format("Find {0} Word.", EndWord.Count), LOGIN_INSTANCE_NAME);
NormalWord = DatabaseManager.FindWord(i, 0);
ConsoleManager.Log(ConsoleManager.LogType.Info, string.Format("Find {0} Word.", NormalWord.Count), LOGIN_INSTANCE_NAME);
if (preferEndWord)
{
ConsoleManager.Log(ConsoleManager.LogType.Info, "Endword priority enabled.", LOGIN_INSTANCE_NAME);
EndWord = DatabaseManager.FindWord(i, 1);
ConsoleManager.Log(ConsoleManager.LogType.Info, string.Format("Find {0} Word.", EndWord.Count), LOGIN_INSTANCE_NAME);
}
}
else
{
NormalWord = DatabaseManager.FindWord(i, 2);
ConsoleManager.Log(ConsoleManager.LogType.Info, string.Format("Find {0} Word.", NormalWord.Count), LOGIN_INSTANCE_NAME);
}
}
catch (Exception e)
Expand All @@ -141,7 +150,7 @@ public static void FindPath(CommonHandler.ResponsePresentedWord i, bool UseEndWo
UpdatedPath(null, new UpdatedPathEventArgs(FindResult.Error, 0, 0, 0, false));
}
QualifiedNormalList = QualifyList(NormalWord);
if (UseEndWord)
if (preferEndWord)
{
QualifiedEndList = QualifyList(EndWord);
if (QualifiedEndList.Count != 0)
Expand Down Expand Up @@ -186,7 +195,7 @@ public static void FindPath(CommonHandler.ResponsePresentedWord i, bool UseEndWo
watch.Stop();
ConsoleManager.Log(ConsoleManager.LogType.Warning, string.Format("Total {0} Path Ready. ({1}ms)", FinalList.Count, watch.ElapsedMilliseconds), LOGIN_INSTANCE_NAME);
if (UpdatedPath != null)
UpdatedPath(null, new UpdatedPathEventArgs(FindResult.Normal, NormalWord.Count, FinalList.Count, Convert.ToInt32(watch.ElapsedMilliseconds), UseEndWord));
UpdatedPath(null, new UpdatedPathEventArgs(FindResult.Normal, NormalWord.Count, FinalList.Count, Convert.ToInt32(watch.ElapsedMilliseconds), !manner));
}

public enum FindResult
Expand Down

0 comments on commit a6e8519

Please sign in to comment.