O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Robot Control Program complex.ptr

This isn’t really a Perl/Tk program, but we’re including it anyway. It’s a TclRobots Robot Control Program written in Perl.

map { dputs $_; } split /\n/, <<'end-of-about'; ----- Robot Control Program complex.ptr Even though I prefer simplicity, here's complexity, but it doesn't always work very well, alas. Basically, this RCP is completely state driven and uses clock ticks to schedule internal events. It moves in a path described by an n-sided polygon that approximates a circle (this was my idea, I didn't know one of Tom's RCP team samples also used this technique!). The direction of movement is randomly chosen during preset, eliminating "wall" code (although the RCP may perform a "crazy Ivan" if it cannot find an enemy). The RCP also attempts to move as fast as possible, thus tracks its cooling rate to coordinate turns, eliminating "flee" code. There is also some watchdog code that periodically checks the RCP's health. Finally, the robot list from the first tournament is maintained, so it was simple to add a "friend" field and thus implement team play. Stephen.O.Lidie@Lehigh.EDU, 2000/09/24. ----- end-of-about # Syntax check: TCLROBOTS_RCP_CHECK=1 perl -MTclRobots -c complex.ptr use Tk qw/lsearch/; use vars qw/ $ATTACK_LIST_ENTRY $CANNON_HEADING $CANNON_READY $CLIP_SIZE $COOLING @COST $DANGER_RANGE $DIRECTION $DRIVE_HEADING $DRIVE_SPEED $EMERGENCY_X $EMERGENCY_Y @HEAT $HOUSE_KEEP_COUNT $HOUSE_KEEP_TICK @HUNT_STATE_LIST @IWSL $IWSL_COUNT $IWSL_TICK ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required