Here is the source code for for CRobots and C++Robots versions of my SideTracker robot. This was a fun little diversion ages ago. This little robot did rather well back then. Very simple technique.

CRobots :: SideTrac.r

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ****************************************************************** */
/*                                                                    */
/*      Name     : SIDETRAC                                           */
/*      Strategy : Kick butt on all other robots by moving fast,      */
/*                 firing accurately.                                 */
/*      Creator  : Hans D. Kellner  -  1987     Phoenix, AZ           */
/*                                                                    */

int drive_angle;                 /* Angle to travel */
int scan_angle;                  /* Angle to scan other robots */

main()
{
    drive_angle = 0;
    scan_angle  = 0;

    while(1) {                   /* Loop until I win! */
        move_robot();            /* Go get some robots */
        scan_field();            /* Look for any and blast em! */
    }

}

move_robot()
{
    if ( speed() < 50 ) {          /* If speed is below 50 we can turn.  */
                                   /* Therefore, change angle by 90 dgrs */
        drive_angle = ( drive_angle + 90 ) % 360;
        drive ( drive_angle,99 );  /* then start motors back up to full! */
    }
                                   /* Watch out for walls */
    if ( drive_angle == 0 && loc_x() > 700 )        /* Watch for right edge */
        drive ( drive_angle,40 );                   /* Slow down for turn   */
    else if ( drive_angle == 180 && loc_x() < 300 ) /* At left edge?        */
        drive ( drive_angle,40 );                   /* All motors slow!     */
    else if ( drive_angle == 90 && loc_y() > 700 )  /* At top wall?         */
        drive ( drive_angle,40 );                   /* Hit the brakes!      */
    else if ( drive_angle == 270 && loc_y() < 300 ) /* At the bottom edge?  */
        drive ( drive_angle,40 );                   /* Whoaoaoaoa!          */

}

scan_field()
{
    int range;                           /* Distance to other robot */
    int range2;

    range = scan ( scan_angle,10 );                  /* Look for a meal!   */
    if ( range < 700 && range > 0 ) {                /* Is it in range?    */
        range2 = scan( scan_angle - 5,10 );          /* Scan in closer...  */
        if ( range2 < 700 && range2 > 0 ) {          /* In range on right? */
            cannon( scan_angle - 5, 2*(range2 - range) + range); /* Then shoot */
            scan_angle = (scan_angle - 10) % 360;    /* Track the meal!    */
        }
        else {
            cannon ( scan_angle + 5, 2*(range2 - range) + range);
            scan_angle = (scan_angle + 10) % 360;    /* Track the meal!    */
        }
    }
    else                          /* No meals in sight so rotate angle 20 */
        scan_angle = ( scan_angle + 20 ) % 360;

}

/*  Thats all folks!  Short, sweet, DEADLY!  */

C++Robots :: SideTrac.c

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
//      Name     : SIDETRACKER2
//
//      Strategy : Kick butt on all other robots by moving fast,
//                 firing accurately.
//
//      Creator  : Hans Kellner - hansk@netcom.com
//
//      Version  : 1.0 - initial 1987
//               : 2.1 - modified for C++Robots - October 1994
//

#include "robots.h"

main()
{
    int driveAngle;
    int quickAngle;
    int quickScan;
    int quickRange;
    int attackRange;
    int attackAngle;
    int startTurn;

    driveAngle = 0;
    drive( driveAngle, 100 );

    quickScan  = 1;
    quickAngle = 0;

    while ( 1 )
    {
        startTurn = 0;

        if ( driveAngle == 0 )
        {
            if ( loc_x() > 8000 )
                startTurn = 1;
        }
        else
        if ( driveAngle == 90 )
        {
            if ( loc_y() > 8000 )
                startTurn = 1;
        }
        else
        if ( driveAngle == 180 )
        {
            if ( loc_x() < 2000 )
                startTurn = 1;
        }
        else
        if ( driveAngle == 270 )
        {
            if ( loc_y() < 2000 )
                startTurn = 1;
        }

        if ( startTurn )
        {
            drive( driveAngle, 50 );

            driveAngle = ( driveAngle + 90 ) % 360;

            while ( speed() > 50 )
                drive( driveAngle, 50 );

            drive( driveAngle, 100 );
        }

        if ( quickScan )
        {        
            quickRange = scan( quickAngle, 10 );

            if ( quickRange > 0 && quickRange <= 7000 )
            {
                if ( quickRange > 200 )
                    cannon( quickAngle, quickRange );

                quickScan = 0;

                attackAngle = quickAngle;
            }
            else
            {
                quickAngle = ( quickAngle + 20 ) % 360;
            }
        }
        else
        {
            if ( attackRange = scan( attackAngle, 5 ) )
            {
                if ( attackRange > 30 )
                {
                    cannon( attackAngle, attackRange );
                }
            }
            else
            if ( attackRange = scan( attackAngle + 10, 5 ) )
            {
                attackAngle += 10;

                if ( attackRange > 30 )
                {
                    cannon( attackAngle + 4, attackRange );
                }
            }
            else    
            if ( attackRange = scan( attackAngle - 10, 5 ) )
            {
                attackAngle -= 10;

                if ( attackRange > 30 )
                {
                    cannon( attackAngle - 4, attackRange );
                }
            }
            else
            {
                quickScan = 1;
            }
        }
    }
}