#! /usr/bin/perl -w # wumpus agent # read a percept line (stench,breeze,glitter,bump,scream), like "n,n,y,n,n\n" # respond with a one-letter action: L, R, A, S, or Q, like "A\n" # or respond with a one-word action: left, right, forward, shoot, or quit, like "forward\n" # world is 4x4 squares # +-----+-----+-----+-----+ # | 1,4 | 2,4 | 3,4 | 4,4 | # +-----+-----+-----+-----+ # | 1,3 | 2,3 | 3,3 | 4,3 | # +-----+-----+-----+-----+ # | 1,2 | 2,2 | 3,2 | 4,2 | # +-----+-----+-----+-----+ # | 1,1 | 2,1 | 3,1 | 4,1 | # +-----+-----+-----+-----+ # 1,1 is start, facing 2,1, is always safe # debug lines can be printed "# ... \n" # score -1 for each action, -10 for using arrow, -1000 for death, and +1000 for finding gold $moves = 0; while ( 1 ) { chomp ( $line = ); # print "# $line\n"; ( $stench, $breeze, $glitter, $bump, $scream ) = split ( /,/, $line ); $action = "forward"; $r = int ( rand ( 4 ) ); $moves++; if ( $r == 0 ) { $action = "left" } if ( $r == 1 ) { $action = "right" } print "$action\n"; }