Tuesday, May 1, 2012

Small Basic Rock Paper Scissors Code

Just a little quickie, this time. I was looking at the Rock, Paper, Scissors that others have written, and Jason boiled it down to 2 lines. Which I think isn't strictly true. I'd have call it one line. Here is another one-liner. This one works by first splitting the input into 3, and splitting it again. Basically, a simpler way to handle multi-dimensional strings. I also added a touch of detail in that you actually type R/P/S as entry. I could have added the code to convert the input into uppercase, but it's long enough as it is.

I do not do tutorials, at least at this time, but I left out all the original code as comments so hopefully, you can learn from it.

'Rock Paper Scissor
' by Harry Hardjono
'April 2012 - GTJ601
'This is an implementation of Rock-Paper-Scissors
'Rock beat Scisscors
'Scisscors beat Paper
'Paper beat Rock
'The input requires capital letter, and is one of these:
'(R)ock, (P)aper,(S)cissors
'The program will randomly choose one of them
'and display the result.
'The output is encoded because I'm too lazy to type them out.
'">R" means "You choose Rock."
'">P" means "You choose Paper."
'">S" means "You choose Scissors."
'"vR" means "Computer chooses Rock."
'"vP" means "Computer chooses Paper."
'"vS" means "Computer chooses Scissors."
'"=W" means "You win!"
'"=L" means "Computer wins!"
'"=D" means "It's a draw!"
'So, ">RvS=W" is interpreted as:
'"You choose Rock. Computer chooses Scissors. You win!"
'The following is the original source code before
'I collapse them into one line.
'Goto Loop

Goto Loop

No comments: