first commit

This commit is contained in:
UndeadMaelys 2021-05-24 13:13:48 +02:00
commit 8578d2fe78
4 changed files with 680 additions and 0 deletions

0
README.md Normal file
View File

68
helper_functions.lua Normal file
View File

@ -0,0 +1,68 @@
-- enum helper
function Enum(tbl)
for i = 1, #tbl do
local v = tbl[i]
tbl[v] = i
end
return tbl
end
-- doesnt work
function GetTerminalSize()
io.write("\027[s")
io.write("\027[9999;B")
io.write("\027[9999;C")
--io.write("\027[6n")
io.write("\027[u")
end
COLORMODE = Enum {
"Normal",
"Bold",
"Dim",
"Italic",
"Underline",
"BlinkSlow",
"BlinkFast",
"Invert",
"Conceal",
"CrossedOut"
}
COLOR = Enum {
"Black",
"Red",
"Green",
"Yellow",
"Blue",
"Purple",
"Cyan",
"LightGray",
"Gray",
"HighRed",
"HighGreen",
"HighYellow",
"HighBlue",
"HighPurple",
"HighCyan",
"White"
}
function Colorize(Text,Color,Background,Colormode)
if Colormode then
lColormode = "\027["..tostring(Colormode-1).."m"
else
lColormode = ""
end
if Background then
lBackground = "\027[48;5;"..tostring(Background-1).."m"
else
lBackground = ""
end
lColoredText = "\027[38;5;"..tostring(Color-1).."m"..Text
return lColormode..lBackground..lColoredText.."\027[0;m"
end

477
kanji_data.lua Normal file
View File

@ -0,0 +1,477 @@
KanjiData = {
-- FIRST GRADE ELEMENTARY KANJIS
{
Symbol = "",
Meaning = "One",
On = {"イチ","イツ"},
Kun = {"ひと"}
},
{
Symbol = "",
Meaning = "Right",
On = {"","ユウ"},
Kun = {"みぎ"}
},
{
Symbol = "",
Meaning = "Rain",
On = {"エン"},
Kun = {"まる","まる(い)","つぶ(ら)","まろ(やか)"}
},
{
Symbol = "",
Meaning = "King",
On = {"オウ"},
Kun = {}
},
{
Symbol = "",
Meaning = "Sound",
On = {"オン","イン"},
Kun = {"おと",""}
},
{
Symbol = "",
Meaning = "Down",
On = {"",""},
Kun = {"した","しも","もと","くだ(る・さる)","さ(がる)","お(りる)"}
},
{
Symbol = "",
Meaning = "Fire",
On = {""},
Kun = {"",""}
},
{
Symbol = "",
Meaning = "Flower",
On = {""},
Kun = {"はな"}
},
{
Symbol = "",
Meaning = "Learn",
On = {"ガク"},
Kun = {"まな(ぶ)"}
},
{
Symbol = "",
Meaning = "Spirit",
On = {"",""},
Kun = {}
} ,
{
Symbol = "",
Meaning = "Nine",
On = {"キュウ",""},
Kun = {"ここの(つ)"}
},
{
Symbol = "",
Meaning = "Rest",
On = {"キュウ"},
Kun = {"やす(む)"}
},
{
Symbol = "",
Meaning = "Gold, Money",
On = {"キン","コン"},
Kun = {"かね","かな-"}
},
{
Symbol = "",
Meaning = "Sky, Empty",
On = {"クウ"},
Kun = {"そら","から","あ(く)","むな(しい)","す(く)","うつ(ろ)","あだ"}
},
{
Symbol = "",
Meaning = "Moon, Month",
On = {"ゲツ","ガツ"},
Kun = {"つき"}
},
{
Symbol = "",
Meaning = "Dog",
On = {"ケン"},
Kun = {"いぬ"}
},
{
Symbol = "",
Meaning = "See",
On = {"ケン"},
Kun = {"み(る・せる・える)"}
},
{
Symbol = "",
Meaning = "Five",
On = {""},
Kun = {"いつ(つ)"}
},
{
Symbol = "",
Meaning = "Mouth",
On = {"コウ",""},
Kun = {"くち"}
},
{
Symbol = "",
Meaning = "School",
On = {"コウ"},
Kun = {}
},
{
Symbol = "",
Meaning = "Left",
On = {""},
Kun = {"ひだり"}
},
{
Symbol = "",
Meaning = "Three",
On = {"サン"},
Kun = {"み(つ)","みっ(つ)"}
},
{
Symbol = "",
Meaning = "Mountain",
On = {"サン","ザン"},
Kun = {"やま"}
},
{
Symbol = "",
Meaning = "Child",
On = {"",""},
Kun = {"",""}
},
{
Symbol = "",
Meaning = "Four",
On = {""},
Kun = {"よん","よ(つ)","よっ(つ)"}
},
{
Symbol = "",
Meaning = "Thread",
On = {""},
Kun = {"いと"}
},
{
Symbol = "",
Meaning = "Letter",
On = {""},
Kun = {"あざ"}
},
{
Symbol = "",
Meaning = "Ear",
On = {""},
Kun = {"みみ"}
},
{
Symbol = "",
Meaning = "Seven",
On = {"シチ"},
Kun = {"なな"}
},
{
Symbol = "",
Meaning = "Vehicle",
On = {"シャ"},
Kun = {"くるま"}
},
{
Symbol = "",
Meaning = "Hand",
On = {"シュ"},
Kun = {""}
},
{
Symbol = "",
Meaning = "Ten",
On = {"ジュウ"},
Kun = {"とお"}
},
{
Symbol = "",
Meaning = "Woman",
On = {"ジョ","ニョウ","ニョ"},
Kun = {"おんな",""}
},
{
Symbol = "",
Meaning = "Small",
On = {"ショウ"},
Kun = {"こ-","お-","ちいさ(い)"}
},
{
Symbol = "",
Meaning = "Up",
On = {"ジョウ"},
Kun = {"うえ","うわ-","かみ","のぼ(る)","あ(がる・げる)"}
},
{
Symbol = "",
Meaning = "Woods",
On = {"シン"},
Kun = {"もり"}
},
{
Symbol = "",
Meaning = "Person",
On = {"ジン","ニン"},
Kun = {"ひと"}
},
{
Symbol = "",
Meaning = "Water",
On = {"スイ"},
Kun = {"みず"}
},
{
Symbol = "",
Meaning = "Correct",
On = {"セイ","ショウ"},
Kun = {"まさ","ただ(しい・す)"}
},
{
Symbol = "",
Meaning = "Life",
On = {"セイ","ショウ"},
Kun = {"なま","い(きる)","う(む)","は(える)","","","む(す)","お-"}
},
{
Symbol = "",
Meaning = "Blue",
On = {"セイ","ショウ"},
Kun = {"あお"}
},
{
Symbol = "",
Meaning = "Evening",
On = {"セキ"},
Kun = {"ゆう"}
},
{
Symbol = "",
Meaning = "Stone",
On = {"セキ","シャク","コク"},
Kun = {"いし"}
},
{
Symbol = "",
Meaning = "Red",
On = {"セキ","シャク"},
Kun = {"あか"}
},
{
Symbol = "",
Meaning = "Thousand",
On = {"セン"},
Kun = {""}
},
{
Symbol = "",
Meaning = "River",
On = {"セン"},
Kun = {"かわ"}
},
{
Symbol = "",
Meaning = "Previous, Tip",
On = {"セン"},
Kun = {"さき"}
},
{
Symbol = "",
Meaning = "Early, Fast",
On = {"ソウ","サッ"},
Kun = {"はや(い)"}
},
{
Symbol = "",
Meaning = "Leg, Sufficient",
On = {"ソク"},
Kun = {"あし","た(りる)"}
},
{
Symbol = "",
Meaning = "Village",
On = {"ソン"},
Kun = {"むら"}
},
{
Symbol = "",
Meaning = "Large",
On = {"ダイ","タイ"},
Kun = {"おお(きい)"}
},
{
Symbol = "",
Meaning = "Man",
On = {"ダン","ナン"},
Kun = {"おとこ"}
},
{
Symbol = "",
Meaning = "Middle",
On = {"チュウ"},
Kun = {"なか","あ(てる)"}
},
{
Symbol = "",
Meaning = "Bug",
On = {"チュウ"},
Kun = {"むし"}
},
{
Symbol = "",
Meaning = "Town",
On = {"チョウ"},
Kun = {"まち"}
},
{
Symbol = "",
Meaning = "Heaven",
On = {"テン"},
Kun = {"あま-"}
},
{
Symbol = "",
Meaning = "Rice Field",
On = {"デン"},
Kun = {""}
},
{
Symbol = "",
Meaning = "Earth",
On = {"",""},
Kun = {"つち"}
},
{
Symbol = "",
Meaning = "Two",
On = {""},
Kun = {"ふた(つ)"}
},
{
Symbol = "",
Meaning = "Sun, Day",
On = {"ニチ","ジツ"},
Kun = {"","-か"}
},
{
Symbol = "",
Meaning = "Enter",
On = {"ニュウ"},
Kun = {"はい(る)","い(れる・る)"}
},
{
Symbol = "",
Meaning = "Year",
On = {"ネン"},
Kun = {"とし"}
},
{
Symbol = "",
Meaning = "White",
On = {"ハク"},
Kun = {"しろ"}
},
{
Symbol = "",
Meaning = "Eight",
On = {"ハチ"},
Kun = {"や(つ)","やっ(つ)"}
},
{
Symbol = "",
Meaning = "Hundred",
On = {"ヒャク"},
Kun = {"もも"}
},
{
Symbol = "",
Meaning = "Text",
On = {"ブン","モン"},
Kun = {"ふみ","あや"}
},
{
Symbol = "",
Meaning = "Tree",
On = {"ボク","モク"},
Kun = {"","こ-"}
},
{
Symbol = "",
Meaning = "Book",
On = {"ホン"},
Kun = {"もと"}
},
{
Symbol = "",
Meaning = "Exit, Emerge",
On = {"シュツ"},
Kun = {"で(る)","だ(す)"}
},
{
Symbol = "",
Meaning = "Name",
On = {"メイ","ミョウ"},
Kun = {""}
},
{
Symbol = "",
Meaning = "Eye",
On = {"モク","ボク"},
Kun = {"","ま-"}
},
{
Symbol = "",
Meaning = "Stand",
On = {"リツ","リュウ"},
Kun = {"た(つ)"}
},
{
Symbol = "",
Meaning = "Strength",
On = {"リョク","リキ"},
Kun = {"ちから","りき(む)","つと(める"}
},
{
Symbol = "",
Meaning = "Forest",
On = {"リン"},
Kun = {"はやし"}
},
{
Symbol = "",
Meaning = "Six",
On = {"ロク"},
Kun = {"む(つ)","むっ(つ)"}
},
{
Symbol = "",
Meaning = "Grass",
On = {"ソウ"},
Kun = {"くさ"}
},
{
Symbol = "",
Meaning = "Ball",
On = {"ギョク"},
Kun = {"たま"}
},
{
Symbol = "",
Meaning = "Bamboo",
On = {"チク"},
Kun = {"たけ"}
},
{
Symbol = "",
Meaning = "Seashell",
On = {"バイ"},
Kun = {"かい"}
}
}

