Code Question: Rock, Paper, Scissors
MisterBoring last edited by
So I brought up using OWoD LARP mechanics in a MU in another thread, and I had a question for the code savvy folks out there:
How would you go about coding RPS into a MU?
For an example, I want to play RPS with Mary.
I should be able to do “RPS Mary” or “+RPS Mary” and get some output that looks like:
You throw rock, paper, scissors with Mary. You throw PAPER! Mary throws SCISSORS! You lose!
Under the hood, in an effort to streamline the process, the game chooses an RPS value for both me and Mary at random, then figures out which one wins. If they are randomly the same, it’s declared a draw.
Jennkryst last edited by
This is Lizard Spock erasure.
Roz last edited by
@MisterBoring It might help to include what codebase/language you’re looking for!
Faraday last edited by
I’m confused. If you’re just going to draw straws at random, why not just do a coin flip or roll a die? A big part of RPS is the strategy of “oh they picked rock last time so I’ll pick scissors” or whatever.
That would be more complicated because you’d need a command that would store state until both characters had entered their thing.
Mourne last edited by
You could have it be determined completely randomly, or, you could have it be that the controller has to set what they are going to throw before hand.
Solstice last edited by Solstice
I started typing it in pseudo code and got very tired because I am not a real coder.
But yes. Store some variables and compare the results, or 1d3.
Faraday last edited by Faraday
If you remove the strategy from RPS by just picking randomly (which, as stated previously, I wouldn’t recommend), there’s an equivalent chance of win, loss, or tie. So just
rand(1,6)(or whatever the equivalent is in your codebase) and emit “You play rock paper scissors with Mary and <result>!” Win on 1-2, Lose on 3-4, and Tie on 5-6.
If you want strategy, then you need each player to enter the commands as a multi-part sequence:
- I do
rps Mary=scissorsand the system stores “scissors” for Faraday v Mary.
- Mary does
rps Faraday=rockand the system recognizes that this is the second piece of the Faraday v Mary game.
- The system compares rock vs scissors and says Mary wins. There are only 9 possible scenarios so it’s not too involved to figure out the outcome.
How precisely you do this will of course vary by codebase.
- I do
Warma Sheen last edited by
Definitely don’t take the player option of of RPS, otherwise there’s no reason to use RPS. That would turn people away.
MisterBoring last edited by
Well, I’m most familiar with TinyMUX, with PennMUSH a close second, so those would be the ones I’d understand the quickest.
To @Faraday @Warma-Sheen : You do have a point about RPS strategy that I hadn’t considered, so perhaps having the command be a bit more interactive so that each player inputs their choice.
Also, @Jennkryst : That’s right, we don’t want your funny signs here.
KarmaBum last edited by
@MisterBoring said in Code Question: Rock, Paper, Scissors:
You do have a point about RPS strategy that I hadn’t considered, so perhaps having the command be a bit more interactive so that each player inputs their choice.
If it only ever runs one game at a time, you can run it so you
rps <choice>and it creates a data attribute on an object. If you’re the first player, it stores your data and emits something about “waiting for 2nd player…”
If it already has one DATA-* attribute, then it knows you’re the second player, and it resolves the match, emits the resolution, and wipes the data.
If it already has two DATA-* attributes, then it is broken.