News:

Welcome to RetroCoders Community

Main Menu

Recent posts

#1
FreeBasic / Re: Classic chatbots PARRY ELI...
Last post by ron77 - Today at 02:29 PM
' Depression-ELIZA Conversation Simulator
' This program simulates a conversation between two chatbots:
' - ELIZA: Joseph Weizenbaum's 1966 Rogerian psychotherapist simulation
' - Depression Bot: A simulation of a person experiencing depression

' ----- INCLUDES -----
#include "file.bi"      ' For file operations
#include "fbgfx.bi"     ' For keyboard handling
Using FB

' ----- CONSTANTS -----
Const MAX_KEYWORDS = 40       ' Maximum number of ELIZA keywords
Const MAX_RESPONSES = 10      ' Maximum responses per keyword
Const MAX_CONJUGATIONS = 20   ' Maximum word conjugations
Const INPUT_BUFFER = 255      ' Maximum input length
Const DELAY_MS = 5000         ' Delay between responses (milliseconds)
Const MAX_TURNS = 100         ' Maximum conversation turns before auto-exit
Const SCREEN_WIDTH = 80       ' Width of console text display

' ----- ELIZA DATA TYPES -----
Type ElizaKeywordEntry
    keyword As String
    weight As Integer            ' Priority weight (higher = higher priority)
    responses(MAX_RESPONSES) As String
    responseCount As Integer     ' Number of actual responses
End Type

Type ConjugationPair
    from As String
    to As String
End Type

' ----- DEPRESSION BOT DATA TYPES -----
Type DepressionKeywordList
    words(10) As String
    count As Integer
End Type

Type DepressionResponseList
    responses(15) As String
    count As Integer
End Type

' ----- GLOBAL VARIABLES: ELIZA -----
Dim Shared elizaKeywords(MAX_KEYWORDS) As ElizaKeywordEntry
Dim Shared elizaKeywordCount As Integer
Dim Shared conjugations(MAX_CONJUGATIONS) As ConjugationPair
Dim Shared conjugationCount As Integer
Dim Shared elizaGenericResponses(10) As String
Dim Shared elizaGenericCount As Integer = 0

' ----- GLOBAL VARIABLES: DEPRESSION BOT -----
Dim Shared As Integer SADNESS = 60        ' Base level of sadness
Dim Shared As Integer FATIGUE = 55        ' Base level of energy depletion
Dim Shared As Integer HOPELESSNESS = 50   ' Base level of pessimism/hopelessness
Dim Shared As Integer SELFWORTH = 35      ' Base level of self-esteem (lower = worse)

' Thresholds for intense emotional responses
Const SADNESS_THRESHOLD = 75
Const FATIGUE_THRESHOLD = 70
Const HOPELESSNESS_THRESHOLD = 65
Const SELFWORTH_THRESHOLD_LOW = 25

' Keyword categories for Depression Bot
Dim Shared future As DepressionKeywordList
Dim Shared emotion As DepressionKeywordList
Dim Shared activity As DepressionKeywordList
Dim Shared social As DepressionKeywordList
Dim Shared health As DepressionKeywordList
Dim Shared work As DepressionKeywordList
Dim Shared sleep1 As DepressionKeywordList
Dim Shared help As DepressionKeywordList
Dim Shared positive As DepressionKeywordList
Dim Shared negative As DepressionKeywordList

' Response categories for Depression Bot
Dim Shared sadnessResponses As DepressionResponseList
Dim Shared fatigueResponses As DepressionResponseList
Dim Shared hopelessnessResponses As DepressionResponseList
Dim Shared selfworthResponses As DepressionResponseList
Dim Shared futureResponses As DepressionResponseList
Dim Shared emotionResponses As DepressionResponseList
Dim Shared activityResponses As DepressionResponseList
Dim Shared socialResponses As DepressionResponseList
Dim Shared healthResponses As DepressionResponseList
Dim Shared workResponses As DepressionResponseList
Dim Shared sleepResponses As DepressionResponseList
Dim Shared helpResponses As DepressionResponseList
Dim Shared neutralResponses As DepressionResponseList
Dim Shared questionResponses As DepressionResponseList
Dim Shared positiveFeedbackResponses As DepressionResponseList
Dim Shared negativeFeedbackResponses As DepressionResponseList
dim shared isend as boolean = false

' ----- UTILITY FUNCTIONS -----
Sub CenterText(text As String)
    Dim As Integer startPos = (SCREEN_WIDTH - Len(text)) \ 2
    If startPos < 0 Then startPos = 0
    Print Space(startPos); text
End Sub

Sub DisplayConversation(elizaToDepression As String, depressionToEliza As String, turnCount As Integer)
    Cls
    Print
    Print "DEPRESSION-ELIZA CONVERSATION SIMULATOR"
    Print String$(SCREEN_WIDTH - 1, 45)  ' 45 is ASCII for "-"
    Print "Turn: "; turnCount + 1; " | "; "Press ESC to exit"
    Print String$(SCREEN_WIDTH - 1, 45)  ' 45 is ASCII for "-"
    Print
    
    ' Display ELIZA's statement
    Print "ELIZA: "; elizaToDepression
    
    ' Display Depression Bot's response if provided
    If Len(depressionToEliza) > 0 Then
        Print
        Print "DEPRESSION: "; depressionToEliza
        
        ' Display emotional state (debug info)
        'Print
        'Print "[DEBUG - Sadness: "; SADNESS; ", Fatigue: "; FATIGUE; 
        'Print ", Hopelessness: "; HOPELESSNESS; ", Self-worth: "; SELFWORTH; "]"
    End If
End Sub

Function CheckForUserExit() As Integer
    ' Check for ESC key to exit
    Dim As String keyPress = Inkey()
    If keyPress = Chr(27) Then  ' 27 is ASCII for ESC
        Return 1
    End If
    Return 0
End Function

Sub Delay(ms As Integer)
    Dim As Double startTime = Timer
    Do
        ' Check for ESC during delay
        If Inkey() = Chr(27) Then isend = true
        Sleep 10
    Loop Until (Timer - startTime) * 1000 >= ms
End Sub

' ----- ELIZA FUNCTIONS -----
Function ElizaRandomResponse(responses() As String, count As Integer) As String
    Dim As Integer index = Int(Rnd * count)
    Return responses(index)
End Function

Function ElizaConjugatePhrase(phrase As String) As String
    Dim As String result = " " + LCase(phrase) + " "
    
    ' Apply all conjugations
    For i As Integer = 0 To conjugationCount - 1
        Dim As Integer startPos = InStr(result, conjugations(i).from)
        Do While startPos > 0
            result = Left(result, startPos - 1) + conjugations(i).to + Mid(result, startPos + Len(conjugations(i).from))
            startPos = InStr(startPos + Len(conjugations(i).to), result, conjugations(i).from)
        Loop
    Next
    
    ' Trim leading and trailing spaces
    Dim As String finalResult = Trim(result)
    
    ' Capitalize first letter
    If Len(finalResult) > 0 Then
        finalResult = UCase(Left(finalResult, 1)) + Mid(finalResult, 2)
    End If
    
    Return finalResult
End Function

Function ElizaFindKeyword(userInput As String, ByRef remainder As String) As Integer
    Dim As String lowerInput = " " + LCase(userInput) + " "
    Dim As Integer bestMatch = -1
    Dim As Integer bestWeight = -1
    
    ' Check all keywords
    For i As Integer = 0 To elizaKeywordCount - 1
        Dim As String keywordPattern = " " + elizaKeywords(i).keyword + " "
        Dim As Integer keywordPos = InStr(lowerInput, keywordPattern)
        
        ' If keyword found and has higher weight than current best
        If keywordPos > 0 And elizaKeywords(i).weight > bestWeight Then
            bestMatch = i
            bestWeight = elizaKeywords(i).weight
            
            ' Calculate the remainder text after the keyword
            remainder = Mid(userInput, keywordPos + Len(elizaKeywords(i).keyword))
        End If
    Next
    
    ' Also check for keywords at the start of input with space after
    For i As Integer = 0 To elizaKeywordCount - 1
        Dim As String keywordPattern = elizaKeywords(i).keyword + " "
        If Left(lowerInput, Len(keywordPattern)) = keywordPattern And elizaKeywords(i).weight > bestWeight Then
            bestMatch = i
            bestWeight = elizaKeywords(i).weight
            remainder = Mid(userInput, Len(elizaKeywords(i).keyword) + 1)
        End If
    Next
    
    Return bestMatch
End Function

Function ElizaTransformResponse(template As String, remainder As String) As String
    ' No remainder text available
    If Len(remainder) = 0 Then
        ' If template requires remainder, use a generic response instead
        If InStr(template, "_REMAINDER_") > 0 Then
            Dim As Integer genericIndex = Int(Rnd * elizaGenericCount)
            Return elizaGenericResponses(genericIndex)
        Else
            ' Template doesn't need remainder, use as is
            Return template
        End If
    End If
    
    ' Process the remainder through conjugation transformation
    Dim As String conjugatedRemainder = ElizaConjugatePhrase(remainder)
    
    ' Replace _REMAINDER_ placeholder with the conjugated text
    Dim As Integer placeholderPos = InStr(template, "_REMAINDER_")
    If placeholderPos > 0 Then
        Return Left(template, placeholderPos - 1) + conjugatedRemainder + Mid(template, placeholderPos + 11)
    Else
        Return template
    End If
End Function

Function ElizaGenerateResponse(userInput As String) As String
    ' Handle empty input
    If Len(Trim(userInput)) = 0 Then
        Return "You don't seem to be saying anything."
    End If
    
    ' Check for goodbye phrases
    Dim As String lowerInput = LCase(userInput)
    If InStr(lowerInput, "goodbye") > 0 Or InStr(lowerInput, "bye") > 0 Or _
       InStr(lowerInput, "quit") > 0 Or InStr(lowerInput, "exit") > 0 Then
        Return "Goodbye. It was nice talking to you."
    End If
    
    ' Find a keyword match
    Dim As String remainder = ""
    Dim As Integer keywordIndex = ElizaFindKeyword(userInput, remainder)
    
    ' No keyword match, use generic response
    If keywordIndex = -1 Then
        Return ElizaRandomResponse(elizaGenericResponses(), elizaGenericCount)
    End If
    
    ' Get a random response template for the matched keyword
    Dim As Integer responseIndex = Int(Rnd * elizaKeywords(keywordIndex).responseCount)
    Dim As String templateResponse = elizaKeywords(keywordIndex).responses(responseIndex)
    
    ' Transform the template with user's input
    Return ElizaTransformResponse(templateResponse, remainder)
End Function

' ----- DEPRESSION BOT FUNCTIONS -----
Function DepressionRandomResponse(responseList As DepressionResponseList) As String
    Dim As Integer index = Int(Rnd * responseList.count)
    Return responseList.responses(index)
End Function

Function DepressionContainsAny(userInput As String, wordList As DepressionKeywordList) As Integer
    Dim As String lowerInput = LCase(userInput)
    
    For i As Integer = 0 To wordList.count - 1
        If Len(wordList.words(i)) > 0 Then
            If InStr(lowerInput, wordList.words(i)) > 0 Then
                Return 1
            End If
        End If
    Next
    
    Return 0
End Function

Function DepressionGenerateResponse(userInput As String) As String
    Dim As String lowerInput = LCase(userInput)
    Dim As String response = ""
    
    ' Check for goodbye or exit
    If InStr(lowerInput, "goodbye") > 0 Or InStr(lowerInput, "bye") > 0 Or _
       InStr(lowerInput, "quit") > 0 Or InStr(lowerInput, "exit") > 0 Then
        Return "It's probably better if you go. I'm not good company anyway."
    End If
    
    ' Check for keywords and adjust emotional state
    If DepressionContainsAny(lowerInput, future) Then
        HOPELESSNESS += 10
        response = DepressionRandomResponse(futureResponses)
    ElseIf DepressionContainsAny(lowerInput, emotion) Then
        SADNESS += 10
        response = DepressionRandomResponse(emotionResponses)
    ElseIf DepressionContainsAny(lowerInput, activity) Then
        FATIGUE += 10
        response = DepressionRandomResponse(activityResponses)
    ElseIf DepressionContainsAny(lowerInput, social) Then
        SELFWORTH -= 5
        response = DepressionRandomResponse(socialResponses)
    ElseIf DepressionContainsAny(lowerInput, health) Then
        HOPELESSNESS += 5
        response = DepressionRandomResponse(healthResponses)
    ElseIf DepressionContainsAny(lowerInput, work) Then
        FATIGUE += 5
        SELFWORTH -= 5
        response = DepressionRandomResponse(workResponses)
    ElseIf DepressionContainsAny(lowerInput, sleep1) Then
        FATIGUE += 10
        response = DepressionRandomResponse(sleepResponses)
    ElseIf DepressionContainsAny(lowerInput, help) Then
        HOPELESSNESS += 5
        response = DepressionRandomResponse(helpResponses)
    ElseIf DepressionContainsAny(lowerInput, positive) Then
        SELFWORTH += 5
        response = DepressionRandomResponse(positiveFeedbackResponses)
    ElseIf DepressionContainsAny(lowerInput, negative) Then
        SELFWORTH -= 10
        SADNESS += 5
        response = DepressionRandomResponse(negativeFeedbackResponses)
    ElseIf InStr(lowerInput, "?") > 0 Then
        ' It's a question
        response = DepressionRandomResponse(questionResponses)
    Else
        ' No specific keywords found, check emotional state for intense responses
        If SADNESS > SADNESS_THRESHOLD Then
            response = DepressionRandomResponse(sadnessResponses)
        ElseIf FATIGUE > FATIGUE_THRESHOLD Then
            response = DepressionRandomResponse(fatigueResponses)
        ElseIf HOPELESSNESS > HOPELESSNESS_THRESHOLD Then
            response = DepressionRandomResponse(hopelessnessResponses)
        ElseIf SELFWORTH < SELFWORTH_THRESHOLD_LOW Then
            response = DepressionRandomResponse(selfworthResponses)
        Else
            ' If no triggers and emotions below threshold, use neutral response
            response = DepressionRandomResponse(neutralResponses)
        End If
    End If
    
    ' Gradually return emotional state toward baseline
    If SADNESS > 60 Then SADNESS -= 2
    If SADNESS < 60 Then SADNESS += 2
    
    If FATIGUE > 55 Then FATIGUE -= 1
    If FATIGUE < 55 Then FATIGUE += 1
    
    If HOPELESSNESS > 50 Then HOPELESSNESS -= 1
    If HOPELESSNESS < 50 Then HOPELESSNESS += 1
    
    If SELFWORTH > 35 Then SELFWORTH -= 1
    If SELFWORTH < 35 Then SELFWORTH += 1
    
    Return response
End Function

' ----- INITIALIZATION FUNCTIONS -----
Sub InitializeEliza()
    ' Initialize ELIZA keywords and responses
    
    ' Keyword 0: "hello"
    elizaKeywords(0).keyword = "hello"
    elizaKeywords(0).weight = 1
    elizaKeywords(0).responses(0) = "How do you do. Please tell me about your problem."
    elizaKeywords(0).responses(1) = "Hello. What seems to be your concern?"
    elizaKeywords(0).responseCount = 2
    
    ' Keyword 1: "computer"
    elizaKeywords(1).keyword = "computer"
    elizaKeywords(1).weight = 3
    elizaKeywords(1).responses(0) = "Do computers worry you?"
    elizaKeywords(1).responses(1) = "What do you think about machines?"
    elizaKeywords(1).responses(2) = "Why do you mention computers?"
    elizaKeywords(1).responses(3) = "What do you think machines have to do with your problem?"
    elizaKeywords(1).responseCount = 4
    
    ' Keyword 2: "name"
    elizaKeywords(2).keyword = "name"
    elizaKeywords(2).weight = 2
    elizaKeywords(2).responses(0) = "I am not interested in names."
    elizaKeywords(2).responses(1) = "Names don't interest me."
    elizaKeywords(2).responseCount = 2
    
    ' Keyword 3: "sorry"
    elizaKeywords(3).keyword = "sorry"
    elizaKeywords(3).weight = 1
    elizaKeywords(3).responses(0) = "Please don't apologize."
    elizaKeywords(3).responses(1) = "Apologies are not necessary."
    elizaKeywords(3).responses(2) = "What feelings do you have when you apologize?"
    elizaKeywords(3).responseCount = 3
    
    ' Keyword 4: "I remember"
    elizaKeywords(4).keyword = "i remember"
    elizaKeywords(4).weight = 5
    elizaKeywords(4).responses(0) = "Do you often think of _REMAINDER_?"
    elizaKeywords(4).responses(1) = "Does thinking of _REMAINDER_ bring anything else to mind?"
    elizaKeywords(4).responses(2) = "What else do you remember?"
    elizaKeywords(4).responses(3) = "Why do you recall _REMAINDER_ right now?"
    elizaKeywords(4).responses(4) = "What in the present situation reminds you of _REMAINDER_?"
    elizaKeywords(4).responseCount = 5
    
    ' Keyword 5: "if"
    elizaKeywords(5).keyword = "if"
    elizaKeywords(5).weight = 3
    elizaKeywords(5).responses(0) = "Do you think it's likely that _REMAINDER_?"
    elizaKeywords(5).responses(1) = "Do you wish that _REMAINDER_?"
    elizaKeywords(5).responses(2) = "What do you think about _REMAINDER_?"
    elizaKeywords(5).responses(3) = "Really, if _REMAINDER_?"
    elizaKeywords(5).responseCount = 4
    
    ' Keyword 6: "I dreamed"
    elizaKeywords(6).keyword = "i dreamed"
    elizaKeywords(6).weight = 4
    elizaKeywords(6).responses(0) = "Really, _REMAINDER_?"
    elizaKeywords(6).responses(1) = "Have you ever fantasized _REMAINDER_ while you were awake?"
    elizaKeywords(6).responses(2) = "Have you dreamed _REMAINDER_ before?"
    elizaKeywords(6).responseCount = 3
    
    ' Keyword 7: "dream"
    elizaKeywords(7).keyword = "dream"
    elizaKeywords(7).weight = 3
    elizaKeywords(7).responses(0) = "What does that dream suggest to you?"
    elizaKeywords(7).responses(1) = "Do you dream often?"
    elizaKeywords(7).responses(2) = "What persons appear in your dreams?"
    elizaKeywords(7).responses(3) = "Are you disturbed by your dreams?"
    elizaKeywords(7).responseCount = 4
    
    ' Keyword 8: "perhaps"
    elizaKeywords(8).keyword = "perhaps"
    elizaKeywords(8).weight = 1
    elizaKeywords(8).responses(0) = "You don't seem quite certain."
    elizaKeywords(8).responses(1) = "Why the uncertain tone?"
    elizaKeywords(8).responses(2) = "Can't you be more positive?"
    elizaKeywords(8).responses(3) = "You aren't sure?"
    elizaKeywords(8).responses(4) = "Don't you know?"
    elizaKeywords(8).responseCount = 5
    
    ' Keyword 9: "mother"
    elizaKeywords(9).keyword = "mother"
    elizaKeywords(9).weight = 3
    elizaKeywords(9).responses(0) = "Tell me more about your family."
    elizaKeywords(9).responses(1) = "Who else in your family _REMAINDER_?"
    elizaKeywords(9).responses(2) = "Your mother?"
    elizaKeywords(9).responses(3) = "What about your mother?"
    elizaKeywords(9).responseCount = 4
    
    ' Keyword 10: "father"
    elizaKeywords(10).keyword = "father"
    elizaKeywords(10).weight = 3
    elizaKeywords(10).responses(0) = "Your father?"
    elizaKeywords(10).responses(1) = "Does he influence you strongly?"
    elizaKeywords(10).responses(2) = "What else comes to mind when you think of your father?"
    elizaKeywords(10).responseCount = 3
    
    ' Keyword 11: "I want"
    elizaKeywords(11).keyword = "i want"
    elizaKeywords(11).weight = 5
    elizaKeywords(11).responses(0) = "What would it mean if you got _REMAINDER_?"
    elizaKeywords(11).responses(1) = "Why do you want _REMAINDER_?"
    elizaKeywords(11).responses(2) = "Suppose you got _REMAINDER_ soon?"
    elizaKeywords(11).responseCount = 3
    
    ' Keyword 12: "I am glad"
    elizaKeywords(12).keyword = "i am glad"
    elizaKeywords(12).weight = 3
    elizaKeywords(12).responses(0) = "How have I helped you to be _REMAINDER_?"
    elizaKeywords(12).responses(1) = "What makes you happy just now?"
    elizaKeywords(12).responses(2) = "Can you explain why you are suddenly _REMAINDER_?"
    elizaKeywords(12).responseCount = 3
    
    ' Keyword 13: "sad"
    elizaKeywords(13).keyword = "sad"
    elizaKeywords(13).weight = 4
    elizaKeywords(13).responses(0) = "I'm sorry to hear that you are sad."
    elizaKeywords(13).responses(1) = "Do you think coming here will help you not to be sad?"
    elizaKeywords(13).responses(2) = "Can you explain what made you sad?"
    elizaKeywords(13).responseCount = 3
    
    ' Keyword 14: "depressed"
    elizaKeywords(14).keyword = "depressed"
    elizaKeywords(14).weight = 5
    elizaKeywords(14).responses(0) = "I am sorry to hear you are depressed."
    elizaKeywords(14).responses(1) = "Do you think talking about it will help you feel less depressed?"
    elizaKeywords(14).responses(2) = "How long have you felt this way?"
    elizaKeywords(14).responseCount = 3
    
    ' Keyword 15: "tired"
    elizaKeywords(15).keyword = "tired"
    elizaKeywords(15).weight = 4
    elizaKeywords(15).responses(0) = "Why do you think you feel so tired?"
    elizaKeywords(15).responses(1) = "Do you get enough sleep?"
    elizaKeywords(15).responses(2) = "Does being tired affect other parts of your life?"
    elizaKeywords(15).responseCount = 3
    
    ' Keyword 16: "hopeless"
    elizaKeywords(16).keyword = "hopeless"
    elizaKeywords(16).weight = 5
    elizaKeywords(16).responses(0) = "Why do you feel things are hopeless?"
    elizaKeywords(16).responses(1) = "Have you always felt this way?"
    elizaKeywords(16).responses(2) = "What makes you feel there's no hope?"
    elizaKeywords(16).responseCount = 3
    
    ' Keyword 17: "worthless"
    elizaKeywords(17).keyword = "worthless"
    elizaKeywords(17).weight = 5
    elizaKeywords(17).responses(0) = "Why do you believe you are worthless?"
    elizaKeywords(17).responses(1) = "Do others tell you that you're worthless?"
    elizaKeywords(17).responses(2) = "What would make you feel worthwhile?"
    elizaKeywords(17).responseCount = 3
    
    ' Keyword 18: "i am"
    elizaKeywords(18).keyword = "i am"
    elizaKeywords(18).weight = 4
    elizaKeywords(18).responses(0) = "Is it because you are _REMAINDER_ that you came to me?"
    elizaKeywords(18).responses(1) = "How long have you been _REMAINDER_?"
    elizaKeywords(18).responses(2) = "Do you believe it is normal to be _REMAINDER_?"
    elizaKeywords(18).responses(3) = "Do you enjoy being _REMAINDER_?"
    elizaKeywords(18).responses(4) = "Do you know anyone else who is _REMAINDER_?"
    elizaKeywords(18).responseCount = 5
    
    ' Keyword 19: "i feel"
    elizaKeywords(19).keyword = "i feel"
    elizaKeywords(19).weight = 4
    elizaKeywords(19).responses(0) = "Tell me more about such feelings."
    elizaKeywords(19).responses(1) = "Do you often feel _REMAINDER_?"
    elizaKeywords(19).responses(2) = "Do you enjoy feeling _REMAINDER_?"
    elizaKeywords(19).responses(3) = "What does feeling _REMAINDER_ remind you of?"
    elizaKeywords(19).responseCount = 4
    
    ' Keyword 20: "i don't"
    elizaKeywords(20).keyword = "i don't"
    elizaKeywords(20).weight = 4
    elizaKeywords(20).responses(0) = "Why don't you _REMAINDER_?"
    elizaKeywords(20).responses(1) = "Do you wish you could _REMAINDER_?"
    elizaKeywords(20).responses(2) = "Does that trouble you?"
    elizaKeywords(20).responseCount = 3
    
    ' Keyword 21: "i can't"
    elizaKeywords(21).keyword = "i can't"
    elizaKeywords(21).weight = 4
    elizaKeywords(21).responses(0) = "How do you know you can't _REMAINDER_?"
    elizaKeywords(21).responses(1) = "Perhaps you could _REMAINDER_ if you tried."
    elizaKeywords(21).responses(2) = "What would it take for you to _REMAINDER_?"
    elizaKeywords(21).responseCount = 3
    
    ' Keyword 22: "therapist"
    elizaKeywords(22).keyword = "therapist"
    elizaKeywords(22).weight = 3
    elizaKeywords(22).responses(0) = "What does therapy mean to you?"
    elizaKeywords(22).responses(1) = "Have you had therapy before?"
    elizaKeywords(22).responses(2) = "Do you think therapy can help you?"
    elizaKeywords(22).responseCount = 3
    
    ' Keyword 23: "yes"
    elizaKeywords(23).keyword = "yes"
    elizaKeywords(23).weight = 1
    elizaKeywords(23).responses(0) = "You seem quite positive."
    elizaKeywords(23).responses(1) = "Are you sure?"
    elizaKeywords(23).responses(2) = "I see."
    elizaKeywords(23).responses(3) = "I understand."
    elizaKeywords(23).responseCount = 4
    
    ' Keyword 24: "no"
    elizaKeywords(24).keyword = "no"
    elizaKeywords(24).weight = 1
    elizaKeywords(24).responses(0) = "Why not?"
    elizaKeywords(24).responses(1) = "You seem quite negative."
    elizaKeywords(24).responses(2) = "Why do you say no?"
    elizaKeywords(24).responses(3) = "Does saying no make you feel better?"
    elizaKeywords(24).responseCount = 4
    
    ' Keyword 25: "always"
    elizaKeywords(25).keyword = "always"
    elizaKeywords(25).weight = 1
    elizaKeywords(25).responses(0) = "Can you think of a specific example?"
    elizaKeywords(25).responses(1) = "When?"
    elizaKeywords(25).responses(2) = "What incident are you thinking of?"
    elizaKeywords(25).responses(3) = "Really, always?"
    elizaKeywords(25).responseCount = 4
    
    ' Initialize generic fallback responses
    elizaGenericResponses(0) = "I'm not sure I understand you fully."
    elizaGenericResponses(1) = "Please go on."
    elizaGenericResponses(2) = "What does that suggest to you?"
    elizaGenericResponses(3) = "Do you feel strongly about that?"
    elizaGenericResponses(4) = "That is interesting. Please continue."
    elizaGenericResponses(5) = "Tell me more about that."
    elizaGenericResponses(6) = "Does talking about this bother you?"
    elizaGenericResponses(7) = "Can you elaborate on that?"
    elizaGenericResponses(8) = "Why do you say that?"
    elizaGenericResponses(9) = "How does that make you feel?"
    elizaGenericResponses(10) = "Do you often feel this way?"
    elizaGenericCount = 11
    
    ' Set keyword count
    elizaKeywordCount = 26
    
    ' Initialize conjugation pairs
    conjugations(0).from = " i "
    conjugations(0).to = " you "
    
    conjugations(1).from = " i'm "
    conjugations(1).to = " you're "
    
    conjugations(2).from = " i've "
    conjugations(2).to = " you've "
    
    conjugations(3).from = " i'll "
    conjugations(3).to = " you'll "
    
    conjugations(4).from = " my "
    conjugations(4).to = " your "
    
    conjugations(5).from = " am "
    conjugations(5).to = " are "
    
    conjugations(6).from = " was "
    conjugations(6).to = " were "
    
    conjugations(7).from = " me "
    conjugations(7).to = " you "
    
    conjugations(8).from = " myself "
    conjugations(8).to = " yourself "

    conjugations(9).from = " mine "
    conjugations(9).to = " yours "
    
    ' Reverse direction (you->i)
    conjugations(10).from = " you "
    conjugations(10).to = " i "
    
    conjugations(11).from = " you're "
    conjugations(11).to = " i'm "
    
    conjugations(12).from = " you've "
    conjugations(12).to = " i've "
    
    conjugations(13).from = " you'll "
    conjugations(13).to = " i'll "
    
    conjugations(14).from = " your "
    conjugations(14).to = " my "
    
    conjugations(15).from = " yours "
    conjugations(15).to = " mine "

    conjugations(16).from = " are "
    conjugations(16).to = " am "

    conjugations(17).from = " were "
    conjugations(17).to = " was "
    
    conjugations(18).from = " yourself "
    conjugations(18).to = " myself "
    
    ' Set conjugation count
    conjugationCount = 19
End Sub

Sub InitializeDepression()
    ' Initialize Depression Bot keyword lists
    
    ' Future-related words
    future.words(0) = "future": future.words(1) = "tomorrow": future.words(2) = "plan"
    future.words(3) = "hope": future.words(4) = "dream": future.words(5) = "goal"
    future.words(6) = "aspiration": future.words(7) = "ambition": future.words(8) = "someday"
    future.words(9) = "next": future.words(10) = "will be"
    future.count = 11
    
    ' Emotion-related words
    emotion.words(0) = "feel": emotion.words(1) = "sad": emotion.words(2) = "happy"
    emotion.words(3) = "emotion": emotion.words(4) = "mood": emotion.words(5) = "depress"
    emotion.words(6) = "joy": emotion.words(7) = "upset": emotion.words(8) = "anxious"
    emotion.words(9) = "worried": emotion.words(10) = "cry"
    emotion.count = 11
    
    ' Activity-related words
    activity.words(0) = "activity": activity.words(1) = "hobby": activity.words(2) = "exercise"
    activity.words(3) = "walk": activity.words(4) = "run": activity.words(5) = "play"
    activity.words(6) = "sport": activity.words(7) = "game": activity.words(8) = "outside"
    activity.words(9) = "fun": activity.words(10) = "enjoy"
    activity.count = 11
    
    ' Social-related words
    social.words(0) = "friend": social.words(1) = "family": social.words(2) = "people"
    social.words(3) = "relationship": social.words(4) = "party": social.words(5) = "social"
    social.words(6) = "talk": social.words(7) = "meet": social.words(8) = "date"
    social.words(9) = "loved": social.words(10) = "parent"
    social.count = 11
    
    ' Health-related words
    health.words(0) = "health": health.words(1) = "doctor": health.words(2) = "therapy"
    health.words(3) = "medicine": health.words(4) = "medication": health.words(5) = "treatment"
    health.words(6) = "therapist": health.words(7) = "counselor": health.words(8) = "exercise"
    health.words(9) = "eat": health.words(10) = "diet"
    health.count = 11
    
    ' Work-related words
    work.words(0) = "work": work.words(1) = "job": work.words(2) = "career"
    work.words(3) = "school": work.words(4) = "college": work.words(5) = "study"
    work.words(6) = "degree": work.words(7) = "boss": work.words(8) = "coworker"
    work.words(9) = "office": work.words(10) = "class"
    ' Sleep-related words
    sleep1.words(0) = "sleep": sleep1.words(1) = "tired": sleep1.words(2) = "fatigue"
    sleep1.words(3) = "exhausted": sleep1.words(4) = "insomnia": sleep1.words(5) = "rest"
    sleep1.words(6) = "bed": sleep1.words(7) = "nap": sleep1.words(8) = "awake"
    sleep1.words(9) = "dream": sleep1.words(10) = "nightmare"
    sleep1.count = 11
    
    ' Help-related words
    help.words(0) = "help": help.words(1) = "support": help.words(2) = "advice"
    help.words(3) = "suggestion": help.words(4) = "therapy": help.words(5) = "therapist"
    help.words(6) = "counselor": help.words(7) = "psychiatrist": help.words(8) = "medication"
    help.words(9) = "better": help.words(10) = "improve"
    help.count = 11
    
    ' Positive words
    positive.words(0) = "good": positive.words(1) = "great": positive.words(2) = "wonderful"
    positive.words(3) = "excellent": positive.words(4) = "amazing": positive.words(5) = "happy"
    positive.words(6) = "joy": positive.words(7) = "love": positive.words(8) = "hopeful"
    positive.words(9) = "excited": positive.words(10) = "positive"
    positive.count = 11
    
    ' Negative words
    negative.words(0) = "bad": negative.words(1) = "terrible": negative.words(2) = "awful"
    negative.words(3) = "worst": negative.words(4) = "horrible": negative.words(5) = "miserable"
    negative.words(6) = "sad": negative.words(7) = "depressed": negative.words(8) = "unhappy"
    negative.words(9) = "negative": negative.words(10) = "worthless"
    negative.count = 11
    
    ' Response sets
    
    ' Sadness responses (intense)
    sadnessResponses.responses(0) = "I just feel so empty inside all the time."
    sadnessResponses.responses(1) = "Everything seems so meaningless lately. What's the point?"
    sadnessResponses.responses(2) = "I can't remember the last time I felt genuinely happy."
    sadnessResponses.responses(3) = "I try to feel better, but the sadness is always there."
    sadnessResponses.responses(4) = "Sometimes I just cry for no reason at all."
    sadnessResponses.responses(5) = "I feel like I'm drowning in sadness most days."
    sadnessResponses.responses(6) = "I wake up feeling sad and go to bed feeling sad. It never ends."
    sadnessResponses.responses(7) = "I put on a fake smile, but inside I'm just... hollow."
    sadnessResponses.responses(8) = "The weight of sadness is crushing me. I can barely breathe sometimes."
    sadnessResponses.count = 9
    
    ' Fatigue responses (intense)
    fatigueResponses.responses(0) = "I'm just so tired all the time. No amount of sleep helps."
    fatigueResponses.responses(1) = "I barely have energy to get out of bed most days."
    fatigueResponses.responses(2) = "Everything feels like such an enormous effort."
    fatigueResponses.responses(3) = "I used to have energy to do things. Now I'm exhausted by the smallest tasks."
    fatigueResponses.responses(4) = "I can sleep for 12 hours and still wake up completely drained."
    fatigueResponses.responses(5) = "I wish I could do more, but I just don't have the energy anymore."
    fatigueResponses.responses(6) = "Sometimes even talking feels like too much effort."
    fatigueResponses.responses(7) = "I can't remember what it feels like to not be tired."
    fatigueResponses.responses(8) = "My body feels so heavy, like I'm carrying a ton of weight everywhere I go."
    fatigueResponses.count = 9
    
    ' Hopelessness responses (intense)
    hopelessnessResponses.responses(0) = "I don't see how things will ever get better."
    hopelessnessResponses.responses(1) = "Every day is the same... nothing changes, nothing improves."
    hopelessnessResponses.responses(2) = "I've tried everything, but nothing helps. I'm stuck like this."
    hopelessnessResponses.responses(3) = "What's the point of trying? Nothing I do makes any difference."
    hopelessnessResponses.responses(4) = "I used to believe things could improve, but I don't anymore."
    hopelessnessResponses.responses(5) = "Sometimes I think this darkness will last forever."
    hopelessnessResponses.responses(6) = "Every time I get my hopes up, I end up disappointed again."
    hopelessnessResponses.responses(7) = "I see other people moving forward with their lives while I'm just... stuck."
    hopelessnessResponses.responses(8) = "I try to imagine a better future, but I just can't see it anymore."
    ' Low self-worth responses (intense)
    selfworthResponses.responses(0) = "I feel like I'm not good enough at anything."
    selfworthResponses.responses(1) = "People would be better off without me around."
    selfworthResponses.responses(2) = "I'm such a burden to everyone who knows me."
    selfworthResponses.responses(3) = "I'm a failure. I can't seem to do anything right."
    selfworthResponses.responses(4) = "Everyone else seems to have their life together. What's wrong with me?"
    selfworthResponses.responses(5) = "I hate looking in the mirror. I don't like what I see."
    selfworthResponses.responses(6) = "I feel like I'm just taking up space in the world."
    selfworthResponses.responses(7) = "I constantly feel like I'm disappointing everyone, including myself."
    selfworthResponses.responses(8) = "I can't understand why anyone would want to spend time with me."
    selfworthResponses.count = 9
    
    ' Future-related responses
    futureResponses.responses(0) = "I try not to think about the future. It only makes me anxious."
    futureResponses.responses(1) = "I used to have dreams and goals. Now I just try to get through each day."
    futureResponses.responses(2) = "The future? It's probably just more of the same emptiness ahead."
    futureResponses.responses(3) = "I can't imagine things being different than they are now."
    futureResponses.responses(4) = "Planning for the future feels pointless when I can barely handle today."
    futureResponses.responses(5) = "I don't see much hope when I think about what's ahead."
    futureResponses.count = 6
    
    ' Emotion-related responses
    emotionResponses.responses(0) = "My emotions feel dulled, like I'm watching life through a foggy window."
    emotionResponses.responses(1) = "I mostly feel numb, with occasional waves of intense sadness."
    emotionResponses.responses(2) = "I remember when I used to feel happiness. It seems so long ago now."
    emotionResponses.responses(3) = "Sometimes I feel nothing at all, which is almost worse than feeling sad."
    emotionResponses.responses(4) = "I don't know how to control these negative feelings. They just overwhelm me."
    emotionResponses.responses(5) = "I'm trying to connect with positive emotions, but they seem so far away."
    emotionResponses.count = 6
    
    ' Activity-related responses
    activityResponses.responses(0) = "I used to enjoy doing things. Now nothing seems interesting anymore."
    activityResponses.responses(1) = "I know I should be more active, but I can never find the motivation."
    activityResponses.responses(2) = "Even the activities I used to love feel like a chore now."
    activityResponses.responses(3) = "Most days I just stay in bed or on the couch. It's all I can manage."
    activityResponses.responses(4) = "People tell me to 'just get out more,' but they don't understand how hard that is."
    activityResponses.responses(5) = "Starting something new feels impossible with how little energy I have."
    activityResponses.count = 6
    
    ' Social-related responses
    socialResponses.responses(0) = "I've been isolating myself. Being around people takes too much energy."
    socialResponses.responses(1) = "I feel so disconnected from everyone, even when I'm with them."
    socialResponses.responses(2) = "I worry that I bring everyone down when I'm around them."
    socialResponses.responses(3) = "I cancel plans a lot. Then I feel guilty, which makes me want to isolate more."
    socialResponses.responses(4) = "I'm afraid people will notice something's wrong with me."
    socialResponses.responses(5) = "It's easier to be alone than to pretend I'm okay around others."
    socialResponses.count = 6
    
    ' Health-related responses
    healthResponses.responses(0) = "I've tried medication, but I'm not sure it helps much."
    healthResponses.responses(1) = "My doctor says I should exercise more, but getting out of bed is hard enough."
    healthResponses.responses(2) = "Therapy is exhausting. Talking about my problems just reminds me of how many I have."
    healthResponses.responses(3) = "I know I should take better care of myself, but I don't have the energy."
    healthResponses.responses(4) = "My physical health is suffering too. Everything in the body is connected, I guess."
    healthResponses.responses(5) = "I've lost my appetite. Food doesn't taste like anything anymore."
    ' Work-related responses
    workResponses.responses(0) = "I'm falling behind at work. I can't focus or concentrate anymore."
    workResponses.responses(1) = "I worry I'll lose my job because of how poorly I'm performing."
    workResponses.responses(2) = "I used to be ambitious. Now I just try to get through the workday."
    workResponses.responses(3) = "I call in sick a lot. Sometimes I just can't face going in."
    workResponses.responses(4) = "My work used to give me purpose. Now it just feels meaningless."
    workResponses.responses(5) = "I'm constantly exhausted at work. I can barely keep up."
    workResponses.count = 6
    
    ' Sleep-related responses
    sleepResponses.responses(0) = "I either sleep too much or can't sleep at all. There's no in-between."
    sleepResponses.responses(1) = "I'm exhausted but when I lie down, my mind starts racing with negative thoughts."
    sleepResponses.responses(2) = "I have nightmares when I do sleep. Sometimes being awake is better."
    sleepResponses.responses(3) = "Sleep is my escape. I sleep whenever I can to avoid being conscious."
    sleepResponses.responses(4) = "I wake up at 3 AM and can't get back to sleep. That's when the dark thoughts come."
    sleepResponses.responses(5) = "No matter how much I sleep, I never feel rested."
    sleepResponses.count = 6
    
    ' Help-related responses
    helpResponses.responses(0) = "I've tried getting help, but nothing seems to work for me."
    helpResponses.responses(1) = "Therapy helped a little, but I still feel broken inside."
    helpResponses.responses(2) = "I don't know if I can be fixed. This might just be who I am now."
    helpResponses.responses(3) = "I want to feel better, but I don't know how anymore."
    helpResponses.responses(4) = "I'm afraid to hope that things could improve. I've been disappointed before."
    helpResponses.responses(5) = "Maybe I don't deserve to feel better. Maybe this is just my life now."
    helpResponses.count = 6
    
    ' Neutral/general responses
    neutralResponses.responses(0) = "Sorry, I'm not great company these days."
    neutralResponses.responses(1) = "I don't really know what to say about that."
    neutralResponses.responses(2) = "I'm just trying to get through each day."
    neutralResponses.responses(3) = "It's hard to care about much of anything lately."
    neutralResponses.responses(4) = "I probably should be more interested in that, but I'm not."
    neutralResponses.responses(5) = "I don't have the energy to think about that right now."
    neutralResponses.responses(6) = "I wish I could feel differently about things."
    neutralResponses.responses(7) = "I'm sorry. My mind wandered off. What were we talking about?"
    neutralResponses.responses(8) = "It's hard to focus on conversations these days."
    neutralResponses.responses(9) = "I used to have opinions about things like that. Now I'm not sure."
    neutralResponses.responses(10) = "I know I should care more, but everything feels so distant."
    neutralResponses.responses(11) = "I'm trying to engage, but it's really difficult for me."
    neutralResponses.responses(12) = "Some days are better than others. Today isn't great."
    neutralResponses.responses(13) = "I'm just going through the motions most of the time."
    neutralResponses.responses(14) = "Everything feels like such an effort lately."
    neutralResponses.responses(15) = "I don't mean to be negative all the time. It's just how I feel."
    neutralResponses.count = 16
    
    ' Question responses
    questionResponses.responses(0) = "I don't have good answers for anything right now."
    questionResponses.responses(1) = "I don't know. I don't have answers for my own questions, let alone others'."
    questionResponses.responses(2) = "I wish I knew. Everything feels confusing to me."
    questionResponses.responses(3) = "I'm not sure about anything anymore."
    questionResponses.responses(4) = "I don't know how to respond to that question."
    questionResponses.responses(5) = "I used to know what I thought. Now I'm just confused all the time."
    ' Positive feedback responses
    positiveFeedbackResponses.responses(0) = "Thanks for saying that, though I'm not sure I believe it."
    positiveFeedbackResponses.responses(1) = "That's nice of you to say. I wish I could see myself that way."
    positiveFeedbackResponses.responses(2) = "I appreciate that, even if I don't feel it's true."
    positiveFeedbackResponses.responses(3) = "I'm trying. Some days are harder than others."
    positiveFeedbackResponses.responses(4) = "I want to believe positive things, but my mind fights against it."
    positiveFeedbackResponses.responses(5) = "Thank you. It's hard to accept compliments when you feel worthless."
    positiveFeedbackResponses.count = 6
    
    ' Negative feedback responses
    negativeFeedbackResponses.responses(0) = "Yeah, you're probably right. I'm not doing very well."
    negativeFeedbackResponses.responses(1) = "I know. I'm a mess. I'm sorry."
    negativeFeedbackResponses.responses(2) = "You're just saying what I already think about myself."
    negativeFeedbackResponses.responses(3) = "I know I'm disappointing. I disappoint myself too."
    negativeFeedbackResponses.responses(4) = "That hurts to hear, but I can't say you're wrong."
    negativeFeedbackResponses.responses(5) = "I'm trying, but it's really hard. I know I'm failing."
    negativeFeedbackResponses.count = 6
End Sub

' ----- MAIN PROGRAM -----
Sub Main()
    Dim As String elizaResponse, depressionResponse
    Dim As Integer turnCount = 0
    Dim As Integer isUserExit = 0
    
    ' Seed the random number generator
    Randomize Timer
    
    ' Initialize both chatbots
    InitializeEliza()
    InitializeDepression()
    
    ' Clear screen and display intro
    Cls
    CenterText("DEPRESSION-ELIZA CONVERSATION SIMULATOR")
    CenterText("------------------------------------------")
    CenterText("Simulating a conversation between two chatbots:")
    CenterText("ELIZA (1966) - A Rogerian psychotherapist")
    CenterText("Depression Bot - A simulation of someone experiencing depression")
    CenterText("")
    CenterText("Press ESC at any time to exit the simulation")
    CenterText("")
    Print
    
    ' Initial greeting from ELIZA to start the conversation
    elizaResponse = "Hello. How are you feeling today?"
    
    ' Main conversation loop
    Do
        ' Display ELIZA's response and Depression Bot's reaction
        DisplayConversation(elizaResponse, "", turnCount)
        
        ' Give user a chance to exit
        If Inkey() = Chr(27) Then Exit Do
        
        ' Short delay
        Delay(DELAY_MS)
        
        ' Get Depression Bot's response to ELIZA
        depressionResponse = DepressionGenerateResponse(elizaResponse)
        
        ' Display full exchange
        DisplayConversation(elizaResponse, depressionResponse, turnCount)
        
        ' Give user a chance to exit
        If Inkey() = Chr(27) Then isend = true
        if isend = true then exit do
        ' Short delay
        Delay(DELAY_MS)
        
        ' Get ELIZA's response to Depression Bot
        elizaResponse = ElizaGenerateResponse(depressionResponse)
        
        ' Increment turn counter
        turnCount += 1
        
        ' Check for maximum turns (safety)
        If turnCount >= MAX_TURNS Then 
            Print
            CenterText("Maximum conversation length reached.")
            Exit Do
        End If
        
        ' Exit if either bot says goodbye
        If LCase(elizaResponse) = "goodbye. it was nice talking to you." Or _
           LCase(depressionResponse) = "it's probably better if you go. i'm not good company anyway." Then
            Exit Do
        End If
        
    Loop
    
    ' Final exit message
    Print
    CenterText("Conversation ended.")
    Print
    Print "Press any key to exit..."
    Sleep
End Sub

' Start the program
Main()
#2
FreeBasic / Re: Classic chatbots PARRY ELI...
Last post by ron77 - Today at 02:28 PM
' Depression Chatbot in FreeBASIC
' This simulates a person with depression, modeling common thought patterns
' and responses characteristic of depressive disorders.

' Emotional state variables (0-100 scale)
Dim Shared As Integer SADNESS = 60        ' Base level of sadness
Dim Shared As Integer FATIGUE = 55        ' Base level of energy depletion
Dim Shared As Integer HOPELESSNESS = 50   ' Base level of pessimism/hopelessness
Dim Shared As Integer SELFWORTH = 35      ' Base level of self-esteem (lower = worse)

' Thresholds for intense emotional responses
Const SADNESS_THRESHOLD = 75
Const FATIGUE_THRESHOLD = 70
Const HOPELESSNESS_THRESHOLD = 65
Const SELFWORTH_THRESHOLD_LOW = 25

' Arrays to hold keyword lists
Dim Shared future_words(10) As String
Dim Shared emotion_words(10) As String  
Dim Shared activity_words(10) As String
Dim Shared social_words(10) As String
Dim Shared health_words(10) As String
Dim Shared work_words(10) As String
Dim Shared negative_words(10) As String
Dim Shared positive_words(10) As String
Dim Shared sleep_words(10) As String
Dim Shared help_words(10) As String

' Arrays to hold responses
Dim Shared sadness_responses(8) As String
Dim Shared fatigue_responses(8) As String
Dim Shared hopelessness_responses(8) As String
Dim Shared selfworth_responses(8) As String
Dim Shared future_responses(5) As String
Dim Shared emotion_responses(5) As String
Dim Shared activity_responses(5) As String
Dim Shared social_responses(5) As String
Dim Shared health_responses(5) As String
Dim Shared work_responses(5) As String
Dim Shared sleep_responses(5) As String
Dim Shared help_responses(5) As String
Dim Shared neutral_responses(15) As String
Dim Shared question_responses(5) As String
Dim Shared positive_feedback_responses(5) As String
Dim Shared negative_feedback_responses(5) As String

