#! /usr/bin/perl -w # Vacuum Agent, for robotic vacuums cleaning arbitrary rooms # written by Don Colton # argv is the list of executible agent programs (non-numeric names) # argv may (but need not) contain a numeric random number seed # we spawn each agent and communicate through stdin/stdout # in the typical case, there is just one vacuum running at a time # The room is generated at random, on a square-cell pattern, with # walls and furnishings filling some of the cells. The vacuum starts # at a randomized location and must finish at that some location. # The driver prompts the vacuum by sending a set of percepts. The # percepts are, in order, radar-left, radar-front, radar-right, dirt, # and home. Each is a binary quantity, with 1 representing true and 0 # representing false. The percepts are space-separated and terminated # by a colon-space but no newline. For example, "1 0 0 1 0: ". # The vacuum responds by giving a command. The valid commands are: # "forward\n": move forward one cell, if possible, else do not move. # "left\n": turn left 90 degrees, staying in the same cell. # "right\n": turn right 90 degrees, staying in the same cell. # "vacuum\n": pick up dirt in the current cell. # "off\n": turn off, indicating the task is completed. # Score is -100 per dirt remaining, +100 per dirt captured, -1 per # command issued, and +100 for ending in the proper cell (direction # faced does not matter). $moves = 0; while ( 1 ) { chomp ( $line = ); # print "# $line\n"; ( $rl, $rf, $rr, $d, $h ) = split ( / /, $line ); $r = rand(); $moves++; if ( $d ) { print "vacuum\n"; next } if ( $moves > 1 && $h ) { print "off\n"; last } if ( $rf && $rl ) { print "right\n"; next } if ( $rf && $rr ) { print "left\n"; next } if ( $rl && $rr ) { print "forward\n"; next } if ( $rf ) { $dir = "left"; if ( $r > 0.5 ) { $dir = "right" } print "$dir\n"; next } if ( $rl ) { $dir = "forward"; if ( $r > 0.85 ) { $dir = "right" } print "$dir\n"; next } if ( $rr ) { $dir = "forward"; if ( $r > 0.85 ) { $dir = "left" } print "$dir\n"; next } $dir = "forward"; if ( $r > 0.95 ) { $dir = "left" } if ( $r < 0.05 ) { $dir = "right" } print "$dir\n"; }