GridWorld - an environment to run intelligent agents.
use GridWorld; my $grid = new GridWorld( xSize => 8, ySize => 8, stuff => 'dirt', dirtFraction => 0.3); $grid->runVacuumAgent( verbose=>1 );
An environment to run intelligent agents.
Runs a simple AI vacuum cleaner ``agent'' in a checkerboard world with dirt on some of the squares.
Here's an example of an agent.
# Input: reference ($percepts->{key}=value) hash of perceptions. # Output: action taken (string) sub reflexAgent { my ($percept) = @_; return 'suck' if $percept->{dirt}; return (qw(turnLeft turnRight))[int(rand(2))] if $percept->{bump}; return (qw( forward forward forward turnRight turnLeft ))[ int(rand(5)) ]; }
And here's an example of a ``performance measure'' used to evaluate the agent's performance.
# Input: reference ($result->{key}=value) of results of actions. # Output: numeric score for that result. sub performanceMeasure { my ($result) = @_; return 100 if $result->{suck}; return -1 if $result->{move}; return 0; }
References to both of these routines may be specified in the runVacuumAgent call. The key => value pairs which may be passed are
runVacuumAgent( x => $startX, y => $start, direction => $startDirection, agent => \&agentFunction, performance => \&performanceFunction, verbose => 'yes' (the default) or 'no' );
The directions are (left, right, up or down).
Actions are (forward, turnRight, turnLeft, suck, wait).
Results of actions, passed to the performanceMeasure function, are (suck, move).
None.
Artificial Intelligence: A Modern Approach, by Stuart Russel and Peter Norvig, chapter 2.
Jim Mahoney, <mahoney@marlboro.edu
Copyright 2003 by Jim Mahoney
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.