Mapper-6
Project #2
CIS480
Option Explicit
Const maxNodes = 26
Const maxNeighs = 10
Dim numNodes As Integer
' Simulator data & structures
Private Type mapNode
nodeName As String * 1
numPaths As Integer
neighbor(0 To maxNeighs - 1) As Integer
End Type
Dim robiLoc As Integer
Dim robiDir As Integer
Dim simMap(1 To maxNodes) As mapNode
Dim place(1 To maxNodes) As String * 1
' Robot data & structures
Private Type robiMapNode
nodeName As String * 1
mapped As Boolean
numPaths As Integer
neighbor(0 To maxNeighs - 1) As Integer
End Type
Private Type srchNode
nodeNum As Integer
parent As Integer
End Type
Private Type nodeRay
low As Integer
high As Integer
nodeId(1 To maxNodes) As Integer
End Type
Dim myLocName As String * 1
Dim myLoc As Integer
Dim prevLoc As Integer
Dim myDir As Integer
Dim goalDir As Integer
Dim robiMap(1 To maxNodes) As robiMapNode
Private Sub cmdMap_Click()
Dim numP As Integer
Dim doneMapping As Boolean
Dim fromDir As Integer
nextNewNode = 1
myLocName = senseLoc
numP = sensePaths
myDir = 0
goalDir = 0
myLoc = makeNewNode(myLocName, numP)
Call travel
doneMapping = False
While Not doneMapping
prevLoc = myLoc
myLocName = senseLoc
numP = sensePaths
If prevSeen(myLocName) Then
myLoc = getLoc(myLocName)
fromDir = getFromDir(myLoc, prevLoc)
Else
myLoc = makeNewNode(myLocName, numP)
fromDir = 0
End If
myDir = (fromDir + 1) Mod numP
robiMap(prevLoc).neighbor(goalDir) = myLoc
robiMap(prevLoc).mapped = isMapped(prevLoc)
If Not robiMap(myLoc).mapped Then
robiMap(myLoc).neighbor(fromDir) = prevLoc
robiMap(myLoc).mapped = isMapped(myLoc)
End If
If robiMap(myLoc).mapped Then
doneMapping = gotoClosestInc(myLoc, myDir)
End If
If Not doneMapping Then
goalDir = chooseDir(myLoc)
turn ((goalDir + numP - myDir) Mod numP)
Call travel
End If
Wend
lblMesg.Caption = "DONE Mapping!"
End Sub
Private Sub cmdInit_Click()
robiLoc = 4
robiDir = 0
End Sub
' Robi's Logical sensors
Public Function senseLoc() As String
senseLoc = place(robiLoc)
End Function
Public Function sensePaths()
sensePaths = simMap(robiLoc).numPaths
End Function
' Robi's Logical actuators
Public Sub turn(ByVal numTicks As Integer)
robiDir = (robiDir + numTicks) Mod simMap(robiLoc).numPaths
End Sub
Public Sub travel()
Dim prevRobiLoc As Integer
Dim robiFrom As Integer
prevRobiLoc = robiLoc
robiLoc = simMap(robiLoc).neighbor(robiDir)
robiFrom = getRobiFrom(prevRobiLoc, robiLoc)
robiDir = (robiFrom + 1) Mod simMap(robiLoc).numPaths
End Sub