Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Brain Damage Algorithm BDA for short
- Emulates drunk or brain damaged persons speech patterns
- Devloped By BigSHinyToys
- http://www.computercraft.info/forums2/index.php?/topic/3546-fun-ai-learning-program-that-can-talk/
- BUILD 4 with aoto learn
- ]]--
- local winX,winY = term.getSize()
- local length = 8
- local tDictionary = {}
- local shado = {}
- local tArgs = {...}
- local savefile = "words"
- local convofile = "convo"
- local function saveTalk(sentence)
- local f = fs.open(convofile, "a")
- f.write(sentence.."\n")
- f.close()
- end
- local function save()
- local f = fs.open(savefile, "w")
- f.write(textutils.serialize({tDictionary, shado}))
- f.close()
- end
- if fs.exists(savefile) then
- local f = fs.open(savefile, "r")
- local save = textutils.unserialize(f.readAll())
- f.close()
- tDictionary = save[1]
- shado = save[2]
- end
- local function addThis(sLine)
- local posX,posY = term.getCursorPos()
- local scrX,scrY = term.getSize()
- posX = 1
- local tWords = {}
- for match in string.gmatch(sLine, "[^ \t]+") do
- table.insert( tWords, match )
- end
- for i = 1,#tWords do
- --sleep(0.01)
- if tDictionary[tWords[i]] then
- table.insert(tDictionary[tWords[i]]["to"],tWords[i])
- else
- table.insert(shado,tWords[i])
- tDictionary[tWords[i]] = {}
- tDictionary[tWords[i]]["name"] = tWords[i]
- tDictionary[tWords[i]]["to"] = {}
- end
- term.setCursorPos(posX,posY)
- write(string.rep("=",math.floor((i/#tWords)*(scrX-1))))
- term.setCursorPos(scrX/2,posY)
- write(tostring(math.floor((i/#tWords)*100)).." %")
- end
- end
- if tArgs[1] ~= nil and fs.exists(tArgs[1]) and fs.isDir(tArgs[1]) then
- print("Folder Found")
- local tFiles = fs.list(tArgs[1])
- print(tostring(#tFiles).." "..type(tFiles))
- local posX,posY = term.getCursorPos()
- local scrX,scrY = term.getSize()
- posX = 1
- for i = 1,#tFiles do
- term.setCursorPos(posX,posY)
- write(string.rep("=",math.floor((i/#tFiles)*(scrX-1))))
- term.setCursorPos(scrX/2,posY)
- write(tostring(math.floor((i/#tFiles)*100)).." %")
- print(" ")
- sleep(0.01)
- if not fs.isDir(tArgs[1]..[[\]]..tFiles[i]) then
- local file = fs.open(tArgs[1]..[[\]]..tFiles[i],"r")
- if file then
- local data = file:readAll()
- file:close()
- addThis(data)
- else
- print("error")
- end
- end
- end
- save()
- elseif tArgs[1] ~= nil then
- print(tostring(tArgs[1]).." is not a Folder")
- os.pullEvent("key")
- end
- local function dataAI()
- local lastTimer = os.startTimer(math.random(1,120))
- while true do
- local event,arg1,arg2,arg3 = os.pullEvent()
- if event == "new_line" or event == "timer" then
- if event == "timer" then
- if arg1 == lastTimer then
- lastTimer = os.startTimer(math.random(1,120))
- end
- arg1 = ""
- end
- local sLine = arg1
- local tWords = {}
- for match in string.gmatch(sLine, "[^ \t]+") do
- table.insert( tWords, match )
- end
- for i = 1,#tWords do
- if tDictionary[tWords[i]] then
- table.insert(tDictionary[tWords[i]]["to"],tWords[i])
- else
- table.insert(shado,tWords[i])
- tDictionary[tWords[i]] = {}
- tDictionary[tWords[i]]["name"] = tWords[i]
- tDictionary[tWords[i]]["to"] = {}
- end
- end
- local test = ""
- local last = nil
- for i = 1,math.random(1,length) do
- if last then
- if #tDictionary[last]["to"] and #tDictionary[last]["to"] > 0 then
- sNext = tDictionary[last]["to"][math.random(1,#tDictionary[last]["to"])]
- if sNext ~= last then
- test = test..sNext.." "
- last = sNext
- else
- last = tDictionary[shado[math.random(1,#shado)]]["name"]
- test = test..last.." "
- end
- else
- last = tDictionary[shado[math.random(1,#shado)]]["name"]
- test = test..last.." "
- end
- else
- last = tDictionary[shado[math.random(1,#shado)]]["name"]
- test = test..last.." "
- end
- end
- term.scroll(1)
- term.setCursorPos(1,winY - 1)
- term.clearLine()
- if arg1 ~= "" then
- save()
- end
- saveTalk("AI> "..test)
- print("AI> "..test)
- end
- end
- end
- local function userInput()
- while true do
- term.setCursorPos(1,winY)
- term.clearLine()
- local input = read()
- saveTalk(input)
- os.queueEvent("new_line",input)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- parallel.waitForAny(userInput,dataAI)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement