Pages

Sunday, January 13, 2019

Being Useful

Always feels good to help people with things. Sometimes this is just recommending resources, but sometimes I get to flex my slowly-dying engineer muscles. These are two things I got to help people with recently on some Discord chats, but Discord is temporary so I'm writing them down here for posterity.

RPS Mechanics in Play-by-Post Games

Image source: wikimedia.

Rock-paper-scissors only works in person because you can throw more-or-less simultaneously. In a play-by-post environment, someone has to go first. Here's how:
  1. Alice generates a random number and appends it to her choice.
    Example: "paper04"
  2. Alice takes a hash* of the result and shares it.
    Example: "md5:fbe1a7f5e0330c5cf5a986d40065a21e"
  3. Bob shares his choice.
    Example: "scissors"
  4. Alice shares her original string.
    Example: "paper04"
  5. Bob checks the hash of the original string.
This is not a protocol focused on security. For example, given that the salt is a number 00-99, Bob could generate a rainbow table of all the possible checksums and guess Alice's answer before she revealed it.
It could be automated in some ways if you ran the forum, for example, a bot could automate the final check.




Weighted Selection from a Compact Table

It's common for a table in a book to be formatted like:
1-10. Very common result
11-15. Less common result
16-19. Slightly less common result
20. Very rare result
This is useful if you want to mimic a specific type of distribution given a flat input curve. The theory is that if you use this table a lot, then it will make the results feel more natural.
This presents a problem if you would like to automatically roll on the table in a spreadsheet. A naive way to do this is the format it like:
(A1) Very common result
(A2) Very common result
(A3) Very common result
. . .
(A20) Very rare result
But this is time-consuming and annoying to change. Using VLOOKUP, you can format it like:
(A1) 10 (B1) Very common result
(A2) 15 (B2) Less common result
(A3) 19 (B3) Slightly less common result
(A4) 20 (B4) Very rare result
And then roll as normal. There is a (rough) proof of concept here. There's a couple mistakes in it, but if you play around with it you can see how it works.
Cols A & B are the actual table, while Cols C & D are for illustrative purposes and aren't necessary for the table to function. Cols E & F show how an automated roller might function.
* = I use DuckDuckGo as my default search engine. If you search "md5 [term]" it will auto-suggest the md5sum of "[term]", which is neat. Wolfram Alpha also does this.

No comments:

Post a Comment