135
kanji_learner.lua Normal file
View File

@ -0,0 +1,135 @@
require "kanji_data"
require "helper_functions"
function GetUnrepeatedKanji(lAvoid)
lKanji = KanjiData[math.random(#KanjiData)]
for i=1, #lAvoid do
if lKanji == lAvoid[i] then
lKanji = GetUnrepeatedKanji(lAvoid)
break
end
end
return lKanji
end
function AskMeaning()
io.write(Colorize("Q: ",COLOR.HighBlue).."What does "..CurrentKanji.Symbol.." mean? \n")
io.write("\n")
for i=1, 4 do
if i == Solution then
io.write(Colorize(" ("..i..") ",COLOR.HighYellow)..CurrentKanji.Meaning)
io.write("\n")
else
lRandomKanji = GetUnrepeatedKanji(AvoidList)
table.insert(AvoidList,lRandomKanji)
io.write(Colorize(" ("..i..") ",COLOR.HighYellow)..lRandomKanji.Meaning)
io.write("\n")
end
end
end
function AskKanji()
io.write(Colorize("Q: ",COLOR.HighBlue).."Which is the kanji for \""..CurrentKanji.Meaning.."\"? \n")
io.write("\n")
for i=1, 4 do
if i == Solution then
io.write(Colorize(" ("..i..") ",COLOR.HighYellow)..CurrentKanji.Symbol)
io.write("\n")
else
lRandomKanji = GetUnrepeatedKanji(AvoidList)
table.insert(AvoidList,lRandomKanji)
io.write(Colorize(" ("..i..") ",COLOR.HighYellow)..lRandomKanji.Symbol)
io.write("\n")
end
end
end
function Ask(Type)
Solution = math.random(4)
AvoidList = {}
table.insert(AvoidList,CurrentKanji)
if Type == QuestionType.KANJI then
AskKanji()
elseif Type == QuestionType.MEANING then
AskMeaning()
end
io.write("\n")
io.write(Colorize("A: ",COLOR.HighPurple))
end
function Check(answer)
if answer == "" then
io.write("\027[1F".."\027[3C")
Check(io.read())
else
io.write("\n")
if answer == tostring(Solution) then
io.write(Colorize("Correct!",COLOR.HighGreen))
io.write(Colorize(" [Streak +1]",COLOR.HighCyan,nil,COLORMODE.BlinkFast))
Streak = Streak + 1
Correct = Correct + 1
else
io.write(Colorize("Wrong!",COLOR.HighRed).." Answer is ("..Solution..")")
if Streak >= 5 then io.write(Colorize(" [Streak Lost]",COLOR.Cyan,nil,COLORMODE.BlinkFast)) end
Streak = 0
Wrong = Wrong + 1
end
UpdateProgress()
io.write("\n")
io.read()
end
Total = Total + 1
end
QuestionType = Enum {
"KANJI",
"MEANING",
"ON",
"KUN"
}
function ShowProgress()
io.write("#"..tostring(Total+1).."\t")
io.write("Right: "..Colorize(tostring(Correct),COLOR.HighGreen).."\t")
io.write("Wrong: "..Colorize(tostring(Wrong),COLOR.HighRed).."\t")
if Streak >= 5 then
io.write(Colorize("CURRENT STREAK: ", COLOR.HighCyan,nil,COLORMODE.BlinkFast)..Colorize(Streak,COLOR.White,nil,COLORMODE.BlinkFast))
end
io.write("\n\n")
end
function UpdateProgress()
io.write("\027[s")
io.write("\027[1;1H")
ShowProgress(true)
io.write("\027[u")
end
Correct = 0
Total = 0
Streak = 0
Wrong = 0
while 1 do
os.execute("clear")
CurrentKanji = KanjiData[math.random(#KanjiData)]
ShowProgress()
--Ask(math.random(#QuestionType))
Ask(math.random(2))
--Ask(QuestionType.KANJI)
response = io.read()
Check(response)
end