Rock-paper-scissors: Difference between revisions

Added an implementation of Rock Paper Scissors in Lasso. Requires a web server, checks for query-string parameters.
(First implementation of PL/I)
(Added an implementation of Rock Paper Scissors in Lasso. Requires a web server, checks for query-string parameters.)
Line 1,714:
you 2
me 1</pre>
 
=={{header|Lasso}}==
<lang Lasso>[
encode_set(-encodenone);
session_start('user');
 
define_tag("winner", -required="c", -type="string", -required="p", -type="string");
if(#c == $superior->find(#p));
return("Lasso");
else(#p == $superior->find(#c));
return("User");
else;
return("Nobody");
/if;
/define_tag;
 
var("choice") = action_param("choice");
var("computer_choice") = "";
var("lookup") = map("rock"=1, "paper"=2, "scissors"=3);
var("superior") = map("rock"="paper", "paper"="scissors", "scissors"="rock");
var("controls") = "<a href=?choice=rock>Rock</a> <a href=?choice=paper>Paper</a> <a href=?choice=scissors>Scissors</a> <a href=?choice=quit>Quit</a><br/>";
 
if(string($choice) == "quit");
output("See ya. <a href=?>Start over</a>");
session_end('user');
 
else(array("rock","paper","scissors") >> $choice);
 
output($controls);
 
if(!var_defined("historic_choices"));
var("historic_choices") = map("rock"=0, "paper"=0, "scissors"=0);
var("plays") = 0;
session_addvar("user", "historic_choices");
session_addvar("user", "plays");
$computer_choice = $lookup->get(math_random(-lower=1, -upper=4))->first;
/if;
 
if($plays != 0);
local("possibilities") = array();
iterate($lookup, local("i"));
loop($historic_choices->find(#i->first)); #possibilities->insert(#i->first); /loop;
/iterate;
$computer_choice = $superior->find(#possibilities->get(math_random(-lower=1, -upper=($plays))));
/if;
 
output("User chose " + $choice + "<br/>");
output("Lasso chose " + $computer_choice + "<br/>");
output(winner(string(($computer_choice)), $choice) + " wins!");
 
$historic_choices->find($choice) = $historic_choices->find($choice)+1;
$plays = $plays+1;
session_addvar("user", "historic_choices");
session_addvar("user", "plays");
 
 
else($choice->size == 0);
output($controls);
 
else;
output("Invalid Choice.<br/>" + $controls);
/if;
 
/encode_set;
]
</lang>
<pre>Notes: This implementation uses the default session handling in Lasso, and assumes it's running on a web server. User choices are passed in via HTTP as query parameters.</pre>
 
=={{header|Liberty BASIC}}==