#!/usr/bin/perl use Time::HiRes qw(gettimeofday); @slens = (0, 1, 1, 2, 2, 3, 6, 5, 6, 5, 5, 7, 8, 7, 9, 8, 10, 8, 9, 10, 11, 11, 11, 13, 11, 14, 13, 14, 13, 15, 18, 16, 18, 19, 20, 19, 23, 19, 23, 21, 21, 20, 22, 22, 24, 26, 25, 25, 27); $failure = 0; $timeout = 0; $optimal = 0; $nonoptimal = 0; $A = "/home/bylander/agents/bin"; for ($i = 1; $i <= 48 && ! $timeout; $i++) { next if ($i == 4); $seed = $i + 100; $a1 = "$A/cookie -n " . $i . " -s " . $seed; $a2 = $ARGV[0]; $command = "$A/interact -v \"" . $a1 . "\" \"" . $a2 . "\""; print "\nrunning $command\n"; ($starts, $startus) = gettimeofday; $pid = open(RUN, "$command |"); $result = 0; $moves = 0; while ($line = ) { if ($line =~ /^$a2:\s*[dlru]\s*$/) { $moves++; } if ($line =~ /^$a1: me full$/) { $result = 1; } } close(RUN); ($ends, $endus) = gettimeofday; $time = ($ends + $endus / 1000000) - ($starts + $startus / 1000000); if (! $result) { print "Failed to find a solution.\n"; $failure++; } else { print "Solution of length $moves found. Used $time seconds.\n"; $len = $slens[$i]; if ($moves > $len) { print "Found a nonoptimal solution of length $moves, optimal is $len.\n"; $nonoptimal++; } else { $optimal++; } } if ($time > 10) { $timeout = 1; print "Timeout: Time exceeded 10 seconds.\n"; if (! $result) {$failure--;} } } printf "Over %d trials, %d are optimal, %d are nonoptimal, and %d are failures.\n", $failure+$optimal+$nonoptimal, $optimal, $nonoptimal, $failure;