home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / IntelliBots 1.0.1 / IntelliBots / IBots / wanderer.asm < prev    next >
Encoding:
Assembly Source File  |  1995-07-26  |  3.3 KB  |  95 lines  |  [TEXT/IBot]

  1. ;******************************************************
  2. ;TITLE:        WANDERER.ASM"
  3. ;CREATED BY:   Intelligent Technologies
  4. ;DESCRIPTION:  This program makes an IBot wander around and avoid
  5. ;              any obstacles that would cause it damage
  6. ;NOTES:        This program supports a more advanced movement algorithm
  7. ;              so that it is able to move up next to objects without
  8. ;              hitting them
  9. ;Name             Date          Description
  10. ;---------------- ------------- -------------------
  11. ;ITI              July 22, 1995 created the program
  12. ;******************************************************
  13.  
  14.  
  15.     .NAME    "Wanderer"
  16.     
  17. Start
  18.     COPR    #CHASSISSCAN,#0        ;do a chassis scan in the new direction
  19.     GETP    #SCANDISTANCE,R1    ;get the distance to the object scanned
  20.     GETP    #SCANOBJECT,R0        ;get the object scanned
  21.     JE        TryToMove            ;-if the scanned terrain is EMPTY then just move
  22.     MOVE    R0,R2                ;get the object scanned
  23.     TSTB    #15,R2
  24.     JNZ        HandleTerrain        ;-terrain
  25.     CMP        #IBOT4,R2            ;is it a robot?
  26.     JG        HandleNonRobot        ;-not a robot
  27.     CMP        #4,R1                ;is the robot farther away than 4 squares?
  28.     JG        ShootCannon            ;-yes, try to shoot it with the cannon
  29.     JUMP    ShootLaser            ;-no, shoot it with the laser
  30.  
  31. HandleTerrain
  32.     TEST    #$0006,R2            ;does the terrain do medium or power damage
  33.     JNE        HandleBadTerrain    ;-yes
  34.  
  35. TryToMove
  36.     CMP        #2,R1                ;are we moving at all?
  37.     JLE        TryToTurn            ;-no, turn instead
  38.     COPR    #CHASSISMOVE,R1        ;move the robot
  39.     JUMP    Start
  40.  
  41. TryToTurn
  42.     MOVE    #0,BestDistance        ;initialize the best distance
  43.     MOVE    #-120,R4            ;get the current chassis direction
  44. TryNewDir
  45.     ADD        #15,R4                ;turn a little
  46.     CMP        #120,R4                ;are we done?
  47.     JG        Turn                ;-yes, use the best direction
  48.     COPR    #CHASSISSCAN,R4        ;scan in the new direction
  49.     GETP    #SCANDISTANCE,R1    ;get the distance to the object scanned
  50.     CMP        R1,BestDistance        ;is the new distance better than the best to date?
  51.     JG        TryNewDir            ;-no, try another one
  52.     JL        UseDir                ;-yes, use this one
  53.     CMP        #-90,BestDirection    ;is the best direction greater than -90 degrees
  54.     JL        UseDir                ;-yes, then use it
  55.     CMP        #90,BestDirection    ;is the best direction less than or equal to 90 degrees
  56.     JLE        TryNewDir            ;-yes, try another one
  57. UseDir    
  58.     MOVE    R1,BestDistance        ;save the new distance
  59.     MOVE    R4,BestDirection    ;save the new direction
  60.     JUMP    TryNewDir            ;try another direction
  61. Turn
  62.     CMP        #0,BestDirection    ;is the best direction straight ahead(are we stuck)?
  63.     JNE        DoTurn                ;-no, turn the chassis
  64.     MOVE    #45,BestDirection    ;set the turn to 45
  65. DoTurn
  66.     COPR    #chassisturn,BestDirection    ;turn the chassis
  67.     JUMP    Start                ;goto the main loop
  68.     
  69. HandleBadTerrain
  70. HandleNonRobot
  71.     DEC        R1                    ;decrement the distance so that we do not hit the obstruction
  72.     JUMP    TryToMove            ;now move
  73.  
  74. ShootCannon
  75.     GETP    #CANNONTEMP,R3        ;get the cannon temp
  76.     ADD        #CANNONINC,R3        ;add in the temp per firing
  77.     CMP        #CANNONMELTTEMP,R3    ;will we melt the cannon if we fire?
  78.     JGE        ShootLaser            ;-yes, shoot the laser instead
  79.     COPR    #OFFENSECANNON,R1    ;shoot the cannon
  80.     JUMP    Start                ;goto the main loop
  81.  
  82. ShootLaser
  83.     GETP    #LASERTEMP,R3        ;get the laser temp
  84.     MOVE    #LASERMELTTEMP,R4    ;get the laser melt temp
  85.     SUB        R3,R4                ;calculate the difference
  86.     CMP        #25,R4                ;is it addequate for firing?
  87.     JL        Start                ;-no, goto the main loop
  88.     COPR    #OFFENSELASER,R4    ;fire the laser
  89.     JUMP    Start                ;goto the main loop
  90.  
  91. BestDistance
  92.     DL    0
  93. BestDirection
  94.     DL    0
  95.