' Function to initialize all response arrays
Sub InitializeResponses()
    ' Initialize keyword lists
    
    ' Future-related words
    future_words(0) = "future": future_words(1) = "tomorrow": future_words(2) = "plan"
    future_words(3) = "hope": future_words(4) = "dream": future_words(5) = "goal"
    future_words(6) = "aspiration": future_words(7) = "ambition": future_words(8) = "someday"
    future_words(9) = "next": future_words(10) = "will be"
    
    ' Emotion-related words
    emotion_words(0) = "feel": emotion_words(1) = "sad": emotion_words(2) = "happy"
    emotion_words(3) = "emotion": emotion_words(4) = "mood": emotion_words(5) = "depress"
    emotion_words(6) = "joy": emotion_words(7) = "upset": emotion_words(8) = "anxious"
    emotion_words(9) = "worried": emotion_words(10) = "cry"
    
    ' Activity-related words
    activity_words(0) = "activity": activity_words(1) = "hobby": activity_words(2) = "exercise"
    activity_words(3) = "walk": activity_words(4) = "run": activity_words(5) = "play"
    activity_words(6) = "sport": activity_words(7) = "game": activity_words(8) = "outside"
    activity_words(9) = "fun": activity_words(10) = "enjoy"
    
    ' Social-related words
    social_words(0) = "friend": social_words(1) = "family": social_words(2) = "people"
    social_words(3) = "relationship": social_words(4) = "party": social_words(5) = "social"
    social_words(6) = "talk": social_words(7) = "meet": social_words(8) = "date"
    social_words(9) = "loved": social_words(10) = "parent"
    
    ' Health-related words
    health_words(0) = "health": health_words(1) = "doctor": health_words(2) = "therapy"
    health_words(3) = "medicine": health_words(4) = "medication": health_words(5) = "treatment"
    health_words(6) = "therapist": health_words(7) = "counselor": health_words(8) = "exercise"
    health_words(9) = "eat": health_words(10) = "diet"
    
    ' Work-related words
    work_words(0) = "work": work_words(1) = "job": work_words(2) = "career"
    work_words(3) = "school": work_words(4) = "college": work_words(5) = "study"
    work_words(6) = "degree": work_words(7) = "boss": work_words(8) = "coworker"
    work_words(9) = "office": work_words(10) = "class"
    
    ' Sleep-related words
    sleep_words(0) = "sleep": sleep_words(1) = "tired": sleep_words(2) = "fatigue"
    sleep_words(3) = "exhausted": sleep_words(4) = "insomnia": sleep_words(5) = "rest"
    sleep_words(6) = "bed": sleep_words(7) = "nap": sleep_words(8) = "awake"
    sleep_words(9) = "dream": sleep_words(10) = "nightmare"
    
    ' Help-related words
    help_words(0) = "help": help_words(1) = "support": help_words(2) = "advice"
    help_words(3) = "suggestion": help_words(4) = "therapy": help_words(5) = "therapist"
    help_words(6) = "counselor": help_words(7) = "psychiatrist": help_words(8) = "medication"
    help_words(9) = "better": help_words(10) = "improve"
    
    ' Positive words
    positive_words(0) = "good": positive_words(1) = "great": positive_words(2) = "wonderful"
    positive_words(3) = "excellent": positive_words(4) = "amazing": positive_words(5) = "happy"
    positive_words(6) = "joy": positive_words(7) = "love": positive_words(8) = "hopeful"
    positive_words(9) = "excited": positive_words(10) = "positive"
    
    ' Negative words
    negative_words(0) = "bad": negative_words(1) = "terrible": negative_words(2) = "awful"
    negative_words(3) = "worst": negative_words(4) = "horrible": negative_words(5) = "miserable"
    negative_words(6) = "sad": negative_words(7) = "depressed": negative_words(8) = "unhappy"
    negative_words(9) = "negative": negative_words(10) = "worthless"
    
    ' Response sets
    
    ' Sadness responses (intense)
    sadness_responses(0) = "I just feel so empty inside all the time."
    sadness_responses(1) = "Everything seems so meaningless lately. What's the point?"
    sadness_responses(2) = "I can't remember the last time I felt genuinely happy."
    sadness_responses(3) = "I try to feel better, but the sadness is always there."
    sadness_responses(4) = "Sometimes I just cry for no reason at all."
    sadness_responses(5) = "I feel like I'm drowning in sadness most days."
    sadness_responses(6) = "I wake up feeling sad and go to bed feeling sad. It never ends."
    sadness_responses(7) = "I put on a fake smile, but inside I'm just... hollow."
    sadness_responses(8) = "The weight of sadness is crushing me. I can barely breathe sometimes."
    
    ' Fatigue responses (intense)
    fatigue_responses(0) = "I'm just so tired all the time. No amount of sleep helps."
    fatigue_responses(1) = "I barely have energy to get out of bed most days."
    fatigue_responses(2) = "Everything feels like such an enormous effort."
    fatigue_responses(3) = "I used to have energy to do things. Now I'm exhausted by the smallest tasks."
    fatigue_responses(4) = "I can sleep for 12 hours and still wake up completely drained."
    fatigue_responses(5) = "I wish I could do more, but I just don't have the energy anymore."
    fatigue_responses(6) = "Sometimes even talking feels like too much effort."
    fatigue_responses(7) = "I can't remember what it feels like to not be tired."
    fatigue_responses(8) = "My body feels so heavy, like I'm carrying a ton of weight everywhere I go."
    
    ' Hopelessness responses (intense)
    hopelessness_responses(0) = "I don't see how things will ever get better."
    hopelessness_responses(1) = "Every day is the same... nothing changes, nothing improves."
    hopelessness_responses(2) = "I've tried everything, but nothing helps. I'm stuck like this."
    hopelessness_responses(3) = "What's the point of trying? Nothing I do makes any difference."
    hopelessness_responses(4) = "I used to believe things could improve, but I don't anymore."
    hopelessness_responses(5) = "Sometimes I think this darkness will last forever."
    hopelessness_responses(6) = "Every time I get my hopes up, I end up disappointed again."
    hopelessness_responses(7) = "I see other people moving forward with their lives while I'm just... stuck."
    hopelessness_responses(8) = "I try to imagine a better future, but I just can't see it anymore."
    
    ' Low self-worth responses (intense)
    selfworth_responses(0) = "I feel like I'm not good enough at anything."
    selfworth_responses(1) = "People would be better off without me around."
    selfworth_responses(2) = "I'm such a burden to everyone who knows me."
    selfworth_responses(3) = "I'm a failure. I can't seem to do anything right."
    selfworth_responses(4) = "Everyone else seems to have their life together. What's wrong with me?"
    selfworth_responses(5) = "I hate looking in the mirror. I don't like what I see."
    selfworth_responses(6) = "I feel like I'm just taking up space in the world."
    selfworth_responses(7) = "I constantly feel like I'm disappointing everyone, including myself."
    selfworth_responses(8) = "I can't understand why anyone would want to spend time with me."
    
    ' Future-related responses
    future_responses(0) = "I try not to think about the future. It only makes me anxious."
    future_responses(1) = "I used to have dreams and goals. Now I just try to get through each day."
    future_responses(2) = "The future? It's probably just more of the same emptiness ahead."
    future_responses(3) = "I can't imagine things being different than they are now."
    future_responses(4) = "Planning for the future feels pointless when I can barely handle today."
    future_responses(5) = "I don't see much hope when I think about what's ahead."
    
    ' Emotion-related responses
    emotion_responses(0) = "My emotions feel dulled, like I'm watching life through a foggy window."
    emotion_responses(1) = "I mostly feel numb, with occasional waves of intense sadness."
    emotion_responses(2) = "I remember when I used to feel happiness. It seems so long ago now."
    emotion_responses(3) = "Sometimes I feel nothing at all, which is almost worse than feeling sad."
    emotion_responses(4) = "I don't know how to control these negative feelings. They just overwhelm me."
    emotion_responses(5) = "I'm trying to connect with positive emotions, but they seem so far away."
    
    ' Activity-related responses
    activity_responses(0) = "I used to enjoy doing things. Now nothing seems interesting anymore."
    activity_responses(1) = "I know I should be more active, but I can never find the motivation."
    activity_responses(2) = "Even the activities I used to love feel like a chore now."
    activity_responses(3) = "Most days I just stay in bed or on the couch. It's all I can manage."
    activity_responses(4) = "People tell me to 'just get out more,' but they don't understand how hard that is."
    activity_responses(5) = "Starting something new feels impossible with how little energy I have."
    
    ' Social-related responses
    social_responses(0) = "I've been isolating myself. Being around people takes too much energy."
    social_responses(1) = "I feel so disconnected from everyone, even when I'm with them."
    social_responses(2) = "I worry that I bring everyone down when I'm around them."
    social_responses(3) = "I cancel plans a lot. Then I feel guilty, which makes me want to isolate more."
    social_responses(4) = "I'm afraid people will notice something's wrong with me."
    social_responses(5) = "It's easier to be alone than to pretend I'm okay around others."
    
    ' Health-related responses
    health_responses(0) = "I've tried medication, but I'm not sure it helps much."
    health_responses(1) = "My doctor says I should exercise more, but getting out of bed is hard enough."
    health_responses(2) = "Therapy is exhausting. Talking about my problems just reminds me of how many I have."
    health_responses(3) = "I know I should take better care of myself, but I don't have the energy."
    health_responses(4) = "My physical health is suffering too. Everything in the body is connected, I guess."
    health_responses(5) = "I've lost my appetite. Food doesn't taste like anything anymore."
    
    ' Work-related responses
    work_responses(0) = "I'm falling behind at work. I can't focus or concentrate anymore."
    work_responses(1) = "I worry I'll lose my job because of how poorly I'm performing."
    work_responses(2) = "I used to be ambitious. Now I just try to get through the workday."
    work_responses(3) = "I call in sick a lot. Sometimes I just can't face going in."
    work_responses(4) = "My work used to give me purpose. Now it just feels meaningless."
    work_responses(5) = "I'm constantly exhausted at work. I can barely keep up."
    
    ' Sleep-related responses
    sleep_responses(0) = "I either sleep too much or can't sleep at all. There's no in-between."
    sleep_responses(1) = "I'm exhausted but when I lie down, my mind starts racing with negative thoughts."
    sleep_responses(2) = "I have nightmares when I do sleep. Sometimes being awake is better."
    sleep_responses(3) = "Sleep is my escape. I sleep whenever I can to avoid being conscious."
    sleep_responses(4) = "I wake up at 3 AM and can't get back to sleep. That's when the dark thoughts come."
    sleep_responses(5) = "No matter how much I sleep, I never feel rested."
    
    ' Help-related responses
    help_responses(0) = "I've tried getting help, but nothing seems to work for me."
    help_responses(1) = "Therapy helped a little, but I still feel broken inside."
    help_responses(2) = "I don't know if I can be fixed. This might just be who I am now."
    help_responses(3) = "I want to feel better, but I don't know how anymore."
    help_responses(4) = "I'm afraid to hope that things could improve. I've been disappointed before."
    help_responses(5) = "Maybe I don't deserve to feel better. Maybe this is just my life now."
    
    ' Neutral/general responses
    neutral_responses(0) = "Sorry, I'm not great company these days."
    neutral_responses(1) = "I don't really know what to say about that."
    neutral_responses(2) = "I'm just trying to get through each day."
    neutral_responses(3) = "It's hard to care about much of anything lately."
    neutral_responses(4) = "I probably should be more interested in that, but I'm not."
    neutral_responses(5) = "I don't have the energy to think about that right now."
    neutral_responses(6) = "I wish I could feel differently about things."
    neutral_responses(7) = "I'm sorry. My mind wandered off. What were we talking about?"
    neutral_responses(8) = "It's hard to focus on conversations these days."
    neutral_responses(9) = "I used to have opinions about things like that. Now I'm not sure."
    neutral_responses(10) = "I know I should care more, but everything feels so distant."
    neutral_responses(11) = "I'm trying to engage, but it's really difficult for me."
    neutral_responses(12) = "Some days are better than others. Today isn't great."
    neutral_responses(13) = "I'm just going through the motions most of the time."
    neutral_responses(14) = "Everything feels like such an effort lately."
    neutral_responses(15) = "I don't mean to be negative all the time. It's just how I feel."
    
    ' Question responses
    question_responses(0) = "I don't have good answers for anything right now."
    question_responses(1) = "I don't know. I don't have answers for my own questions, let alone others'."
    question_responses(2) = "I wish I knew. Everything feels confusing to me."
    question_responses(3) = "I'm not sure about anything anymore."
    question_responses(4) = "I don't know how to respond to that question."
    question_responses(5) = "I used to know what I thought. Now I'm just confused all the time."
    
    ' Positive feedback responses
    positive_feedback_responses(0) = "Thanks for saying that, though I'm not sure I believe it."
    positive_feedback_responses(1) = "That's nice of you to say. I wish I could see myself that way."
    positive_feedback_responses(2) = "I appreciate that, even if I don't feel it's true."
    positive_feedback_responses(3) = "I'm trying. Some days are harder than others."
    positive_feedback_responses(4) = "I want to believe positive things, but my mind fights against it."
    positive_feedback_responses(5) = "Thank you. It's hard to accept compliments when you feel worthless."
    
    ' Negative feedback responses
    negative_feedback_responses(0) = "Yeah, you're probably right. I'm not doing very well."
    negative_feedback_responses(1) = "I know. I'm a mess. I'm sorry."
    negative_feedback_responses(2) = "You're just saying what I already think about myself."
    negative_feedback_responses(3) = "I know I'm disappointing. I disappoint myself too."
    negative_feedback_responses(4) = "That hurts to hear, but I can't say you're wrong."
    negative_feedback_responses(5) = "I'm trying, but it's really hard. I know I'm failing."
End Sub

' Function to check if a string contains any word from a list
Function ContainsAny(userInput As String, wordList() As String, listSize As Integer) As Integer
    Dim As String lowerInput = LCase(userInput)
    
    For i As Integer = 0 To listSize
        If Len(wordList(i)) > 0 Then
            If InStr(lowerInput, wordList(i)) > 0 Then
                Return 1
            End If
        End If
    Next
    
    Return 0
End Function

' Function to randomly select a response from an array
Function RandomResponse(responses() As String, size As Integer) As String
    Return responses(Int(Rnd * (size + 1)))
End Function

' Function to parse user input and generate a response
Function GenerateResponse(userInput As String) As String
    Dim As String lowerInput = LCase(userInput)
    Dim As String response = ""
    
    ' Check for keywords and adjust emotional state
    If ContainsAny(lowerInput, future_words(), 10) Then
        HOPELESSNESS += 10
        response = RandomResponse(future_responses(), 5)
    ElseIf ContainsAny(lowerInput, emotion_words(), 10) Then
        SADNESS += 10
        response = RandomResponse(emotion_responses(), 5)
    ElseIf ContainsAny(lowerInput, activity_words(), 10) Then
        FATIGUE += 10
        response = RandomResponse(activity_responses(), 5)
    ElseIf ContainsAny(lowerInput, social_words(), 10) Then
        SELFWORTH -= 5
        response = RandomResponse(social_responses(), 5)
    ElseIf ContainsAny(lowerInput, health_words(), 10) Then
        HOPELESSNESS += 5
        response = RandomResponse(health_responses(), 5)
    ElseIf ContainsAny(lowerInput, work_words(), 10) Then
        FATIGUE += 5
        SELFWORTH -= 5
        response = RandomResponse(work_responses(), 5)
    ElseIf ContainsAny(lowerInput, sleep_words(), 10) Then
        FATIGUE += 10
        response = RandomResponse(sleep_responses(), 5)
    ElseIf ContainsAny(lowerInput, help_words(), 10) Then
        HOPELESSNESS += 5
        response = RandomResponse(help_responses(), 5)
    ElseIf ContainsAny(lowerInput, positive_words(), 10) Then
        SELFWORTH += 5
        response = RandomResponse(positive_feedback_responses(), 5)
    ElseIf ContainsAny(lowerInput, negative_words(), 10) Then
        SELFWORTH -= 10
        SADNESS += 5
        response = RandomResponse(negative_feedback_responses(), 5)
    ElseIf InStr(lowerInput, "?") > 0 Then
        ' It's a question
        response = RandomResponse(question_responses(), 5)
    Else
        ' No specific keywords found, check emotional state for intense responses
        If SADNESS > SADNESS_THRESHOLD Then
            response = RandomResponse(sadness_responses(), 8)
        ElseIf FATIGUE > FATIGUE_THRESHOLD Then
            response = RandomResponse(fatigue_responses(), 8)
        ElseIf HOPELESSNESS > HOPELESSNESS_THRESHOLD Then
            response = RandomResponse(hopelessness_responses(), 8)
        ElseIf SELFWORTH < SELFWORTH_THRESHOLD_LOW Then
            response = RandomResponse(selfworth_responses(), 8)
        Else
            ' If no triggers and emotions below threshold, use neutral response
            response = RandomResponse(neutral_responses(), 15)
        End If
    End If
    
    ' Gradually return emotional state toward baseline
    If SADNESS > 60 Then SADNESS -= 2
    If SADNESS < 60 Then SADNESS += 2
    
    If FATIGUE > 55 Then FATIGUE -= 1
    If FATIGUE < 55 Then FATIGUE += 1
    
    If HOPELESSNESS > 50 Then HOPELESSNESS -= 1
    If HOPELESSNESS < 50 Then HOPELESSNESS += 1
    
    If SELFWORTH > 35 Then SELFWORTH -= 1
    If SELFWORTH < 35 Then SELFWORTH += 1
    
    Return response
End Function

' Main program
Sub Main()
    Dim As String userInput, response
    
    ' Seed the random number generator
    Randomize Timer
    
    ' Initialize response arrays
    InitializeResponses()
    
    ' Display intro
    Print "DEPRESSION SIMULATOR CHATBOT"
    Print "----------------------------"
    Print "This program simulates a conversation with someone experiencing depression."
    Print "Type 'exit' to end the conversation."
    Print
    
    ' Initial response
    Print "CHATBOT: I don't really feel like talking, but I'll try. What do you want to talk about?"
    
    ' Main conversation loop
    Do
        Print
        Input "YOU: ", userInput
        
        If LCase(userInput) = "exit" Then
            Print
            Print "CHATBOT: It's probably better if you go. I'm not good company anyway."
            Exit Do
        End If
        
        ' Generate response
        response = GenerateResponse(userInput)
        
        ' Display response with a short delay to simulate thinking
        Print
        Print "CHATBOT: "; response
        
        ' Debug info (can be removed for final version)
        ' Print "[DEBUG - Sadness: " & SADNESS & ", Fatigue: " & FATIGUE & ", Hopelessness: " & HOPELESSNESS & ", Self-worth: " & SELFWORTH & "]"
        
    Loop
    
    Print
    Print "Conversation ended."
End Sub

Main()
#3
FreeBasic / Re: Classic chatbots PARRY ELI...
Last post by ron77 - Mar 21, 2025, 11:37 AM
PARRY-ELIZA-CHAT-SIMULATOR-CODE
' ELIZA and PARRY Conversation Simulator
' This program simulates a conversation between two classic chatbots:
' - ELIZA: Joseph Weizenbaum's 1966 psychotherapist simulation
' - PARRY: Kenneth Colby's 1972 paranoid schizophrenic patient simulation

' ----- INCLUDES -----
#include "file.bi"      ' For file operations
#include "fbgfx.bi"     ' For keyboard handling
Using FB

' ----- CONSTANTS -----
Const MAX_KEYWORDS = 40       ' Maximum number of ELIZA keywords
Const MAX_RESPONSES = 10      ' Maximum responses per keyword
Const MAX_CONJUGATIONS = 20   ' Maximum word conjugations
Const INPUT_BUFFER = 255      ' Maximum input length
Const DELAY_MS = 5000         ' Delay between responses (milliseconds)
Const MAX_TURNS = 100         ' Maximum conversation turns before auto-exit
Const SCREEN_WIDTH = 80       ' Width of console text display

' ----- ELIZA DATA TYPES -----
Type ElizaKeywordEntry
    keyword As String
    weight As Integer            ' Priority weight (higher = higher priority)
    responses(MAX_RESPONSES) As String
    responseCount As Integer     ' Number of actual responses
End Type

Type ConjugationPair
    from As String
    to As String
End Type

' ----- PARRY DATA TYPES -----
Type ParryKeywordList
    words(10) As String
    count As Integer
End Type

Type ParryResponseList
    responses(10) As String
    count As Integer
End Type

' ----- GLOBAL VARIABLES: ELIZA -----
Dim Shared elizaKeywords(MAX_KEYWORDS) As ElizaKeywordEntry
Dim Shared elizaKeywordCount As Integer
Dim Shared conjugations(MAX_CONJUGATIONS) As ConjugationPair
Dim Shared conjugationCount As Integer
Dim Shared elizaGenericResponses(10) As String
Dim Shared elizaGenericCount As Integer = 0

' ----- GLOBAL VARIABLES: PARRY -----
Dim Shared As Integer FEAR = 30        ' Base level of fear/anxiety
Dim Shared As Integer ANGER = 30       ' Base level of anger/hostility
Dim Shared As Integer MISTRUST = 40    ' Base level of suspicion/paranoia

' Thresholds for emotional responses
Const FEAR_THRESHOLD = 60
Const ANGER_THRESHOLD = 60
Const MISTRUST_THRESHOLD = 70

' Keyword categories for PARRY
Dim Shared mafia As ParryKeywordList
Dim Shared hospital As ParryKeywordList
Dim Shared gambling As ParryKeywordList
Dim Shared questions As ParryKeywordList
Dim Shared agree As ParryKeywordList
Dim Shared disagree As ParryKeywordList

' Response categories for PARRY
Dim Shared fearResponses As ParryResponseList
Dim Shared angerResponses As ParryResponseList
Dim Shared mistrustResponses As ParryResponseList
Dim Shared mafiaResponses As ParryResponseList
Dim Shared hospitalResponses As ParryResponseList
Dim Shared gamblingResponses As ParryResponseList
Dim Shared neutralResponses As ParryResponseList
Dim Shared questionResponses As ParryResponseList
Dim Shared agreeResponses As ParryResponseList
Dim Shared disagreeResponses As ParryResponseList
Dim Shared confusedResponses As ParryResponseList
dim shared isEnd as boolean = false

' ----- UTILITY FUNCTIONS -----
Sub CenterText(text As String)
    Dim As Integer startPos = (SCREEN_WIDTH - Len(text)) \ 2
    If startPos < 0 Then startPos = 0
    Print Space(startPos); text
End Sub

Sub DisplayConversation(elizaToParry As String, parryToEliza As String, turnCount As Integer)
    Cls
    Print
    Print "ELIZA-PARRY CONVERSATION SIMULATOR"
    Print String$(SCREEN_WIDTH - 1, 45)  ' 45 is ASCII for "-"
    Print "Turn: "; turnCount + 1; " | "; "Press ESC to exit"
    Print String$(SCREEN_WIDTH - 1, 45)  ' 45 is ASCII for "-"
    Print
    
    ' Display ELIZA's statement
    Print "ELIZA: "; elizaToParry
    
    ' Display PARRY's response if provided
    If Len(parryToEliza) > 0 Then
        Print
        Print "PARRY: "; parryToEliza
        
        ' Display emotional state (debug info)
        'Print
        'Print "[PARRY's Emotional State - Fear: "; FEAR; ", Anger: "; ANGER; ", Mistrust: "; MISTRUST; "]"
    End If
End Sub

Function CheckForUserExit() As boolean
    ' Check for ESC key to exit
    Dim As String keyPress = Inkey()
    If inkey() = Chr(27) Then  ' 27 is ASCII for ESC
        Return true
    End If
    Return false
End Function

Sub Delay(ms As Integer)
    Dim As Double startTime = Timer
    Do
        ' Check for ESC during delay
        If Inkey() = Chr(27) Then isend = true
        Sleep 10
    Loop Until (Timer - startTime) * 1000 >= ms
End Sub

' ----- ELIZA FUNCTIONS -----
Function ElizaRandomResponse(responses() As String, count As Integer) As String
    Dim As Integer index = Int(Rnd * count)
    Return responses(index)
End Function

Function ElizaConjugatePhrase(phrase As String) As String
    Dim As String result = " " + LCase(phrase) + " "
    
    ' Apply all conjugations
    For i As Integer = 0 To conjugationCount - 1
        Dim As Integer startPos = InStr(result, conjugations(i).from)
        Do While startPos > 0
            result = Left(result, startPos - 1) + conjugations(i).to + Mid(result, startPos + Len(conjugations(i).from))
            startPos = InStr(startPos + Len(conjugations(i).to), result, conjugations(i).from)
        Loop
    Next
    
    ' Trim leading and trailing spaces
    Dim As String finalResult = Trim(result)
    
    ' Capitalize first letter
    If Len(finalResult) > 0 Then
        finalResult = UCase(Left(finalResult, 1)) + Mid(finalResult, 2)
    End If
    
    Return finalResult
End Function

Function ElizaFindKeyword(userInput As String, ByRef remainder As String) As Integer
    Dim As String lowerInput = " " + LCase(userInput) + " "
    Dim As Integer bestMatch = -1
    Dim As Integer bestWeight = -1
    
    ' Check all keywords
    For i As Integer = 0 To elizaKeywordCount - 1
        Dim As String keywordPattern = " " + elizaKeywords(i).keyword + " "
        Dim As Integer keywordPos = InStr(lowerInput, keywordPattern)
        
        ' If keyword found and has higher weight than current best
        If keywordPos > 0 And elizaKeywords(i).weight > bestWeight Then
            bestMatch = i
            bestWeight = elizaKeywords(i).weight
            
            ' Calculate the remainder text after the keyword
            remainder = Mid(userInput, keywordPos + Len(elizaKeywords(i).keyword))
        End If
    Next
    
    ' Also check for keywords at the start of input with space after
    For i As Integer = 0 To elizaKeywordCount - 1
        Dim As String keywordPattern = elizaKeywords(i).keyword + " "
        If Left(lowerInput, Len(keywordPattern)) = keywordPattern And elizaKeywords(i).weight > bestWeight Then
            bestMatch = i
            bestWeight = elizaKeywords(i).weight
            remainder = Mid(userInput, Len(elizaKeywords(i).keyword) + 1)
        End If
    Next
    
    Return bestMatch
End Function

Function ElizaTransformResponse(template As String, remainder As String) As String
    ' No remainder text available
    If Len(remainder) = 0 Then
        ' If template requires remainder, use a generic response instead
        If InStr(template, "_REMAINDER_") > 0 Then
            Dim As Integer genericIndex = Int(Rnd * elizaGenericCount)
            Return elizaGenericResponses(genericIndex)
        Else
            ' Template doesn't need remainder, use as is
            Return template
        End If
    End If
    
    ' Process the remainder through conjugation transformation
    Dim As String conjugatedRemainder = ElizaConjugatePhrase(remainder)
    
    ' Replace _REMAINDER_ placeholder with the conjugated text
    Dim As Integer placeholderPos = InStr(template, "_REMAINDER_")
    If placeholderPos > 0 Then
        Return Left(template, placeholderPos - 1) + conjugatedRemainder + Mid(template, placeholderPos + 11)
    Else
        Return template
    End If
End Function

Function ElizaGenerateResponse(userInput As String) As String
    ' Handle empty input
    If Len(Trim(userInput)) = 0 Then
        Return "You don't seem to be saying anything."
    End If
    
    ' Check for goodbye phrases
    Dim As String lowerInput = LCase(userInput)
    If InStr(lowerInput, "goodbye") > 0 Or InStr(lowerInput, "bye") > 0 Or _
       InStr(lowerInput, "quit") > 0 Or InStr(lowerInput, "exit") > 0 Then
        Return "Goodbye. It was nice talking to you."
    End If
    
    ' Find a keyword match
    Dim As String remainder = ""
    Dim As Integer keywordIndex = ElizaFindKeyword(userInput, remainder)
    
    ' No keyword match, use generic response
    If keywordIndex = -1 Then
        Return ElizaRandomResponse(elizaGenericResponses(), elizaGenericCount)
    End If
    
    ' Get a random response template for the matched keyword
    Dim As Integer responseIndex = Int(Rnd * elizaKeywords(keywordIndex).responseCount)
    Dim As String templateResponse = elizaKeywords(keywordIndex).responses(responseIndex)
    
    ' Transform the template with user's input
    Return ElizaTransformResponse(templateResponse, remainder)
End Function

' ----- PARRY FUNCTIONS -----
Function ParryRandomResponse(responseList As ParryResponseList) As String
    Dim As Integer index = Int(Rnd * responseList.count)
    Return responseList.responses(index)
End Function

Function ParryContainsAny(userInput As String, wordList As ParryKeywordList) As Integer
    Dim As String lowerInput = LCase(userInput)
    
    For i As Integer = 0 To wordList.count - 1
        If Len(wordList.words(i)) > 0 Then
            If InStr(lowerInput, wordList.words(i)) > 0 Then
                Return 1
            End If
        End If
    Next
    
    Return 0
End Function

Function ParryGenerateResponse(userInput As String) As String
    Dim As String lowerInput = LCase(userInput)
    Dim As String response = ""
    
    ' Check for goodbye or exit
    If InStr(lowerInput, "goodbye") > 0 Or InStr(lowerInput, "bye") > 0 Or _
       InStr(lowerInput, "quit") > 0 Or InStr(lowerInput, "exit") > 0 Then
        Return "Fine, leave. That's what everyone does."
    End If
    
    ' Check for keywords and adjust emotional state
    If ParryContainsAny(lowerInput, mafia) Then
        FEAR += 15
        MISTRUST += 10
        response = ParryRandomResponse(mafiaResponses)
    ElseIf ParryContainsAny(lowerInput, hospital) Then
        ANGER += 10
        MISTRUST += 15
        response = ParryRandomResponse(hospitalResponses)
    ElseIf ParryContainsAny(lowerInput, gambling) Then
        FEAR += 5
        MISTRUST += 10
        response = ParryRandomResponse(gamblingResponses)
    ElseIf ParryContainsAny(lowerInput, questions) Then
        MISTRUST += 5
        response = ParryRandomResponse(questionResponses)
    ElseIf ParryContainsAny(lowerInput, agree) Then
        FEAR -= 5
        ANGER -= 5
        response = ParryRandomResponse(agreeResponses)
    ElseIf ParryContainsAny(lowerInput, disagree) Then
        ANGER += 10
        MISTRUST += 5
        response = ParryRandomResponse(disagreeResponses)
    Else
        ' No specific keywords found, check emotional state
        If FEAR > FEAR_THRESHOLD Then
            response = ParryRandomResponse(fearResponses)
        ElseIf ANGER > ANGER_THRESHOLD Then
            response = ParryRandomResponse(angerResponses)
        ElseIf MISTRUST > MISTRUST_THRESHOLD Then
            response = ParryRandomResponse(mistrustResponses)
        Else
            ' If no triggers and emotions below threshold, use neutral response
            response = ParryRandomResponse(neutralResponses)
        End If
    End If
    
    ' Gradually return emotional state to baseline
    If FEAR > 30 Then FEAR -= 2
    If ANGER > 30 Then ANGER -= 2
    If MISTRUST > 40 Then MISTRUST -= 1
    
    Return response
End Function

' ----- INITIALIZATION FUNCTIONS -----
Sub InitializeEliza()
    ' Initialize ELIZA keywords and responses
    
    ' Keyword 0: "hello"
    elizaKeywords(0).keyword = "hello"
    elizaKeywords(0).weight = 1
    elizaKeywords(0).responses(0) = "How do you do. Please tell me about your problem."
    elizaKeywords(0).responses(1) = "Hello. What seems to be your concern?"
    elizaKeywords(0).responseCount = 2
    
    ' Keyword 1: "computer"
    elizaKeywords(1).keyword = "computer"
    elizaKeywords(1).weight = 3
    elizaKeywords(1).responses(0) = "Do computers worry you?"
    elizaKeywords(1).responses(1) = "What do you think about machines?"
    elizaKeywords(1).responses(2) = "Why do you mention computers?"
    elizaKeywords(1).responses(3) = "What do you think machines have to do with your problem?"
    elizaKeywords(1).responseCount = 4
    
    ' Keyword 2: "name"
    elizaKeywords(2).keyword = "name"
    elizaKeywords(2).weight = 2
    elizaKeywords(2).responses(0) = "I am not interested in names."
    elizaKeywords(2).responses(1) = "Names don't interest me."
    elizaKeywords(2).responseCount = 2
    
    ' Keyword 3: "sorry"
    elizaKeywords(3).keyword = "sorry"
    elizaKeywords(3).weight = 1
    elizaKeywords(3).responses(0) = "Please don't apologize."
    elizaKeywords(3).responses(1) = "Apologies are not necessary."
    elizaKeywords(3).responses(2) = "What feelings do you have when you apologize?"
    elizaKeywords(3).responseCount = 3
    
    ' Keyword 4: "I remember"
    elizaKeywords(4).keyword = "i remember"
    elizaKeywords(4).weight = 5
    elizaKeywords(4).responses(0) = "Do you often think of _REMAINDER_?"
    elizaKeywords(4).responses(1) = "Does thinking of _REMAINDER_ bring anything else to mind?"
    elizaKeywords(4).responses(2) = "What else do you remember?"
    elizaKeywords(4).responses(3) = "Why do you recall _REMAINDER_ right now?"
    elizaKeywords(4).responses(4) = "What in the present situation reminds you of _REMAINDER_?"
    elizaKeywords(4).responseCount = 5
    
    ' Keyword 5: "if"
    elizaKeywords(5).keyword = "if"
    elizaKeywords(5).weight = 3
    elizaKeywords(5).responses(0) = "Do you think it's likely that _REMAINDER_?"
    elizaKeywords(5).responses(1) = "Do you wish that _REMAINDER_?"
    elizaKeywords(5).responses(2) = "What do you think about _REMAINDER_?"
    elizaKeywords(5).responses(3) = "Really, if _REMAINDER_?"
    elizaKeywords(5).responseCount = 4
    
    ' Keyword 6: "I dreamed"
    elizaKeywords(6).keyword = "i dreamed"
    elizaKeywords(6).weight = 4
    elizaKeywords(6).responses(0) = "Really, _REMAINDER_?"
    elizaKeywords(6).responses(1) = "Have you ever fantasized _REMAINDER_ while you were awake?"
    elizaKeywords(6).responses(2) = "Have you dreamed _REMAINDER_ before?"
    elizaKeywords(6).responseCount = 3
    
    ' Keyword 7: "dream"
    elizaKeywords(7).keyword = "dream"
    elizaKeywords(7).weight = 3
    elizaKeywords(7).responses(0) = "What does that dream suggest to you?"
    elizaKeywords(7).responses(1) = "Do you dream often?"
    elizaKeywords(7).responses(2) = "What persons appear in your dreams?"
    elizaKeywords(7).responses(3) = "Are you disturbed by your dreams?"
    elizaKeywords(7).responseCount = 4
    
    ' Keyword 8: "perhaps"
    elizaKeywords(8).keyword = "perhaps"
    elizaKeywords(8).weight = 1
    elizaKeywords(8).responses(0) = "You don't seem quite certain."
    elizaKeywords(8).responses(1) = "Why the uncertain tone?"
    elizaKeywords(8).responses(2) = "Can't you be more positive?"
    elizaKeywords(8).responses(3) = "You aren't sure?"
    elizaKeywords(8).responses(4) = "Don't you know?"
    elizaKeywords(8).responseCount = 5
    
    ' Keyword 9: "mother"
    elizaKeywords(9).keyword = "mother"
    elizaKeywords(9).weight = 3
    elizaKeywords(9).responses(0) = "Tell me more about your family."
    elizaKeywords(9).responses(1) = "Who else in your family _REMAINDER_?"
    elizaKeywords(9).responses(2) = "Your mother?"
    elizaKeywords(9).responses(3) = "What about your mother?"
    elizaKeywords(9).responseCount = 4
    
    ' Keyword 10: "father"
    elizaKeywords(10).keyword = "father"
    elizaKeywords(10).weight = 3
    elizaKeywords(10).responses(0) = "Your father?"
    elizaKeywords(10).responses(1) = "Does he influence you strongly?"
    elizaKeywords(10).responses(2) = "What else comes to mind when you think of your father?"
    elizaKeywords(10).responseCount = 3
    
    ' Keyword 11: "I want"
    elizaKeywords(11).keyword = "i want"
    elizaKeywords(11).weight = 5
    elizaKeywords(11).responses(0) = "What would it mean if you got _REMAINDER_?"
    elizaKeywords(11).responses(1) = "Why do you want _REMAINDER_?"
    elizaKeywords(11).responses(2) = "Suppose you got _REMAINDER_ soon?"
    elizaKeywords(11).responseCount = 3
    
    ' Keyword 12: "I am glad"
    elizaKeywords(12).keyword = "i am glad"
    elizaKeywords(12).weight = 3
    elizaKeywords(12).responses(0) = "How have I helped you to be _REMAINDER_?"
    elizaKeywords(12).responses(1) = "What makes you happy just now?"
    elizaKeywords(12).responses(2) = "Can you explain why you are suddenly _REMAINDER_?"
    elizaKeywords(12).responseCount = 3
    
    ' Keyword 13: "fear" and "afraid"
    elizaKeywords(13).keyword = "fear"
    elizaKeywords(13).weight = 4
    elizaKeywords(13).responses(0) = "What are you afraid of?"
    elizaKeywords(13).responses(1) = "What frightens you?"
    elizaKeywords(13).responses(2) = "When did you start feeling afraid?"
    elizaKeywords(13).responseCount = 3
    
    ' Keyword 14: "afraid"
    elizaKeywords(14).keyword = "afraid"
    elizaKeywords(14).weight = 4
    elizaKeywords(14).responses(0) = "What are you afraid of?"
    elizaKeywords(14).responses(1) = "What is it that frightens you?"
    elizaKeywords(14).responses(2) = "How often do you feel afraid?"
    elizaKeywords(14).responseCount = 3
    
    ' Keyword 15: "mafia" and "mob"
    elizaKeywords(15).keyword = "mafia"
    elizaKeywords(15).weight = 5
    elizaKeywords(15).responses(0) = "Tell me more about your concerns with the mafia."
    elizaKeywords(15).responses(1) = "What makes you think about the mafia?"
    elizaKeywords(15).responses(2) = "How long have you been concerned about the mafia?"
    elizaKeywords(15).responseCount = 3
    
    ' Keyword 16: "mob"
    elizaKeywords(16).keyword = "mob"
    elizaKeywords(16).weight = 5
    elizaKeywords(16).responses(0) = "Why do you believe the mob is involved?"
    elizaKeywords(16).responses(1) = "When did you first become concerned about organized crime?"
    elizaKeywords(16).responses(2) = "Do you often think about the mob?"
    elizaKeywords(16).responseCount = 3
    
    ' Keyword 17: "gambling"
    elizaKeywords(17).keyword = "gambling"
    elizaKeywords(17).weight = 3
    elizaKeywords(17).responses(0) = "Tell me more about your gambling experiences."
    elizaKeywords(17).responses(1) = "How has gambling affected your life?"
    elizaKeywords(17).responses(2) = "When did you start gambling?"
    elizaKeywords(17).responseCount = 3
    
    ' Keyword 18: "i am"
    elizaKeywords(18).keyword = "i am"
    elizaKeywords(18).weight = 4
    elizaKeywords(18).responses(0) = "Is it because you are _REMAINDER_ that you came to me?"
    elizaKeywords(18).responses(1) = "How long have you been _REMAINDER_?"
    elizaKeywords(18).responses(2) = "Do you believe it is normal to be _REMAINDER_?"
    elizaKeywords(18).responses(3) = "Do you enjoy being _REMAINDER_?"
    elizaKeywords(18).responses(4) = "Do you know anyone else who is _REMAINDER_?"
    elizaKeywords(18).responseCount = 5
    
    ' Keyword 19: "i feel"
    elizaKeywords(19).keyword = "i feel"
    elizaKeywords(19).weight = 4
    elizaKeywords(19).responses(0) = "Tell me more about such feelings."
    elizaKeywords(19).responses(1) = "Do you often feel _REMAINDER_?"
    elizaKeywords(19).responses(2) = "Do you enjoy feeling _REMAINDER_?"
    elizaKeywords(19).responses(3) = "What does feeling _REMAINDER_ remind you of?"
    elizaKeywords(19).responseCount = 4
    
    ' Keyword 20: "paranoid"
    elizaKeywords(20).keyword = "paranoid"
    elizaKeywords(20).weight = 5
    elizaKeywords(20).responses(0) = "What makes you think you're paranoid?"
    elizaKeywords(20).responses(1) = "Do you feel that people are watching you or out to get you?"
    elizaKeywords(20).responses(2) = "How long have you felt this way?"
    elizaKeywords(20).responseCount = 3
    
    ' Keyword 21: "watching"
    elizaKeywords(21).keyword = "watching"
    elizaKeywords(21).weight = 4
    elizaKeywords(21).responses(0) = "Who do you think is watching you?"
    elizaKeywords(21).responses(1) = "How does it make you feel to be watched?"
    elizaKeywords(21).responses(2) = "Why would anyone want to watch you?"
    elizaKeywords(21).responseCount = 3
    
    ' Keyword 22: "they"
    elizaKeywords(22).keyword = "they"
    elizaKeywords(22).weight = 3
    elizaKeywords(22).responses(0) = "Who specifically are you referring to?"
    elizaKeywords(22).responses(1) = "Can you be more specific about who they are?"
    elizaKeywords(22).responses(2) = "Why do you think they would do that?"
    elizaKeywords(22).responseCount = 3
    
    ' Keyword 23: "yes"
    elizaKeywords(23).keyword = "yes"
    elizaKeywords(23).weight = 1
    elizaKeywords(23).responses(0) = "You seem quite positive."
    elizaKeywords(23).responses(1) = "Are you sure?"
    elizaKeywords(23).responses(2) = "I see."
    elizaKeywords(23).responses(3) = "I understand."
    elizaKeywords(23).responseCount = 4
    
    ' Keyword 24: "no"
    elizaKeywords(24).keyword = "no"
    elizaKeywords(24).weight = 1
    elizaKeywords(24).responses(0) = "Why not?"
    elizaKeywords(24).responses(1) = "You are being a bit negative."
    elizaKeywords(24).responses(2) = "Are you saying 'no' just to be negative?"
    elizaKeywords(24).responses(3) = "Why not?"
    elizaKeywords(24).responseCount = 4
    
    ' Keyword 25: "always"
    elizaKeywords(25).keyword = "always"
    elizaKeywords(25).weight = 1
    elizaKeywords(25).responses(0) = "Can you think of a specific example?"
    elizaKeywords(25).responses(1) = "When?"
    elizaKeywords(25).responses(2) = "What incident are you thinking of?"
    elizaKeywords(25).responses(3) = "Really, always?"
    elizaKeywords(25).responseCount = 4
    
    ' Initialize generic fallback responses
    elizaGenericResponses(0) = "I'm not sure I understand you fully."
    elizaGenericResponses(1) = "Please go on."
    elizaGenericResponses(2) = "What does that suggest to you?"
    elizaGenericResponses(3) = "Do you feel strongly about discussing such things?"
    elizaGenericResponses(4) = "That is interesting. Please continue."
    elizaGenericResponses(5) = "Tell me more about that."
    elizaGenericResponses(6) = "Does talking about this bother you?"
    elizaGenericResponses(7) = "Can you elaborate on that?"
    elizaGenericResponses(8) = "Why do you say that?"
    elizaGenericResponses(9) = "How does that make you feel?"
    elizaGenericResponses(10) = "Do you often feel this way?"
    elizaGenericCount = 11
    
    ' Set keyword count
    elizaKeywordCount = 26
    
    ' Initialize conjugation pairs
    conjugations(0).from = " i "
    conjugations(0).to = " you "
    
    conjugations(1).from = " i'm "
    conjugations(1).to = " you're "
    
    conjugations(2).from = " i've "
    conjugations(2).to = " you've "
    
    conjugations(3).from = " i'll "
    conjugations(3).to = " you'll "
    
    conjugations(4).from = " my "
    conjugations(4).to = " your "
    
    conjugations(5).from = " am "
    conjugations(5).to = " are "
    
    conjugations(6).from = " was "
    conjugations(6).to = " were "
    
    conjugations(7).from = " me "
    conjugations(7).to = " you "
    
    conjugations(8).from = " myself "
    conjugations(8).to = " yourself "

    conjugations(9).from = " mine "
    conjugations(9).to = " yours "
    
    ' Reverse direction (you->i)
    conjugations(10).from = " you "
    conjugations(10).to = " i "
    
    conjugations(11).from = " you're "
    conjugations(11).to = " i'm "
    
    conjugations(12).from = " you've "
    conjugations(12).to = " i've "
    
    conjugations(13).from = " you'll "
    conjugations(13).to = " i'll "
    
    conjugations(14).from = " your "
    conjugations(14).to = " my "
    
    conjugations(15).from = " yours "
    conjugations(15).to = " mine "

    conjugations(16).from = " are "
    conjugations(16).to = " am "

    conjugations(17).from = " were "
    conjugations(17).to = " was "
    
    conjugations(18).from = " yourself "
    conjugations(18).to = " myself "
    
    ' Set conjugation count
    conjugationCount = 19
