Author Topic: Logic machine (Blitzmax)[BMAX]  (Read 2653 times)

0 Members and 1 Guest are viewing this topic.

Offline nawitus

  • C= 64
  • **
  • Posts: 50
  • Karma: 1
    • View Profile
Logic machine (Blitzmax)[BMAX]
« on: October 18, 2006 »
This code prints this logical information:

Quote
color is property.
color is not taste.
green is color.
green is not blue.
green is not red.
blue is color.
blue is not red.
red is color.
taste is property.

Code: [Select]
Strict

Information.InfoList = CreateList()
Type Information
Global InfoList:TList
Field Info$
Field Word1$,Word2$,Word3$

Function Add(NewInfo$,NewWord1$,NewWord2$,NewWord3$)
Local DontAdd=0,In:Information
For In:Information = EachIn InfoList
If In.Info$ = NewInfo$ Then
DontAdd=1
Exit
EndIf
If NewWord2$=In.Word2$ Then
If (NewWord1$ = In.Word3$) And (In.Word1$ = NewWord3$) Then
DontAdd=1
Exit
EndIf
EndIf
Next
If DontAdd = 0 Then
In:Information = New Information
In.Info$ = NewInfo$
In.Word1$ = NewWord1$
In.Word2$ = NewWord2$
In.Word3$ = NewWord3$
EndIf
End Function

Function DeleteAll()
ClearList(InfoList)
End Function

Function PrintAll()
For Local In:Information = EachIn InfoList
Print In.Info$
Next
DeleteAll()
InformationWord.DeleteAll()
End Function

Method New()
InfoList.AddLast Self
End Method
End Type

InformationWord.InfoListWord = CreateList()
Type InformationWord
Global InfoListWord:TList
Field InfoWord$

Function AddWord(NewInfo$)
Local DontAdd=0,In:InformationWord
For In:InformationWord = EachIn InfoListWord
If In.InfoWord$ = NewInfo$ Then
DontAdd=1
Exit
EndIf
Next
If DontAdd = 0 Then
In:InformationWord = New InformationWord
In.InfoWord$ = NewInfo$
EndIf
End Function

Function DeleteAll()
ClearList(InfoListWord)
End Function

Function PrintAll()
For Local In:InformationWord = EachIn InfoListWord
Print In.InfoWord$
Next
DeleteAll()
End Function

Method New()
InfoListWord.AddLast Self
End Method
End Type


Word.WordList = CreateList()
Type Word
Global WordList:TList
Field Name$
Field LinkList:TList

Method AddWordLink(Word2$,AddParent)
Local l:Link = New Link
l.Parent = AddParent
l.LinkTo = GetWord:Word(Word2$)
LinkList.AddLast l
End Method

Method New()
WordList.AddLast Self
LinkList = CreateList()
End Method
End Type

Type Link
Field Parent
Field LinkTo:Word
End Type




Function AddLink(Word1$,Word2$)
Local w1:Word = GetWord(Word1$)
Local w2:Word = GetWord(Word2$)

w1.AddWordLink(Word2$,1)
w2.AddWordLink(Word1$,0)


End Function

Function GetWord:Word(Word1$)
Local w:Word
For w:Word = EachIn Word.WordList
If Word1$ = w.Name$ Then Return w
Next
w:Word = New Word
w.Name$ = Word1$
Return w
End Function

Function PrintWords()
Local w:Word,l:Link
For w = EachIn Word.WordList
Print " "
Print w.Name$
For l = EachIn w.LinkList
If l.Parent Then
Print w.Name$ + "->" + l.LinkTo.Name$
EndIf
Next
Next
End Function

Function PrintInformation(Word1$)
Local w:Word = GetWord:Word(Word1$),l:Link,l2:Link

For l = EachIn w.LinkList
If l.Parent Then
Information.Add l.LinkTo.Name$ + " is " + w.Name$ + ".",l.LinkTo.Name$,"is",w.Name$
If ParentCount(l.LinkTo.Name$) > 1 Then
For l2 = EachIn GetWord(l.LinkTo.Name$).LinkList
If Not l2.Parent Then
If l2.LinkTo.Name$ <> w.Name$ Then
Information.Add w.Name$ + " is not " + l2.LinkTo.Name$ + ".",w.Name$,"is not",l2.LinkTo.Name$
EndIf
EndIf
Next
EndIf
If NotAdded(l.LinkTo.Name$) Then
InformationWord.AddWord l.LinkTo.Name$
PrintInformation(l.LinkTo.Name$)
EndIf
Else
Information.Add w.Name$ + " is " + l.LinkTo.Name$ + ".",w.Name$,"is",l.LinkTo.Name$
If ParentCount(l.LinkTo.Name$) > 1 Then
For l2 = EachIn GetWord(l.LinkTo.Name$).LinkList
If l2.Parent Then
If l2.LinkTo.Name$ <> w.Name$ Then
Information.Add w.Name$ + " is not " + l2.LinkTo.Name$ + ".",w.Name$,"is not",l2.LinkTo.Name$
EndIf
EndIf
Next
EndIf
If NotAdded(l.LinkTo.Name$) Then
InformationWord.AddWord l.LinkTo.Name$
PrintInformation(l.LinkTo.Name$)
EndIf
EndIf
Next

End Function

Function NotAdded(Search$)
Local In:InformationWord
For In = EachIn InformationWord.InfoListWord
If In.InfoWord$ = Search$ Then Return 0
Next
Return 1
End Function

Function ParentCount(Word1$)
Local w:Word = GetWord(Word1$),FoundParents=0
For Local l:Link = EachIn w.LinkList
If l.Parent Then FoundParents=FoundParents+1
Next
Return FoundParents
End Function


'Main app
AddLink("property","color")
AddLink("property","taste")
AddLink("color","green")
AddLink("color","blue")
AddLink("color","red")



PrintInformation("color")
Information.PrintAll()


I also coded a machine to talk with using this code, check this log:
Quote
      Hello.
      :hello
      Hi.
      :red is color
      :green is color
      :blue is color
      :bob is red
      :bob is human
      :what is bob
      bob is red and human.
      :what isnt bob
      bob is not green
      bob is not blue
      :bye
      Bye.

[edit ~ Blitzversion added to topic title}
« Last Edit: July 21, 2007 by Shockwave »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Logic machine
« Reply #1 on: October 18, 2006 »
One of the first ever things I did on a computer was at comprehensive school on a Commodore Pet. It was a program called "Classmates" The lesson consisted of the class telling the program information about some of the pupils. It looked a lot like this and it actually could talk a little about the people in the class after a while.

Like it got to learn who was friends with who and what music everyone liked etc.

At the time I thought it was pretty nifty.
Shockwave ^ Codigos
Challenge Trophies Won: