Skip to content

Instantly share code, notes, and snippets.

@savage69kr
Forked from netvarun/2048-as-a-service-perl
Created May 1, 2014 12:20
Show Gist options
  • Save savage69kr/05781edac11c5ee0249d to your computer and use it in GitHub Desktop.
Save savage69kr/05781edac11c5ee0249d to your computer and use it in GitHub Desktop.
perl -e 'my $host = "http://2048.semantics3.com/hi/";my $cmd = "curl --silent -L $host"."start";my $output = `$cmd`;my $session_id = $output;$session_id=~s/.*?ID:\s(\w+).*/$1/si;my %keyMap = ( 'w' => 0, 'd' => 1, 's' => 2, 'a' => 3);print STDERR $output,"\n";while(1) { print STDERR "Input (w - up, a - left, d - right, s - down):\n"; my $userInput = <STDIN>; chomp ($userInput); if(defined($keyMap{$userInput})) { $userInput = $keyMap{$userInput}; } else { print STDERR "Invalid move.. w - up, a - left, d - right, s - down\n"; next; } my $cmd = "curl --silent $host"."state/$session_id/move/$userInput"; my $output = `$cmd`; print STDERR "\n$output\n"; if($output=~/Message:/si) { exit(0); }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment