[WIP] Basic Rock,Paper, Scissors game

Hey how’s it going everyone! I just received my Arduboy about 5 days ago and I had a lot of fun playing other people’s games. I realized I hadn’t coded in a while and wanted something fun to do, so I made a super basic RPS game. I eventually want to add some music/sounds,graphics, and a 2 Player mode. So I’m just posting this here to get feedback and also any critiques on my code (There are pretty much no tutorials for the arduboy, so a lot of this I got from my CS knowledge and picking at other games source code). If there is a resource I’m missing, please direct me to it, and I would definitely appreciate any help on how to incorporate graphics of some kind through bitmaps, and maybe some basic sound/music tips too. Thanks!


Love the idea! I’ll follow this post :smiley:

1 Like

haha Thanks! It’s pretty bare bones now, but this was after maybe 2 hours or so from idea to end, so it still needs a lot of work!

You can simplify you game logic massively when you say:

R = 1, P = 2, S = 3

x = player_choice
y = ai_choice

result = (x - y + 3) % 3

result == 0 -> tie
result == 1 -> player win
result == 2 -> ai win

just trying to help here :rocket:


Awesome! If you don’t mind me asking, how’d you figure out a formula for that? Also, would something like this work for the “Rock,paper,scissors,lizard,spock” game?

1 Like

I just thought about it xD math is key in programming lol
Yes it is pssible, but you habe to extend it a bit i guess… Haven’t thought it through xD

Unfortunately, I know. I love programming, but hate math haha.

1 Like

Not that big a deal (esp. in this case). Easy enough to store a scoring table in flash:

[item 1, item 2, win?],
[item 1, item 2, win?],
[item 1, item 2, win?]

Then you just loop… and do the inversion if necessary (to avoid storing pairs in both orders). So I think N*(N-1) possibilities. So 10 items would give you 90 possibilities… 270 bytes for scoring (stored in the worst possible way). You can definitely get it down to 180 bytes… of 90 bytes if you limit yourself to 9 items. Then each game state would fit in a single byte. (item 1 [4 bits], item 2 [3 bits], win [1 bit])

…but actually what I’d do (if all combos were equally valid) is look at which is more common (wins or losses) and then just have the table represent one or the other.

So if the game were kind of balanced you could just drop 50% of the items from the table and only include winners… so at the end of a game you search thru the array to see if you “won”… if you reach the end of the array - then you’ve lost - and we’ve cut storage in half.

I have no idea what a formula for 10 items might look like… I bet it would be scary (if even possible). And at that point I’d wager my “store winners” plus a loop might actually use less flash than storing a complex computational formula in order to calculate the result.

1 Like

A truth table is always going to be a lot more readable (and easier to debug) than a crazy formula.


I would store it as a 2D array that would have your choice on the left and their choice on the top. If the answer is 1, then you win, or 2 for their win, and 0 for a tie.

		Rock	Paper	Scissors	Lizard	Spock
Rock		0	2	1		1	2
Paper		1	0	2		2	1
Scissors	1	2	0		1	2
Lizard		2	1	2		0	1
Spock		1	2	1		2	0

EDIT: Oh, gosh… I hope this is formatted the same on other people’s browsers.

That’s a really smart solution! I fell off the way side the past few days, but another member on this forum (L. Torrecilla) posted some graphics that I’ve implemented into the game on github. I still want to add a few more features before I’ll post it in the “finished games” section, but I’m relatively close


Ok now I feel really stupid. You’d use the array index (a 2d array is just a 1d array indexed differently) as “free” ‘storage’ for the item codes and then you’re only storing the actual outcomes in Flash. Nice.

1 Like