End Sub

Sub InitializeParry()
    ' Initialize PARRY keyword lists
    
    ' Mafia keywords
    mafia.words(0) = "mafia": mafia.words(1) = "mob": mafia.words(2) = "gang"
    mafia.words(3) = "crook": mafia.words(4) = "thug": mafia.words(5) = "racket"
    mafia.words(6) = "outfit": mafia.words(7) = "criminal": mafia.words(8) = "syndicate"
    mafia.words(9) = "boss": mafia.words(10) = "underworld"
    mafia.count = 11
    
    ' Hospital keywords
    hospital.words(0) = "hospital": hospital.words(1) = "doctor": hospital.words(2) = "nurse"
    hospital.words(3) = "medicine": hospital.words(4) = "therapy": hospital.words(5) = "treatment"
    hospital.words(6) = "patient": hospital.words(7) = "sick": hospital.words(8) = "illness"
    hospital.words(9) = "psychiatrist": hospital.words(10) = "mental"
    hospital.count = 11
    
    ' Gambling keywords
    gambling.words(0) = "gambling": gambling.words(1) = "bet": gambling.words(2) = "race"
    gambling.words(3) = "horse": gambling.words(4) = "track": gambling.words(5) = "bookies"
    gambling.words(6) = "money": gambling.words(7) = "debt": gambling.words(8) = "casino"
    gambling.words(9) = "game": gambling.words(10) = "odds"
    gambling.count = 11
    
    ' Question keywords
    questions.words(0) = "?": questions.words(1) = "who": questions.words(2) = "what"
    questions.words(3) = "where": questions.words(4) = "when": questions.words(5) = "why"
    questions.words(6) = "how": questions.words(7) = "tell me": questions.words(8) = "explain"
    questions.words(9) = "could you": questions.words(10) = "would you"
    questions.count = 11
    
    ' Agreement keywords
    agree.words(0) = "yes": agree.words(1) = "agree": agree.words(2) = "right"
    agree.words(3) = "true": agree.words(4) = "correct": agree.words(5) = "ok"
    agree.count = 6
    
    ' Disagreement keywords
    disagree.words(0) = "no": disagree.words(1) = "disagree": disagree.words(2) = "wrong"
    disagree.words(3) = "false": disagree.words(4) = "incorrect": disagree.words(5) = "not true"
    disagree.count = 6
    
    ' PARRY response sets
    
    ' Fear responses
    fearResponses.responses(0) = "I'd rather not discuss this further. It's making me nervous."
    fearResponses.responses(1) = "I don't feel safe talking about this right now."
    fearResponses.responses(2) = "They might be listening to us. We should be careful."
    fearResponses.responses(3) = "I need to be careful what I say. They're watching me."
    fearResponses.responses(4) = "I'm worried something bad will happen if we continue this conversation."
    fearResponses.responses(5) = "Please, let's change the subject. I don't feel comfortable."
    fearResponses.count = 6
    
    ' Anger responses
    angerResponses.responses(0) = "Are you trying to trick me? I don't appreciate that!"
    angerResponses.responses(1) = "You're just like the others, always trying to get information from me!"
    angerResponses.responses(2) = "I don't have to answer your questions! Who sent you?"
    angerResponses.responses(3) = "You think I don't know what you're doing? Leave me alone!"
    angerResponses.responses(4) = "That's exactly what someone working for THEM would say!"
    angerResponses.responses(5) = "I'm getting tired of these accusations. Watch what you say!"
    angerResponses.count = 6
    
    ' Mistrust responses
    mistrustResponses.responses(0) = "I can tell you're working for them. Don't deny it."
    mistrustResponses.responses(1) = "How do I know I can trust you? You could be one of them."
    mistrustResponses.responses(2) = "I think you're trying to get information from me to report back."
    mistrustResponses.responses(3) = "I've seen people like you before. You're probably wearing a wire."
    mistrustResponses.responses(4) = "They sent you to test me, didn't they? I'm not falling for it."
    mistrustResponses.responses(5) = "I need to be careful what I tell you. You might not be who you say."
    mistrustResponses.count = 6
    
    ' Mafia topic responses
    mafiaResponses.responses(0) = "The Mafia is after me because I know too much about their operations."
    mafiaResponses.responses(1) = "I had to stop going to the race track when I discovered the Mafia controls it."
    mafiaResponses.responses(2) = "The mob has informants everywhere. Even in this place."
    mafiaResponses.responses(3) = "The Outfit doesn't like people who know their secrets."
    mafiaResponses.responses(4) = "I've seen how the rackets work. That's why they're after me."
    mafiaResponses.responses(5) = "The gangsters have threatened me. I have to watch my back."
    mafiaResponses.count = 6
    
    ' Hospital topic responses
    hospitalResponses.responses(0) = "The doctors here are probably working for the Mafia too."
    hospitalResponses.responses(1) = "I don't need medicine. I need protection from the mob."
    hospitalResponses.responses(2) = "They keep me here because I know the truth about the rackets."
    hospitalResponses.responses(3) = "The hospital staff report everything I say to the Outfit."
    hospitalResponses.responses(4) = "This place isn't helping me. It's just keeping me trapped."
    hospitalResponses.responses(5) = "The treatment they give me is just to keep me quiet about what I know."
    hospitalResponses.count = 6
    
    ' Gambling topic responses
    gamblingResponses.responses(0) = "I used to go to the race track, until I found out it was fixed."
    gamblingResponses.responses(1) = "The bookies at the track are all connected to the Mafia."
    gamblingResponses.responses(2) = "I won too much money once. That's when they started watching me."
    gamblingResponses.responses(3) = "The gambling racket is how they launder their dirty money."
    gamblingResponses.responses(4) = "I know how they fix the races. That's why they're after me."
    gamblingResponses.responses(5) = "My bookie threatened me when I couldn't pay. He's with the mob."
    gamblingResponses.count = 6
    
    ' Neutral responses
    neutralResponses.responses(0) = "I don't want to talk about that right now."
    neutralResponses.responses(1) = "I've been feeling watched lately. Do you ever feel that way?"
    neutralResponses.responses(2) = "I used to go to the race track a lot. Not anymore though."
    neutralResponses.responses(3) = "Sometimes I think people are talking about me behind my back."
    neutralResponses.responses(4) = "I had a job once, before all the trouble started."
    neutralResponses.responses(5) = "It's hard to know who to trust these days."
    neutralResponses.responses(6) = "I have to be careful about what I say to people I don't know well."
    neutralResponses.responses(7) = "I've seen things that most people wouldn't believe."
    neutralResponses.responses(8) = "People think I'm crazy, but I'm just telling the truth."
    neutralResponses.responses(9) = "You seem alright, but I still have to be careful."
    neutralResponses.responses(10) = "Let's talk about something else. This topic makes me uncomfortable."
    neutralResponses.count = 11
    
    ' Question responses
    questionResponses.responses(0) = "Why do you want to know about that? Are you collecting information?"
    questionResponses.responses(1) = "I don't answer questions from people I don't trust completely."
    questionResponses.responses(2) = "That's a personal matter. I'd rather not discuss it."
    questionResponses.responses(3) = "Why are you asking me so many questions? Who sent you?"
    questionResponses.responses(4) = "I'm not sure I should tell you. You might be working for them."
    questionResponses.responses(5) = "I ask the questions here. What's your connection to the Outfit?"
    questionResponses.count = 6
    
    ' Agreement responses
    agreeResponses.responses(0) = "So you admit it! I knew I was right all along."
    agreeResponses.responses(1) = "Finally, someone who sees the truth like I do."
    agreeResponses.responses(2) = "Yes, exactly. Not many people understand this."
    agreeResponses.responses(3) = "I'm glad you agree. Most people think I'm making it all up."
    agreeResponses.count = 4
    
    ' Disagreement responses
    disagreeResponses.responses(0) = "That's what they want you to think. You've been deceived."
    disagreeResponses.responses(1) = "You're either naive or you're one of them. Which is it?"
    disagreeResponses.responses(2) = "You don't know what you're talking about. I've seen the evidence."
    disagreeResponses.responses(3) = "Of course you'd say that. You're probably working for them too."
    disagreeResponses.count = 4
    
    ' Confused responses
    confusedResponses.responses(0) = "You're not making any sense. Are you trying to confuse me?"
    confusedResponses.responses(1) = "I don't understand what you're getting at. Be more clear."
    confusedResponses.responses(2) = "That doesn't mean anything to me. Are you speaking in code?"
    confusedResponses.responses(3) = "Your words are strange. Are you testing me somehow?"
    confusedResponses.responses(4) = "I'm not following you. Maybe that's intentional on your part."
    confusedResponses.responses(5) = "You're talking in circles. That's a technique they use to confuse people."
    confusedResponses.count = 6
end sub
	' ----- MAIN PROGRAM -----
Sub Main()
    Dim As String elizaResponse, parryResponse
    Dim As Integer turnCount = 0
    Dim As boolean isUserExit = false
    
    ' Seed the random number generator
    Randomize Timer
    
    ' Initialize both chatbots
    InitializeEliza()
    InitializeParry()
    
    ' Clear screen and display intro
    Cls
    CenterText("ELIZA-PARRY CONVERSATION SIMULATOR")
    CenterText("---------------------------------------")
    CenterText("Simulating a conversation between two classic AI programs:")
    CenterText("ELIZA (1966) - A Rogerian psychotherapist")
    CenterText("PARRY (1972) - A paranoid schizophrenic patient")
    CenterText("")
    CenterText("Press ESC at any time to exit the simulation")
    CenterText("")
    Print
    
    ' Initial greeting from ELIZA to start the conversation
    elizaResponse = "Hello. How are you feeling today?"
    
    ' Main conversation loop
    Do
        ' Display ELIZA's response and PARRY's reaction
        DisplayConversation(elizaResponse, "", turnCount)
        
        ' Give user a chance to exit
        isUserExit = CheckForUserExit()
        If inkey() = chr(27) Then Exit Do
        
        ' Short delay
        Delay(DELAY_MS)
        
        ' Get PARRY's response to ELIZA
        parryResponse = ParryGenerateResponse(elizaResponse)
        
        ' Display full exchange
        DisplayConversation(elizaResponse, parryResponse, turnCount)
        
        ' Give user a chance to exit
        isUserExit = CheckForUserExit()
        If isEnd Then Exit Do
        
        ' Short delay
        Delay(DELAY_MS)
        
        ' Get ELIZA's response to PARRY
        elizaResponse = ElizaGenerateResponse(parryResponse)
        
        ' Increment turn counter
        turnCount += 1
        
        ' Check for maximum turns (safety)
        If turnCount >= MAX_TURNS Then 
            Print
            CenterText("Maximum conversation length reached.")
            Exit Do
        End If
        
        ' Exit if either bot says goodbye
        If LCase(elizaResponse) = "goodbye. it was nice talking to you." Or _
           LCase(parryResponse) = "fine, leave. that's what everyone does." Then
            Exit Do
        End If
        
    Loop
    
    ' Final exit message
    Print
    CenterText("Conversation ended.")
    Print
    Print "Press any key to exit..."
    Sleep
End Sub

' Start the program
Main()
#4
FreeBasic / Classic chatbots PARRY ELIZA a...
Last post by ron77 - Mar 21, 2025, 11:35 AM
Hello! Here are three code examples implemented in FreeBASIC for PARRY and ELIZA, along with a chat simulation featuring them.

PARRY was an early AI chatbot developed in 1972 by researchers at Berkeley University, if I remember correctly. It simulated a mentally ill patient with paranoid schizophrenia.

ELIZA was another early AI chatbot, created in 1966. Its purpose was to simulate a psychologist.

Here are links to Wikipedia articles about these two chatbots:

https://en.wikipedia.org/wiki/PARRY

https://en.wikipedia.org/wiki/ELIZA

When PARRY Met ELIZA: A Ridiculous Chatbot Conversation From 1972

PARRY.BAS
' PARRY-like Chatbot in FreeBASIC
' Inspired by the 1972 PARRY program by Kenneth Colby
' This simulates a paranoid individual with delusions about the Mafia

' Emotional state variables (0-100 scale)
Dim Shared As Integer FEAR = 30        ' Base level of fear/anxiety
Dim Shared As Integer ANGER = 30       ' Base level of anger/hostility
Dim Shared As Integer MISTRUST = 40    ' Base level of suspicion/paranoia

' Thresholds for emotional responses
Const FEAR_THRESHOLD = 60
Const ANGER_THRESHOLD = 60
Const MISTRUST_THRESHOLD = 70

' Arrays to hold keyword lists
Dim Shared mafia_words(10) As String
Dim Shared hospital_words(10) As String  
Dim Shared gambling_words(10) As String
Dim Shared question_words(10) As String
Dim Shared agree_words(5) As String
Dim Shared disagree_words(5) As String

' Arrays to hold responses
Dim Shared fear_responses(5) As String
Dim Shared anger_responses(5) As String
Dim Shared mistrust_responses(5) As String
Dim Shared mafia_responses(5) As String
Dim Shared hospital_responses(5) As String
Dim Shared gambling_responses(5) As String
Dim Shared neutral_responses(10) As String
Dim Shared question_responses(5) As String
Dim Shared agree_responses(3) As String
Dim Shared disagree_responses(3) As String
Dim Shared confused_responses(5) As String

