Task

Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player.

Rock Paper Scissors is a two player game.

Each player chooses one of rock, paper or scissors, without knowing the other player's choice.

The winner is decided by a set of rules:

   Rock beats scissors
   Scissors beat paper
   Paper beats rock


If both players choose the same thing, there is no winner for that round.

For this task, the computer will be one of the players.

The operator will select Rock, Paper or Scissors and the computer will keep a record of the choice frequency, and use that information to make a weighted random choice in an attempt to defeat its opponent.



Extra credit

Support additional choices   additional weapons.




 
Red [Purpose: "Implement a rock-paper-scissors game with weighted probability"]
 
prior: rejoin choices: ["r" "p" "s"]
 
while [
	find choices pchoice: ask "choose rock: r, paper: p, or scissors: s^/"
] [	
	print ["AI Draws:" cchoice: random/only prior]
	cwin: select "rpsr" pchoice
	close: select "rspr" pchoice
 
	print case [
		pchoice = cchoice ["tie"]
		cchoice = cwin ["you lose"]
		'else ["you win"]
	]
 
	append prior cwin		;adds what would have beaten player
	remove find prior close		;removes what would have lost to player
]
 