Loveless AI
I wrote an AI for Random Person Games' Loveless entry to virtualharby's game jam.
Code
while true; do c=$(import -silent -window 0x160053c ss.bmp ; img2txt -d none -f html3 ss.bmp | perl -ne 'while(/#(.)...(.).">(.*?)<\/font/g){$c="$1$2 ";$t=$3;while($t =~ /<.*?>|(&.*?;|[^&<>])/g){print$c if $1}}print"\n"' | sed 's/55\|0a\|00/ /g' | head -n -4 | tail -n +11 | sed 's/^a0 \|a0 $//g' | sed 's/^a0 / /' | perl -e 'for (1..3) { $_=<>; if (/^(.*?)a0 (.*)/) { $w = length $_; $pc = length($1)/$w; last; } } <>; if (!defined $pc) {$pc = 0.0; <>; <>; <>; } print STDERR "Pin at? $pc\n"; for(1..5) {$_=<>; s/^a0 / /; if (/^(.*?)\S/) { $w=length $_; $bpc=length($1)/$w; last; } } print STDERR "Balloon at? $bpc\n"; if ($bpc > $pc) { $x= "Right\n"; } elsif ($bpc < $pc) { $x= "Left\n" } if ($x) { $sleep=abs($bpc-$pc)**0.5*2/3; print "keydown --window 0x160053c $x sleep $sleep keyup --window 0x160053c $x" }'); echo command: "$c"; if [ -n "$c" ]; then xdotool $c; sleep 0.1; fi; done
Demo