Revisiting Rock, Paper, Scissors

In 2017 @giordano (with 2019 @Mason update) wrote about implementing Rock, Paper, Scissors.
Using v1.7 or v1.6, can we do this any better (more: elegantly, performantly, type-stable, gamelike)?
Are there new (or better understood) language elements or uses of the language that appertain?

[added for clarification]
I am a fan of the blog post and have used some of the code in examples over the years.
I am interested in showcasing at least some the same language features and wondering if there are amended approaches that in some manner would improve the implementations.

5 Likes

Maybe pattern matching to avoid repeating play( in each line.

The shapes could be an enum.

From the article:

The main goal of this post is to show how multiple dispatch enables writing generic and extensible code in a few lines.

Rock, paper, and scissors would never be implemented that way if the goal was not to showcase language features. So what you are asking kinda seems to be missing the point, it never was about a good implementation.

1 Like

I am a fan of the blog post and have used some of the code in examples over the years. I am interested in showcasing at least some the same language features – and wondering if there are alternative approaches to good implementations. [I added a note conveying this to my first post – thank you.]

1 Like

I still love this post @giordano. It was the first post that made multiple dispatch β€œclick” for me. Thanks again!

1 Like