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

0 Members and 1 Guest are viewing this topic.

#### nawitus

• C= 64
• Posts: 50
• Karma: 1
##### 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]
`StrictInformation.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 MethodEnd TypeInformationWord.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 MethodEnd TypeWord.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 MethodEnd TypeType Link Field Parent Field LinkTo:WordEnd TypeFunction AddLink(Word1\$,Word2\$) Local w1:Word = GetWord(Word1\$) Local w2:Word = GetWord(Word2\$) w1.AddWordLink(Word2\$,1) w2.AddWordLink(Word1\$,0)End FunctionFunction 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 wEnd FunctionFunction 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 NextEnd FunctionFunction 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 NextEnd FunctionFunction NotAdded(Search\$) Local In:InformationWord For In = EachIn InformationWord.InfoListWord If In.InfoWord\$ = Search\$ Then Return 0 Next Return 1End FunctionFunction 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 FoundParentsEnd Function'Main appAddLink("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 »

#### Shockwave

• good/evil
• Founder Member
• Posts: 17297
• Karma: 489
• evil/good
##### 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: