👨‍💻 dev LG port Java->vb.net

development

owly

闇の伝説
Staff member
戦闘 コーダー
project progress at 100%
 
0% 100%

  1. AbsDictionaryDB +
  2. Mutatable +
  3. APSay:Mutatable +
  4. DeepCopier +
  5. APVerbatim:Mutatable +
  6. GrimoireMemento +
  7. Algorithm +
  8. CldBool +
  9. APCldVerbatim:APVerbatim +
  10. Kokoro +
  11. Neuron +
  12. DiSkillUtils +
  13. DiSkillV2 +
  14. DiHelloWorld:DiSkillV2 +
  15. Cerabellum +
  16. Fusion +
  17. Thinkable +
  18. Chobits:Thinkable +
  19. Brain +

@fukurou
 
Last edited by a moderator:

fukurou

the supreme coder
ADMIN
Code:
    Public Class AbsDictionaryDB
        Public Sub Save(key As String, value As String)
            ' Save to DB (override me)
        End Sub

        Public Function Load(key As String) As String
            ' Override me
            Return "null"
        End Function
    End Class
    Public MustInherit Class Mutatable
        Public algKillSwitch As Boolean = False

        Public MustOverride Function Action(ear As String, skin As String, eye As String) As String
        Public MustOverride Function Completed() As Boolean
        Public MustOverride Function Clone() As Mutatable

        Public Function MyName() As String
            ' Returns the class name
            Return Me.GetType().Name
        End Function
    End Class
 

fukurou

the supreme coder
ADMIN
Code:
Public Class DeepCopier
        Public Function DeepCopyStringList(originalList As List(Of String)) As List(Of String)
            ' Create a new list and copy each element from the original list.
            Dim copiedList As New List(Of String)(originalList.Count)
            For Each item As String In originalList
                copiedList.Add(item)
            Next

            ' Return the deep-copied list.
            Return copiedList
        End Function
        Public Function DeepCopyIntList(originalList As List(Of Integer)) As List(Of Integer)
            ' Create a new list and copy each element from the original list.
            Dim copiedList As New List(Of Integer)(originalList.Count)
            For Each item As Integer In originalList
                copiedList.Add(item)
            Next

            ' Return the deep-copied list.
            Return copiedList
        End Function

    End Class
 

fukurou

the supreme coder
ADMIN
Code:
Public Class APVerbatim
    Inherits Mutatable

    ' This algorithm part says each past param verbatim
    Private sentences As New List(Of String)()
    Private at As Integer = 0

    Public Sub New(ParamArray sentences() As String)
        For Each sentence As String In sentences
            Me.sentences.Add(sentence)
        Next

        If sentences.Length = 0 Then
            at = 30
        End If
    End Sub

    Public Sub New(list1 As List(Of String))
        Me.sentences = New List(Of String)(list1)

        If Me.sentences.Count = 0 Then
            at = 30
        End If
    End Sub

    Public Overrides Function Action(ear As String, skin As String, eye As String) As String
        Dim axnStr As String = ""
        If at < sentences.Count Then
            axnStr = sentences(at)
            at += 1
        End If
        Return axnStr
    End Function

    Public Overrides Function Completed() As Boolean
        Return at >= sentences.Count
    End Function

    Public Overrides Function Clone() As Mutatable
        Return New APVerbatim(sentences)
    End Function
End Class
 

fukurou

the supreme coder
ADMIN
Code:
Public Class GrimoireMemento
        Private absDictionaryDB As AbsDictionaryDB

        Public Sub New(ByVal absDictionaryDB As AbsDictionaryDB)
            MyBase.New()
            Me.absDictionaryDB = absDictionaryDB
        End Sub

        Public Function SimpleLoad(ByVal key As String) As String
            Return Me.absDictionaryDB.Load(key)
        End Function

        Public Sub SimpleSave(ByVal key As String, ByVal value As String)
            If key.StartsWith("AP") Or key = "" Or value = "" Then
                Return
            End If
            Me.absDictionaryDB.Save(key, value)
        End Sub
    End Class
 

fukurou

the supreme coder
ADMIN
Code:
Public Class CldBool
    ' cloudian : this class is used to provide shadow reference to a boolean variable
    Private modeActive As Boolean = False

    Public Function GetModeActive() As Boolean
        Return modeActive
    End Function

    Public Sub SetModeActive(ByVal modeActive As Boolean)
        Me.modeActive = modeActive
    End Sub
End Class

so me means this or self in vb. asses everywhere
 

fukurou

the supreme coder
ADMIN
Code:
Public Class APCldVerbatim
    Inherits Mutatable
    ' This algorithm part says each past param verbatim
    Private sentences As New List(Of String)()
    Private at As Integer = 0
    Private cldBool As CldBool ' Access via shallow reference

    Public Sub New(ByVal cldBool As CldBool, ByVal ParamArray sentences As String())
        For Each sentence As String In sentences
            Me.sentences.Add(sentence)
        Next
        If sentences.Length = 0 Then
            at = 30
        End If
        Me.cldBool = cldBool
        Me.cldBool.SetModeActive(True)
    End Sub

    Public Sub New(ByVal cldBool As CldBool, ByVal list1 As List(Of String))
        Me.sentences = New List(Of String)(list1)
        If Me.sentences.Count = 0 Then
            at = 30
        End If
        Me.cldBool = cldBool
        Me.cldBool.SetModeActive(True)
    End Sub

    Public Overrides Function Action(ByVal ear As String, ByVal skin As String, ByVal eye As String) As String
        Dim axnStr As String = ""
        If at < sentences.Count Then
            axnStr = sentences(at)
            at += 1
        End If
        cldBool.SetModeActive(Not (at >= sentences.Count))
        Return axnStr
    End Function

    Public Overrides Function Completed() As Boolean
        Return at >= sentences.Count
    End Function

    Public Overrides Function Clone() As Mutatable
        Return New APCldVerbatim(cldBool, sentences)
    End Function
End Class
 

fukurou

the supreme coder
ADMIN
Code:
Public Class Algorithm
        Private algParts As New List(Of Mutatable)()

        Public Sub New(ByVal algParts As List(Of Mutatable))
            MyBase.New()
            Me.algParts = algParts
        End Sub

        Public Function GetAlgParts() As List(Of Mutatable)
            Return algParts
        End Function

        Public Function GetSize() As Integer
            Return algParts.Count
        End Function

        Public Function Clone() As Algorithm
            ' Returns a deep copy of the algorithm
            Dim parts As New List(Of Mutatable)()
            For Each absAlgPart As Mutatable In Me.algParts
                parts.Add(absAlgPart.Clone())
            Next
            Return New Algorithm(parts)
        End Function
    End Class
 

fukurou

the supreme coder
ADMIN
Code:
Public Class Kokoro
    Private emot As String = ""

    Public Function GetEmot() As String
        Return emot
    End Function

    Public Sub SetEmot(emot As String)
        Me.emot = emot
    End Sub

    Public grimoireMemento As GrimoireMemento
    Public toHeart As New Hashtable()

    Public Sub New(absDictionaryDB As AbsDictionaryDB)
        MyBase.New()
        Me.grimoireMemento = New GrimoireMemento(absDictionaryDB)
    End Sub
End Class
 

fukurou

the supreme coder
ADMIN
Code:
    Public Class Neuron
        Private defcons As New Dictionary(Of Integer, List(Of Algorithm))

        Public Sub New()
            For i As Integer = 1 To 5
                defcons(i) = New List(Of Algorithm)()
            Next
        End Sub

        Public Sub InsertAlg(priority As Integer, alg As Algorithm)
            If 0 < priority AndAlso priority < 6 Then
                If defcons(priority).Count < 4 Then
                    defcons(priority).Add(alg)
                End If
            End If
        End Sub

        Public Function GetAlg(defcon As Integer) As Algorithm
            If defcons(defcon).Count > 0 Then
                Dim temp As Algorithm = defcons(defcon)(0)
                defcons(defcon).RemoveAt(0)
                Return temp.Clone()
            End If
            Return Nothing
        End Function
    End Class
 

fukurou

the supreme coder
ADMIN
Code:
Public Class DISkillUtils
    ' alg part based algorithm building methods
    ' var args param
    Public Function AlgBuilder(ParamArray algParts As Mutatable()) As Algorithm
        ' returns an algorithm built with the algPart varargs
        Dim algParts1 As New List(Of Mutatable)()
        For Each part As Mutatable In algParts
            algParts1.Add(part)
        Next
        Dim algorithm As New Algorithm(algParts1)
        Return algorithm
    End Function

    ' String based algorithm building methods
    Public Function SimpleVerbatimAlgorithm(ParamArray sayThis As String()) As Algorithm
        ' returns an algorithm that says the sayThis Strings verbatim per think cycle
        Return AlgBuilder(New APVerbatim(sayThis))
    End Function

    ' String part based algorithm building methods with cloudian (shallow ref object to inform on alg completion)
    Public Function SimpleCloudianVerbatimAlgorithm(cldBool As CldBool, ParamArray sayThis As String()) As Algorithm
        ' returns an algorithm that says the sayThis Strings verbatim per think cycle
        Return AlgBuilder(New APCldVerbatim(cldBool, sayThis))
    End Function

    Public Function StrContainsList(str1 As String, items As List(Of String)) As String
        ' returns the 1st match between words in a string and values in a list.
        For Each temp As String In items
            If str1.Contains(temp) Then
                Return temp
            End If
        Next
        Return ""
    End Function
End Class
 

fukurou

the supreme coder
ADMIN
Code:
Public Class DiSkillV2
    Protected kokoro As Kokoro = New Kokoro(New AbsDictionaryDB()) ' consciousness, shallow ref class to enable interskill communications
    Protected diSkillUtils As DISkillUtils = New DISkillUtils()
    Protected outAlg As Algorithm = Nothing ' skills output
    Protected outpAlgPriority As Integer = -1 ' defcon 1->5

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Input(ear As String, skin As String, eye As String)
    End Sub

    Public Sub Output(noiron As Neuron)
        If outAlg IsNot Nothing Then
            noiron.InsertAlg(Me.outpAlgPriority, outAlg)
            outpAlgPriority = -1
            outAlg = Nothing
        End If
    End Sub

    Public Sub SetKokoro(kokoro As Kokoro)
        Me.kokoro = kokoro
    End Sub

    Protected Sub SetVerbatimAlg(priority As Integer, ParamArray sayThis As String())
        Me.outAlg = Me.diSkillUtils.SimpleVerbatimAlgorithm(sayThis)
        Me.outpAlgPriority = priority ' 1->5 1 is the highest algorithm priority
    End Sub

    Protected Sub SetSimpleAlg(ParamArray sayThis As String())
        Me.outAlg = Me.diSkillUtils.SimpleVerbatimAlgorithm(sayThis)
        Me.outpAlgPriority = 4 ' 1->5 1 is the highest algorithm priority
    End Sub

    Protected Sub SetVerbatimAlgFromList(priority As Integer, sayThis As List(Of String))
        Me.outAlg = Me.diSkillUtils.AlgBuilder(New APVerbatim(sayThis))
        Me.outpAlgPriority = priority ' 1->5 1 is the highest algorithm priority
    End Sub

    Protected Sub AlgPartsFusion(priority As Integer, ParamArray algParts As Mutatable())
        Me.outAlg = Me.diSkillUtils.AlgBuilder(algParts)
        Me.outpAlgPriority = priority ' 1->5 1 is the highest algorithm priority
    End Sub

    Public Function PendingAlgorithm() As Boolean
        Return Me.outAlg IsNot Nothing
    End Function
End Class
 

fukurou

the supreme coder
ADMIN
Code:
    Public Class DiHelloWorld
        Inherits DiSkillV2

        ' hello world skill for testing purposes
        Public Sub New()
            MyBase.New()
        End Sub

        Public Overloads Sub Input(ear As String, skin As String, eye As String)
            Select Case ear
                Case "hello"
                    MyBase.SetVerbatimAlg(4, "hello world") ' 1->5 1 is the highest algorithm priority
            End Select
        End Sub
    End Class
 

fukurou

the supreme coder
ADMIN
Code:
    Public Class Cerabellum
        ' Runs an algorithm
        Private fin As Integer
        Private at As Integer
        Private incrementAt As Boolean = False
        Public alg As Algorithm
        Private ia As Boolean = False ' isActive attribute
        Private emot As String = ""

        Public Sub AdvanceInAlg()
            If incrementAt Then
                incrementAt = False
                at += 1
                If at = fin Then
                    Me.ia = False
                End If
            End If
        End Sub

        Public Function GetAt() As Integer
            Return at
        End Function

        Public Function GetEmot() As String
            Return emot
        End Function

        Public Function SetAlgorithm(algorithm As Algorithm) As Boolean
            If Not IsActive() AndAlso Not algorithm.GetAlgParts.Count = 0 Then
                Me.alg = algorithm
                Me.at = 0
                Me.fin = algorithm.GetSize()
                Me.ia = True
                Me.emot = alg.GetAlgParts()(at).MyName() ' Updated line
                Return False
            End If
            Return True
        End Function

        Public Function IsActive() As Boolean
            Return IsActive
        End Function

        Public Function Act(ear As String, skin As String, eye As String) As String
            Dim axnStr As String = ""
            If Not isActive Then
                Return axnStr
            End If
            If at < fin Then
                axnStr = alg.GetAlgParts()(at).Action(ear, skin, eye)
                Me.emot = alg.GetAlgParts()(at).MyName()
                If alg.GetAlgParts()(at).Completed() Then
                    incrementAt = True
                End If
            End If
            Return axnStr
        End Function

        Public Sub DeActivation()
            Me.ia = Me.IsActive AndAlso Not alg.GetAlgParts()(at).algKillSwitch
        End Sub
    End Class
 

fukurou

the supreme coder
ADMIN
Code:
Public Class Fusion
    Private emot As String = ""
    Private result As String = ""
    Private ceraArr(4) As Cerabellum

    Public Sub New()
        For i As Integer = 0 To 4
            ceraArr(i) = New Cerabellum()
        Next
    End Sub

    Public Function GetEmot() As String
        Return emot
    End Function

    Public Sub LoadAlgs(neuron As Neuron)
        For i As Integer = 1 To 5
            If Not ceraArr(i - 1).IsActive() Then
                Dim temp As Algorithm = neuron.GetAlg(i)
                If temp IsNot Nothing Then
                    ceraArr(i - 1).SetAlgorithm(temp)
                End If
            End If
        Next
    End Sub

    Public Function RunAlgs(ear As String, skin As String, eye As String) As String
        result = ""
        For i As Integer = 0 To 4
            If Not ceraArr(i).IsActive() Then
                Continue For
            End If
            result = ceraArr(i).Act(ear, skin, eye)
            ceraArr(i).AdvanceInAlg()
            emot = ceraArr(i).GetEmot()
            ceraArr(i).DeActivation() ' Deactivation if Mutatable.algkillswitch = True
            Return result
        Next
        emot = ""
        Return result
    End Function
End Class
 
Top