in reply to AI in Perl - proof of concept
Output:#!/usr/bin/perl -w use strict; use warnings 'all'; use re 'eval'; use vars qw /%owns %valuable @thief/; %owns = (merlyn => [qw /gold/], ovid => [qw /pocketLint cheapWhiskey/], kudra => [qw /dominationFund/], badguy => [qw /water/], Abigail => [qw /pearls rubies/],) ; %valuable = map {$_ => 1} qw /gold dominationFund pearls/; @thief = qw /badguy Abigail/; my $regex; my $thief_rule = join "|\n" => map {"(?{ \$thief = qq !$_! })"} @thie +f; $regex .= "(?: $thief_rule )\n"; my $victim_rule = join "|\n" => map {"(?{ \$victim = qq !$_! })"} keys + %owns; $regex .= "(?: $victim_rule )\n"; # Don't steal from yourself. $regex .= "(?(?{ \$thief eq \$victim }) fail)\n"; # Victim needs to be rich. $regex .= "(?(?{ \@loot = grep {\$valuable {\$_}} \@{\$owns {\$victim}} } +) |\n" . "(?{ print qq !\$thief does not steal from \$victim\n!}) fail +)\n"; $regex .= "(?(?{ print qq !\$thief steals \@loot from \$victim +\n! })" . "fail)\n"; "" =~ /$regex/x;
badguy does not steal from ovid badguy steals pearls from Abigail badguy steals dominationFund from kudra badguy steals gold from merlyn Abigail does not steal from ovid Abigail does not steal from badguy Abigail steals dominationFund from kudra Abigail steals gold from merlynI'm not quite satisfied with the regex though; it would be nice if the regex could be independent of the content of the variables. I haven't been able to find a way to say "this (sub)expressions just failed. Let's try the same thing again".
Abigail
|
---|