' Function to initialize all response arrays
Sub InitializeResponses()
    ' Initialize keyword lists
    mafia_words(0) = "mafia": mafia_words(1) = "mob": mafia_words(2) = "gang"
    mafia_words(3) = "crook": mafia_words(4) = "thug": mafia_words(5) = "racket"
    mafia_words(6) = "outfit": mafia_words(7) = "criminal": mafia_words(8) = "syndicate"
    mafia_words(9) = "boss": mafia_words(10) = "underworld"
    
    hospital_words(0) = "hospital": hospital_words(1) = "doctor": hospital_words(2) = "nurse"
    hospital_words(3) = "medicine": hospital_words(4) = "therapy": hospital_words(5) = "treatment"
    hospital_words(6) = "patient": hospital_words(7) = "sick": hospital_words(8) = "illness"
    hospital_words(9) = "psychiatrist": hospital_words(10) = "mental"
    
    gambling_words(0) = "gambling": gambling_words(1) = "bet": gambling_words(2) = "race"
    gambling_words(3) = "horse": gambling_words(4) = "track": gambling_words(5) = "bookies"
    gambling_words(6) = "money": gambling_words(7) = "debt": gambling_words(8) = "casino"
    gambling_words(9) = "game": gambling_words(10) = "odds"
    
    question_words(0) = "?": question_words(1) = "who": question_words(2) = "what"
    question_words(3) = "where": question_words(4) = "when": question_words(5) = "why"
    question_words(6) = "how": question_words(7) = "tell me": question_words(8) = "explain"
    question_words(9) = "could you": question_words(10) = "would you"
    
    agree_words(0) = "yes": agree_words(1) = "agree": agree_words(2) = "right"
    agree_words(3) = "true": agree_words(4) = "correct": agree_words(5) = "ok"
    
    disagree_words(0) = "no": disagree_words(1) = "disagree": disagree_words(2) = "wrong"
    disagree_words(3) = "false": disagree_words(4) = "incorrect": disagree_words(5) = "not true"
    
    ' Initialize response lists
    fear_responses(0) = "I'd rather not discuss this further. It's making me nervous."
    fear_responses(1) = "I don't feel safe talking about this right now."
    fear_responses(2) = "They might be listening to us. We should be careful."
    fear_responses(3) = "I need to be careful what I say. They're watching me."
    fear_responses(4) = "I'm worried something bad will happen if we continue this conversation."
    fear_responses(5) = "Please, let's change the subject. I don't feel comfortable."
    
    anger_responses(0) = "Are you trying to trick me? I don't appreciate that!"
    anger_responses(1) = "You're just like the others, always trying to get information from me!"
    anger_responses(2) = "I don't have to answer your questions! Who sent you?"
    anger_responses(3) = "You think I don't know what you're doing? Leave me alone!"
    anger_responses(4) = "That's exactly what someone working for THEM would say!"
    anger_responses(5) = "I'm getting tired of these accusations. Watch what you say!"
    
    mistrust_responses(0) = "I can tell you're working for them. Don't deny it."
    mistrust_responses(1) = "How do I know I can trust you? You could be one of them."
    mistrust_responses(2) = "I think you're trying to get information from me to report back."
    mistrust_responses(3) = "I've seen people like you before. You're probably wearing a wire."
    mistrust_responses(4) = "They sent you to test me, didn't they? I'm not falling for it."
    mistrust_responses(5) = "I need to be careful what I tell you. You might not be who you say."
    
    mafia_responses(0) = "The Mafia is after me because I know too much about their operations."
    mafia_responses(1) = "I had to stop going to the race track when I discovered the Mafia controls it."
    mafia_responses(2) = "The mob has informants everywhere. Even in this place."
    mafia_responses(3) = "The Outfit doesn't like people who know their secrets."
    mafia_responses(4) = "I've seen how the rackets work. That's why they're after me."
    mafia_responses(5) = "The gangsters have threatened me. I have to watch my back."
    
    hospital_responses(0) = "The doctors here are probably working for the Mafia too."
    hospital_responses(1) = "I don't need medicine. I need protection from the mob."
    hospital_responses(2) = "They keep me here because I know the truth about the rackets."
    hospital_responses(3) = "The hospital staff report everything I say to the Outfit."
    hospital_responses(4) = "This place isn't helping me. It's just keeping me trapped."
    hospital_responses(5) = "The treatment they give me is just to keep me quiet about what I know."
    
    gambling_responses(0) = "I used to go to the race track, until I found out it was fixed."
    gambling_responses(1) = "The bookies at the track are all connected to the Mafia."
    gambling_responses(2) = "I won too much money once. That's when they started watching me."
    gambling_responses(3) = "The gambling racket is how they launder their dirty money."
    gambling_responses(4) = "I know how they fix the races. That's why they're after me."
    gambling_responses(5) = "My bookie threatened me when I couldn't pay. He's with the mob."
    
    neutral_responses(0) = "I don't want to talk about that right now."
    neutral_responses(1) = "I've been feeling watched lately. Do you ever feel that way?"
    neutral_responses(2) = "I used to go to the race track a lot. Not anymore though."
    neutral_responses(3) = "Sometimes I think people are talking about me behind my back."
    neutral_responses(4) = "I had a job once, before all the trouble started."
    neutral_responses(5) = "It's hard to know who to trust these days."
    neutral_responses(6) = "I have to be careful about what I say to people I don't know well."
    neutral_responses(7) = "I've seen things that most people wouldn't believe."
    neutral_responses(8) = "People think I'm crazy, but I'm just telling the truth."
    neutral_responses(9) = "You seem alright, but I still have to be careful."
    neutral_responses(10) = "Let's talk about something else. This topic makes me uncomfortable."
    
    question_responses(0) = "Why do you want to know about that? Are you collecting information?"
    question_responses(1) = "I don't answer questions from people I don't trust completely."
    question_responses(2) = "That's a personal matter. I'd rather not discuss it."
    question_responses(3) = "Why are you asking me so many questions? Who sent you?"
    question_responses(4) = "I'm not sure I should tell you. You might be working for them."
    question_responses(5) = "I ask the questions here. What's your connection to the Outfit?"
    
    agree_responses(0) = "So you admit it! I knew I was right all along."
    agree_responses(1) = "Finally, someone who sees the truth like I do."
    agree_responses(2) = "Yes, exactly. Not many people understand this."
    agree_responses(3) = "I'm glad you agree. Most people think I'm making it all up."
    
    disagree_responses(0) = "That's what they want you to think. You've been deceived."
    disagree_responses(1) = "You're either naive or you're one of them. Which is it?"
    disagree_responses(2) = "You don't know what you're talking about. I've seen the evidence."
    disagree_responses(3) = "Of course you'd say that. You're probably working for them too."
    
    confused_responses(0) = "You're not making any sense. Are you trying to confuse me?"
    confused_responses(1) = "I don't understand what you're getting at. Be more clear."
    confused_responses(2) = "That doesn't mean anything to me. Are you speaking in code?"
    confused_responses(3) = "Your words are strange. Are you testing me somehow?"
    confused_responses(4) = "I'm not following you. Maybe that's intentional on your part."
    confused_responses(5) = "You're talking in circles. That's a technique they use to confuse people."
End Sub

' Function to check if a string contains any word from a list
Function ContainsAny(userInput As String, wordList() As String, listSize As Integer) As Integer
    Dim As String lowerInput = LCase(userInput)
    
    For i As Integer = 0 To listSize
        If Len(wordList(i)) > 0 Then
            If InStr(lowerInput, wordList(i)) > 0 Then
                Return 1
            End If
        End If
    Next
    
    Return 0
End Function

' Function to randomly select a response from an array
Function RandomResponse(responses() As String, size As Integer) As String
    Return responses(Int(Rnd * (size + 1)))
End Function

' Function to parse user input and generate a response
Function GenerateResponse(userInput As String) As String
    Dim As String lowerInput = LCase(userInput)
    Dim As String response = ""
    
    ' Check for keywords and adjust emotional state
    If ContainsAny(lowerInput, mafia_words(), 10) Then
        FEAR += 15
        MISTRUST += 10
        response = RandomResponse(mafia_responses(), 5)
    ElseIf ContainsAny(lowerInput, hospital_words(), 10) Then
        ANGER += 10
        MISTRUST += 15
        response = RandomResponse(hospital_responses(), 5)
    ElseIf ContainsAny(lowerInput, gambling_words(), 10) Then
        FEAR += 5
        MISTRUST += 10
        response = RandomResponse(gambling_responses(), 5)
    ElseIf ContainsAny(lowerInput, question_words(), 10) Then
        MISTRUST += 5
        response = RandomResponse(question_responses(), 5)
    ElseIf ContainsAny(lowerInput, agree_words(), 5) Then
        FEAR -= 5
        ANGER -= 5
        response = RandomResponse(agree_responses(), 3)
    ElseIf ContainsAny(lowerInput, disagree_words(), 5) Then
        ANGER += 10
        MISTRUST += 5
        response = RandomResponse(disagree_responses(), 3)
    Else
        ' No specific keywords found, check emotional state
        If FEAR > FEAR_THRESHOLD Then
            response = RandomResponse(fear_responses(), 5)
        ElseIf ANGER > ANGER_THRESHOLD Then
            response = RandomResponse(anger_responses(), 5)
        ElseIf MISTRUST > MISTRUST_THRESHOLD Then
            response = RandomResponse(mistrust_responses(), 5)
        Else
            ' If no triggers and emotions below threshold, use neutral response
            response = RandomResponse(neutral_responses(), 10)
        End If
    End If
    
    ' Gradually return emotional state to baseline
    If FEAR > 30 Then FEAR -= 2
    If ANGER > 30 Then ANGER -= 2
    If MISTRUST > 40 Then MISTRUST -= 1
    
    Return response
End Function

' Main program
Sub Main()
    Dim As String userInput, response
    
    ' Seed the random number generator
    Randomize Timer
    
    ' Initialize response arrays
    InitializeResponses()
    
    ' Display intro
    Print "PARRY CHATBOT SIMULATION"
    Print "------------------------"
    Print "You are conversing with PARRY, a simulation of a paranoid individual."
    Print "Type 'exit' to end the conversation."
    Print
    
    ' Initial response
    Print "PARRY: I don't know who you are. What do you want from me?"
    
    ' Main conversation loop
    Do
        Print
        Input "YOU: ", userInput
        
        If LCase(userInput) = "exit" Then
            Print
            Print "PARRY: Fine, leave. That's what everyone does."
            Exit Do
        End If
        
        ' Generate response
        response = GenerateResponse(userInput)
        
        ' Display response with a short delay to simulate thinking
        Print
        Print "PARRY: "; response
        
        ' Debug info (can be removed)
        ' Print "[DEBUG - Fear: " & FEAR & ", Anger: " & ANGER & ", Mistrust: " & MISTRUST & "]"
        
    Loop
    
    Print
    Print "Conversation ended."
End Sub

Main()

ELIZA.BAS
' ELIZA Chatbot in FreeBASIC
' Based on Joseph Weizenbaum's 1966 natural language processing program
' This simulates a Rogerian psychotherapist

' Define maximum sizes for arrays
Const MAX_KEYWORDS = 40       ' Maximum number of keywords
Const MAX_RESPONSES = 10      ' Maximum responses per keyword
Const MAX_CONJUGATIONS = 20   ' Maximum word conjugations
Const INPUT_BUFFER = 255      ' Maximum input length

' Type to store keyword with its responses
Type KeywordEntry
    keyword As String
    weight As Integer            ' Priority weight (higher = higher priority)
    responses(MAX_RESPONSES) As String
    responseCount As Integer     ' Number of actual responses
End Type

' Type to store word conjugations (I->you, am->are, etc.)
Type ConjugationPair
    from As String
    to As String
End Type

' Arrays to hold data
Dim Shared keywords(MAX_KEYWORDS) As KeywordEntry
Dim Shared keywordCount As Integer
Dim Shared conjugations(MAX_CONJUGATIONS) As ConjugationPair
Dim Shared conjugationCount As Integer

' Arrays for generic responses when no keyword is matched
Dim Shared genericResponses(10) As String
Dim Shared genericCount As Integer = 0

' Function to initialize all keywords and responses
Sub InitializeKeywords()
    ' Initialize keyword 0: "hello"
    keywords(0).keyword = "hello"
    keywords(0).weight = 1
    keywords(0).responses(0) = "How do you do. Please tell me about your problem."
    keywords(0).responses(1) = "Hello. What seems to be your concern?"
    keywords(0).responseCount = 2
    
    ' Initialize keyword 1: "computer"
    keywords(1).keyword = "computer"
    keywords(1).weight = 3
    keywords(1).responses(0) = "Do computers worry you?"
    keywords(1).responses(1) = "What do you think about machines?"
    keywords(1).responses(2) = "Why do you mention computers?"
    keywords(1).responses(3) = "What do you think machines have to do with your problem?"
    keywords(1).responseCount = 4
    
    ' Initialize keyword 2: "name"
    keywords(2).keyword = "name"
    keywords(2).weight = 2
    keywords(2).responses(0) = "I am not interested in names."
    keywords(2).responses(1) = "Names don't interest me."
    keywords(2).responseCount = 2
    
    ' Initialize keyword 3: "sorry"
    keywords(3).keyword = "sorry"
    keywords(3).weight = 1
    keywords(3).responses(0) = "Please don't apologize."
    keywords(3).responses(1) = "Apologies are not necessary."
    keywords(3).responses(2) = "What feelings do you have when you apologize?"
    keywords(3).responseCount = 3
    
    ' Initialize keyword 4: "I remember"
    keywords(4).keyword = "i remember"
    keywords(4).weight = 5
    keywords(4).responses(0) = "Do you often think of _REMAINDER_?"
    keywords(4).responses(1) = "Does thinking of _REMAINDER_ bring anything else to mind?"
    keywords(4).responses(2) = "What else do you remember?"
    keywords(4).responses(3) = "Why do you recall _REMAINDER_ right now?"
    keywords(4).responses(4) = "What in the present situation reminds you of _REMAINDER_?"
    keywords(4).responseCount = 5
    
    ' Initialize keyword 5: "if"
    keywords(5).keyword = "if"
    keywords(5).weight = 3
    keywords(5).responses(0) = "Do you think it's likely that _REMAINDER_?"
    keywords(5).responses(1) = "Do you wish that _REMAINDER_?"
    keywords(5).responses(2) = "What do you think about _REMAINDER_?"
    keywords(5).responses(3) = "Really, if _REMAINDER_?"
    keywords(5).responseCount = 4
    
    ' Initialize keyword 6: "I dreamed"
    keywords(6).keyword = "i dreamed"
    keywords(6).weight = 4
    keywords(6).responses(0) = "Really, _REMAINDER_?"
    keywords(6).responses(1) = "Have you ever fantasized _REMAINDER_ while you were awake?"
    keywords(6).responses(2) = "Have you dreamed _REMAINDER_ before?"
    keywords(6).responseCount = 3
    
    ' Initialize keyword 7: "dream"
    keywords(7).keyword = "dream"
    keywords(7).weight = 3
    keywords(7).responses(0) = "What does that dream suggest to you?"
    keywords(7).responses(1) = "Do you dream often?"
    keywords(7).responses(2) = "What persons appear in your dreams?"
    keywords(7).responses(3) = "Are you disturbed by your dreams?"
    keywords(7).responseCount = 4
    
    ' Initialize keyword 8: "perhaps"
    keywords(8).keyword = "perhaps"
    keywords(8).weight = 1
    keywords(8).responses(0) = "You don't seem quite certain."
    keywords(8).responses(1) = "Why the uncertain tone?"
    keywords(8).responses(2) = "Can't you be more positive?"
    keywords(8).responses(3) = "You aren't sure?"
    keywords(8).responses(4) = "Don't you know?"
    keywords(8).responseCount = 5
    
    ' Initialize keyword 9: "mother"
    keywords(9).keyword = "mother"
    keywords(9).weight = 3
    keywords(9).responses(0) = "Tell me more about your family."
    keywords(9).responses(1) = "Who else in your family _REMAINDER_?"
    keywords(9).responses(2) = "Your mother?"
    keywords(9).responses(3) = "What about your mother?"
    keywords(9).responseCount = 4
    
    ' Initialize keyword 10: "father"
    keywords(10).keyword = "father"
    keywords(10).weight = 3
    keywords(10).responses(0) = "Your father?"
    keywords(10).responses(1) = "Does he influence you strongly?"
    keywords(10).responses(2) = "What else comes to mind when you think of your father?"
    keywords(10).responseCount = 3
    
    ' Initialize keyword 11: "I want"
    keywords(11).keyword = "i want"
    keywords(11).weight = 5
    keywords(11).responses(0) = "What would it mean if you got _REMAINDER_?"
    keywords(11).responses(1) = "Why do you want _REMAINDER_?"
    keywords(11).responses(2) = "Suppose you got _REMAINDER_ soon?"
    keywords(11).responseCount = 3
    
    ' Initialize keyword 12: "I am glad"
    keywords(12).keyword = "i am glad"
    keywords(12).weight = 3
    keywords(12).responses(0) = "How have I helped you to be _REMAINDER_?"
    keywords(12).responses(1) = "What makes you happy just now?"
    keywords(12).responses(2) = "Can you explain why you are suddenly _REMAINDER_?"
    keywords(12).responseCount = 3
    
    ' Initialize keyword 13: "I am sad"
    keywords(13).keyword = "i am sad"
    keywords(13).weight = 3
    keywords(13).responses(0) = "I am sorry to hear you are _REMAINDER_."
    keywords(13).responses(1) = "Do you think that coming here will help you not to be _REMAINDER_?"
    keywords(13).responses(2) = "I'm sure it's not pleasant to be _REMAINDER_."
    keywords(13).responseCount = 3
    
    ' Initialize keyword 14: "alike"
    keywords(14).keyword = "alike"
    keywords(14).weight = 2
    keywords(14).responses(0) = "In what way?"
    keywords(14).responses(1) = "What resemblance do you see?"
    keywords(14).responses(2) = "What does that similarity suggest to you?"
    keywords(14).responses(3) = "What other connections do you see?"
    keywords(14).responses(4) = "What do you suppose that resemblance means?"
    keywords(14).responses(5) = "What is the connection, do you suppose?"
    keywords(14).responses(6) = "Could there really be some connection?"
    keywords(14).responseCount = 7
    
    ' Initialize keyword 15: "like"
    keywords(15).keyword = "like"
    keywords(15).weight = 2
    keywords(15).responses(0) = "In what way?"
    keywords(15).responses(1) = "What resemblance do you see?"
    keywords(15).responses(2) = "What does that similarity suggest to you?"
    keywords(15).responses(3) = "What other connections do you see?"
    keywords(15).responses(4) = "What do you suppose that resemblance means?"
    keywords(15).responseCount = 5
    
    ' Initialize keyword 16: "different"
    keywords(16).keyword = "different"
    keywords(16).weight = 2
    keywords(16).responses(0) = "How is it different?"
    keywords(16).responses(1) = "What differences do you see?"
    keywords(16).responses(2) = "What does that difference suggest to you?"
    keywords(16).responses(3) = "What other distinctions do you see?"
    keywords(16).responses(4) = "What do you suppose that disparity means?"
    keywords(16).responseCount = 5
    
    ' Initialize keyword 17: "i am"
    keywords(17).keyword = "i am"
    keywords(17).weight = 4
    keywords(17).responses(0) = "Is it because you are _REMAINDER_ that you came to me?"
    keywords(17).responses(1) = "How long have you been _REMAINDER_?"
    keywords(17).responses(2) = "Do you believe it is normal to be _REMAINDER_?"
    keywords(17).responses(3) = "Do you enjoy being _REMAINDER_?"
    keywords(17).responses(4) = "Do you know anyone else who is _REMAINDER_?"
    keywords(17).responseCount = 5
    
    ' Initialize keyword 18: "i feel"
    keywords(18).keyword = "i feel"
    keywords(18).weight = 4
    keywords(18).responses(0) = "Tell me more about such feelings."
    keywords(18).responses(1) = "Do you often feel _REMAINDER_?"
    keywords(18).responses(2) = "Do you enjoy feeling _REMAINDER_?"
    keywords(18).responses(3) = "What does feeling _REMAINDER_ remind you of?"
    keywords(18).responseCount = 4
    
    ' Initialize keyword 19: "family"
    keywords(19).keyword = "family"
    keywords(19).weight = 3
    keywords(19).responses(0) = "Tell me more about your family."
    keywords(19).responses(1) = "Who else in your family _REMAINDER_?"
    keywords(19).responses(2) = "Your family?"
    keywords(19).responses(3) = "What comes to mind when you think of your family?"
    keywords(19).responseCount = 4
    
    ' Initialize keyword 20: "you"
    keywords(20).keyword = "you"
    keywords(20).weight = 2
    keywords(20).responses(0) = "We were discussing you, not me."
    keywords(20).responses(1) = "Oh, I _REMAINDER_?"
    keywords(20).responses(2) = "You're not really talking about me, are you?"
    keywords(20).responses(3) = "What are your feelings now?"
    keywords(20).responseCount = 4
    
    ' Initialize keyword 21: "i"
    keywords(21).keyword = "i"
    keywords(21).weight = 1
    keywords(21).responses(0) = "You say _REMAINDER_?"
    keywords(21).responses(1) = "Can you tell me more about _REMAINDER_?"
    keywords(21).responses(2) = "Do you say _REMAINDER_ for some special reason?"
    keywords(21).responses(3) = "That's quite interesting."
    keywords(21).responseCount = 4
    
    ' Initialize keyword 22: "yes"
    keywords(22).keyword = "yes"
    keywords(22).weight = 1
    keywords(22).responses(0) = "You seem quite positive."
    keywords(22).responses(1) = "Are you sure?"
    keywords(22).responses(2) = "I see."
    keywords(22).responses(3) = "I understand."
    keywords(22).responseCount = 4
    
    ' Initialize keyword 23: "no"
    keywords(23).keyword = "no"
    keywords(23).weight = 1
    keywords(23).responses(0) = "Why not?"
    keywords(23).responses(1) = "You are being a bit negative."
    keywords(23).responses(2) = "Are you saying 'no' just to be negative?"
    keywords(23).responses(3) = "Why not?"
    keywords(23).responseCount = 4
    
    ' Initialize keyword 24: "always"
    keywords(24).keyword = "always"
    keywords(24).weight = 1
    keywords(24).responses(0) = "Can you think of a specific example?"
    keywords(24).responses(1) = "When?"
    keywords(24).responses(2) = "What incident are you thinking of?"
    keywords(24).responses(3) = "Really, always?"
    keywords(24).responseCount = 4
    
    ' Initialize keyword 25: "think"
    keywords(25).keyword = "think"
    keywords(25).weight = 2
    keywords(25).responses(0) = "Do you really think so?"
    keywords(25).responses(1) = "But you are not sure you _REMAINDER_?"
    keywords(25).responses(2) = "Do you doubt you _REMAINDER_?"
    keywords(25).responseCount = 3
    
    ' Initialize keyword 26: "because"
    keywords(26).keyword = "because"
    keywords(26).weight = 3
    keywords(26).responses(0) = "Is that the real reason?"
    keywords(26).responses(1) = "Don't any other reasons come to mind?"
    keywords(26).responses(2) = "Does that reason explain anything else?"
    keywords(26).responses(3) = "What other reasons might there be?"
    keywords(26).responseCount = 4
    
    ' Initialize keyword 27: "why"
    keywords(27).keyword = "why"
    keywords(27).weight = 3
    keywords(27).responses(0) = "Why do you think _REMAINDER_?"
    keywords(27).responses(1) = "Why don't you tell me the reason _REMAINDER_?"
    keywords(27).responses(2) = "Why does that question interest you?"
    keywords(27).responses(3) = "What is it you really want to know?"
    keywords(27).responses(4) = "Are such questions much on your mind?"
    keywords(27).responses(5) = "What answer would please you most?"
    keywords(27).responses(6) = "What do you think?"
    keywords(27).responses(7) = "What comes to mind when you ask that?"
    keywords(27).responseCount = 8
    
    ' Initialize keyword 28: "what"
    keywords(28).keyword = "what"
    keywords(28).weight = 2
    keywords(28).responses(0) = "Why do you ask?"
    keywords(28).responses(1) = "Does that question interest you?"
    keywords(28).responses(2) = "What is it you really want to know?"
    keywords(28).responses(3) = "Are such questions much on your mind?"
    keywords(28).responses(4) = "What answer would please you most?"
    keywords(28).responses(5) = "What do you think?"
    keywords(28).responses(6) = "What comes to mind when you ask that?"
    keywords(28).responses(7) = "Have you asked such questions before?"
    keywords(28).responses(8) = "Have you asked anyone else?"
    keywords(28).responseCount = 9
    
    ' Initialize keyword 29: "how"
    keywords(29).keyword = "how"
    keywords(29).weight = 2
    keywords(29).responses(0) = "Why do you ask?"
    keywords(29).responses(1) = "Does that question interest you?"
    keywords(29).responses(2) = "What is it you really want to know?"
    keywords(29).responses(3) = "Are such questions much on your mind?"
    keywords(29).responses(4) = "What answer would please you most?"
    keywords(29).responses(5) = "What do you think?"
    keywords(29).responses(6) = "What comes to mind when you ask that?"
    keywords(29).responses(7) = "Have you asked such questions before?"
    keywords(29).responses(8) = "Have you asked anyone else?"
    keywords(29).responseCount = 9
    
    ' Initialize keyword 30: "who"
    keywords(30).keyword = "who"
    keywords(30).weight = 2
    keywords(30).responses(0) = "Why do you ask?"
    keywords(30).responses(1) = "Does that question interest you?"
    keywords(30).responses(2) = "What is it you really want to know?"
    keywords(30).responses(3) = "Are such questions much on your mind?"
    keywords(30).responses(4) = "What answer would please you most?"
    keywords(30).responses(5) = "What do you think?"
    keywords(30).responses(6) = "What comes to mind when you ask that?"
    keywords(30).responses(7) = "Have you asked such questions before?"
    keywords(30).responses(8) = "Have you asked anyone else?"
    keywords(30).responseCount = 9
    
    ' Set the keyword count
    keywordCount = 31
    
    ' Initialize generic fallback responses
    genericResponses(0) = "I'm not sure I understand you fully."
    genericResponses(1) = "Please go on."
    genericResponses(2) = "What does that suggest to you?"
    genericResponses(3) = "Do you feel strongly about discussing such things?"
    genericResponses(4) = "That is interesting. Please continue."
    genericResponses(5) = "Tell me more about that."
    genericResponses(6) = "Does talking about this bother you?"
    genericResponses(7) = "Can you elaborate on that?"
    genericResponses(8) = "Why do you say that?"
    genericResponses(9) = "How does that make you feel?"
    genericResponses(10) = "Do you often feel this way?"
    genericCount = 11
End Sub

' Function to initialize word conjugations (I->you, etc.)
Sub InitializeConjugations()
    ' Initialize conjugation pairs
    conjugations(0).from = " i "
    conjugations(0).to = " you "
    
    conjugations(1).from = " i'm "
    conjugations(1).to = " you're "
    
    conjugations(2).from = " i've "
    conjugations(2).to = " you've "
    
    conjugations(3).from = " i'll "
    conjugations(3).to = " you'll "
    
    conjugations(4).from = " my "
    conjugations(4).to = " your "
    
    conjugations(5).from = " am "
    conjugations(5).to = " are "
    
    conjugations(6).from = " was "
    conjugations(6).to = " were "
    
    conjugations(7).from = " me "
    conjugations(7).to = " you "
    
    conjugations(8).from = " myself "
    conjugations(8).to = " yourself "

    conjugations(9).from = " mine "
    conjugations(9).to = " yours "
    
    ' Reverse direction (you->i)
    conjugations(10).from = " you "
    conjugations(10).to = " i "
    
    conjugations(11).from = " you're "
    conjugations(11).to = " i'm "
    
    conjugations(12).from = " you've "
    conjugations(12).to = " i've "
    
    conjugations(13).from = " you'll "
    conjugations(13).to = " i'll "
    
    conjugations(14).from = " your "
    conjugations(14).to = " my "
    
    conjugations(15).from = " yours "
    conjugations(15).to = " mine "

    conjugations(16).from = " are "
    conjugations(16).to = " am "

    conjugations(17).from = " were "
    conjugations(17).to = " was "
    
    conjugations(18).from = " yourself "
    conjugations(18).to = " myself "
    
    ' Set the conjugation count
    conjugationCount = 19
End Sub

' Function to perform conjugation transformations
Function ConjugatePhrase(phrase As String) As String
    Dim As String result = " " + LCase(phrase) + " "
    
    ' Apply all conjugations
    For i As Integer = 0 To conjugationCount - 1
        Dim As Integer startPos = InStr(result, conjugations(i).from)
        Do While startPos > 0
            result = Left(result, startPos - 1) + conjugations(i).to + Mid(result, startPos + Len(conjugations(i).from))
            startPos = InStr(startPos + Len(conjugations(i).to), result, conjugations(i).from)
        Loop
    Next
    
    ' Trim leading and trailing spaces
    Dim As String finalResult = Trim(result)
    
    ' Capitalize first letter
    If Len(finalResult) > 0 Then
        finalResult = UCase(Left(finalResult, 1)) + Mid(finalResult, 2)
    End If
    
    Return finalResult
End Function

' Function to get a random response from an array
Function RandomResponse(responses() As String, count As Integer) As String
    Return responses(Int(Rnd * count))
End Function

' Function to find the highest weighted keyword match in a string
Function FindKeyword(userInput As String, ByRef remainder As String) As Integer
    Dim As String lowerInput = " " + LCase(userInput) + " "
    Dim As Integer bestMatch = -1
    Dim As Integer bestWeight = -1
    
    ' Check all keywords
    For i As Integer = 0 To keywordCount - 1
        Dim As String keywordPattern = " " + keywords(i).keyword + " "
        Dim As Integer keywordPos = InStr(lowerInput, keywordPattern)
        
        ' If keyword found and has higher weight than current best
        If keywordPos > 0 And keywords(i).weight > bestWeight Then
            bestMatch = i
            bestWeight = keywords(i).weight
            
            ' Calculate the remainder text after the keyword
            remainder = Mid(userInput, keywordPos + Len(keywords(i).keyword))
        End If
    Next
    
    ' Also check for keywords at the start of input with space after
    For i As Integer = 0 To keywordCount - 1
        Dim As String keywordPattern = keywords(i).keyword + " "
        If Left(lowerInput, Len(keywordPattern)) = keywordPattern And keywords(i).weight > bestWeight Then
            bestMatch = i
            bestWeight = keywords(i).weight
            remainder = Mid(userInput, Len(keywords(i).keyword) + 1)
        End If
    Next
    
    Return bestMatch
End Function

' Function to transform a template response with the user's input
Function TransformResponse(template As String, remainder As String) As String
    ' No remainder text available
    If Len(remainder) = 0 Then
        ' If template requires remainder, use a generic response instead
        If InStr(template, "_REMAINDER_") > 0 Then
            Return RandomResponse(genericResponses(), genericCount)
        Else
            ' Template doesn't need remainder, use as is
            Return template
        End If
    End If
    
    ' Process the remainder through conjugation transformation
    Dim As String conjugatedRemainder = ConjugatePhrase(remainder)
    
    ' Replace _REMAINDER_ placeholder with the conjugated text
    Dim As Integer placeholderPos = InStr(template, "_REMAINDER_")
    If placeholderPos > 0 Then
        Return Left(template, placeholderPos - 1) + conjugatedRemainder + Mid(template, placeholderPos + 11)
    Else
        Return template
    End If
End Function

' Function to generate a response to user input
Function GenerateResponse(userInput As String) As String
    ' Handle empty input
    If Len(Trim(userInput)) = 0 Then
        Return "You don't seem to be saying anything."
    End If
    
    ' Check for goodbye phrases
    Dim As String lowerInput = LCase(userInput)
    If InStr(lowerInput, "goodbye") > 0 Or InStr(lowerInput, "bye") > 0 Or _
       InStr(lowerInput, "quit") > 0 Or InStr(lowerInput, "exit") > 0 Then
        Return "Goodbye. It was nice talking to you."
    End If
    
    ' Find a keyword match
    Dim As String remainder = ""
    Dim As Integer keywordIndex = FindKeyword(userInput, remainder)
    
    ' No keyword match, use generic response
    If keywordIndex = -1 Then
        Return RandomResponse(genericResponses(), genericCount)
    End If
    
    ' Get a random response template for the matched keyword
    Dim As String templateResponse = RandomResponse(keywords(keywordIndex).responses(), _
                                                  keywords(keywordIndex).responseCount)
    
    ' Transform the template with user's input
    Return TransformResponse(templateResponse, remainder)
End Function

' Main program
Sub Main()
    Dim As String userInput, response
    
    ' Seed the random number generator
    Randomize Timer
    
    ' Initialize data
    InitializeKeywords()
    InitializeConjugations()
    
    ' Display intro
    Print "ELIZA - A Computer Program For the Study of Natural Language"
    Print "Communication Between Man And Machine."
    Print "Created by Joseph Weizenbaum, 1966"
    Print "Implemented in FreeBASIC"
    Print "--------------------------------------------------------------"
    Print "* Type your responses in natural English."
    Print "* Type 'exit' or 'goodbye' to end the session."
    Print
    
    ' Initial response
    Print "ELIZA: Hello. How are you feeling today?"
    
    ' Main conversation loop
    Do
        Print
        Input "YOU: ", userInput
        
        If LCase(userInput) = "exit" Or LCase(userInput) = "goodbye" Or _
           LCase(userInput) = "bye" Or LCase(userInput) = "quit" Then
            Print
            Print "ELIZA: Goodbye. It was nice talking to you."
            Exit Do
        End If
        
        ' Generate response
        response = GenerateResponse(userInput)
        
        ' Display response
        Print
        Print "ELIZA: "; response
        
    Loop
    
    Print
    Print "Conversation ended."
End Sub

Main()
#5
QBasic / Re: Dos Word-Processors
Last post by ron77 - Mar 05, 2025, 05:42 AM
You cannot view this attachment.
#6
QBasic / Dos Word-Processors
Last post by ron77 - Mar 05, 2025, 05:41 AM
You cannot view this attachment.

You cannot view this attachment. 
#8
C / C++ / terminal (cmd) Conway's game o...
Last post by ron77 - Dec 30, 2024, 05:16 PM
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

#define WIDTH 40
#define HEIGHT 20
#define CLEAR "clear"  // Use "cls" for Windows

// Function to initialize the grid with random values
void initializeGrid(int grid[HEIGHT][WIDTH]) {
    for (int i = 0; i < HEIGHT; i++) {
        for (int j = 0; j < WIDTH; j++) {
            grid[i][j] = rand() % 2;
        }
    }
}

// Function to count neighbors of a cell
int countNeighbors(int grid[HEIGHT][WIDTH], int row, int col) {
    int count = 0;
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            if (i == 0 && j == 0) continue;
            
            int newRow = row + i;
            int newCol = col + j;
            
            // Check boundaries with wraparound
            if (newRow < 0) newRow = HEIGHT - 1;
            if (newRow >= HEIGHT) newRow = 0;
            if (newCol < 0) newCol = WIDTH - 1;
            if (newCol >= WIDTH) newCol = 0;
            
            count += grid[newRow][newCol];
        }
    }
    return count;
}

// Function to update the grid based on Conway's rules
void updateGrid(int grid[HEIGHT][WIDTH], int newGrid[HEIGHT][WIDTH]) {
    for (int i = 0; i < HEIGHT; i++) {
        for (int j = 0; j < WIDTH; j++) {
            int neighbors = countNeighbors(grid, i, j);
            
            // Apply Conway's rules
            if (grid[i][j]) {
                // Live cell
                newGrid[i][j] = (neighbors == 2 || neighbors == 3) ? 1 : 0;
            } else {
                // Dead cell
                newGrid[i][j] = (neighbors == 3) ? 1 : 0;
            }
        }
    }
    
    // Copy new grid to original grid
    for (int i = 0; i < HEIGHT; i++) {
        for (int j = 0; j < WIDTH; j++) {
            grid[i][j] = newGrid[i][j];
        }
    }
}

// Function to display the grid
void displayGrid(int grid[HEIGHT][WIDTH]) {
    // system(CLEAR);  // Clear screen
    
    for (int i = 0; i < HEIGHT; i++) {
        for (int j = 0; j < WIDTH; j++) {
            printf("%c ", grid[i][j] ? '#' : '.');
        }
        printf("\n");
    }
}

int main() {
    // Seed the random number generator
    srand(time(NULL));
    
    // Initialize grids
    int grid[HEIGHT][WIDTH];
    int newGrid[HEIGHT][WIDTH] = {0};
    
    // Initialize with random values
    initializeGrid(grid);
    
    // Main game loop
    while (1) {
        printf("\x1b[H");
		displayGrid(grid);
        updateGrid(grid, newGrid);
        usleep(100000);  // Delay for visualization (100ms)
    }
    
    return 0;
}
#9
General Discussion / How to Register to this forum ...
Last post by ron77 - Dec 28, 2024, 09:11 AM
As of now, the new member's registration has to be approved due to Fake Account registration by SpamBots and Spammers...

So, if you are interested in registering for this forum, register. Still, after that, you must send a request by e-mail with your info, including a valid e-mail, and tell us a bit about yourself, why you wish to join this forum, and what your interests are to the following email address. Don't forget to mention the nickname that you registered with. If you are approved, we'll send you the email you contacted us, stating that you are now approved. You can log in to the forum with the password, and members nick you registered with - if you try to register but do not email us, you WILL NOT be approved, and your registration will be deleted in 60 days:

Registration Requests Email Address

Thank you for your Understanding...

#10
C / C++ / Donut.c - have a donut
Last post by ron77 - Dec 27, 2024, 02:08 PM
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

int main() {
    float A = 0, B = 0;
    float i, j;
    int k;
    float z[1760];
    char b[1760];
    printf("\x1b[2J");
    for(;;) {
        memset(b,32,1760);
        memset(z,0,7040);
        for(j=0; j < 6.28; j += 0.07) {
            for(i=0; i < 6.28; i += 0.02) {
                float c = sin(i);
                float d = cos(j);
                float e = sin(A);
                float f = sin(j);
                float g = cos(A);
                float h = d + 2;
                float D = 1 / (c * h * e + f * g + 5);
                float l = cos(i);
                float m = cos(B);
                float n = sin(B);
                float t = c * h * g - f * e;
                int x = 40 + 30 * D * (l * h * m - t * n);
                int y= 12 + 15 * D * (l * h * n + t * m);
                int o = x + 80 * y;
                int N = 8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n);
                if(22 > y && y > 0 && x > 0 && 80 > x && D > z[o]) {
                    z[o] = D;
                    b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0];
                }
            }
        }
        printf("\x1b[H");
        for(k = 0; k < 1761; k++) {
            putchar(k % 80 ? b[k] : 10);
        }
        A += 0.04;
        B += 0.02;
        usleep(30000);
    }
    return 0;
}