Second Project - Rock Paper Scissor

Hello @thecil and @dan-i !

I do not know if the time is right but I think it’s worth giving a shot. I have just searched for some junior jobs in the beginning of this week and found one Junior Solidity Developer position in Slingshot.

In order to Apply I need to make the following game project:

https://github.com/slingshot-finance/RockPaperScissors-test-project/blob/main/README.md

So I just made a code all by myself doing my best and this is where I am standing right now:

https://github.com/Riki0923/Rock-Paper-Scissors/blob/main/Rock%20Paper%20Scissor

I do not understand everything regarding the assignment, for example this part:

"Alice and Bob can play the classic game of rock, paper, scissors using ERC20 (of your choosing)."

Also there are some issues in the contract which I do not know how to solve, such as when somebody cancel a round and I do not know how to delete an array, it is on function cancelRound. Also I am planning to add a getAllRoundbyId function which lists every round Id.

I do not want to make this topic too big so all in all what are your toughts on this? This is really my first own hand work, even if I am not getting the job I think it was worth doing it. And of course I appreciate every help and suggestion you can make as always, I have already learnt a lot by being here on the academy.

Thank you!

1 Like

Hi. Just had a look at the README file.

Yeah, some parts seems very confusing.

“Alice and Bob can play the classic game of rock, paper, scissors using ERC20 (of your choosing).”

I think this means that you have to create an ERC20 token first. In other words, the currency in this game is not Ether but it is ERC20 token. So maybe you need to create token exchange as well.

For the cancelRound part, let’s say i is the index to cancel and n is the last index. Replace newRound[i] with newRound[n] and delete the nth array.

I wanna try this project, too.
But one thing I don’t really get is why enroll and play is separated. Also, what do they mean by right token amount?

Hi @REGO350

Did you mean the cancellation like this?

       function cancelRound(uint256 _id) public {
           require(newRound[_id].challenger == msg.sender);
           uint256 lastId = roundsByPlayer[msg.sender][roundsByPlayer[msg.sender].length-1];
           for (uint i = 0; i < roundsByPlayer[msg.sender].length; i++) {
           if (roundsByPlayer[msg.sender][i] == _id) {
               roundsByPlayer[msg.sender][i] = lastId;
               roundsByPlayer[msg.sender].pop();
           }
       }
           
           emit challengerCancelledRound(_id);
       }

I have made a mapping for it and also I have updated my github page. I do not know if it is enough to handle that in, I know this ERC20 thing is still missing. Looking on it right now.

1 Like

Yes. I think the code is correct.

Did you mean the cancellation like this?

I don’t understand this. Does this mean that Charlie bets if Alice or Bob won the previous game? If so, how can you make sure that Charlie doesn’t see the result? You cannot hide even the private variables in public blockchain…

Let players bet their previous winnings.

I did not add the previous winning thing to my code but now maybe I do understand what is going on regarding “Alice and Bob can play the classic game of rock, paper, scissors using ERC20 (of your choosing).”

So does this mean I need to start the coding with a raw ERC20 and use the transfer function, symbol function, decimal function etc. what you can find in an ERC20 contract?

I have added a name and symbol string to the constructor when the contract deploys but I am unsure of this part.

@thecil any thoughts you have on this one?

Thank you!

If you plan to use different many ERC20 contracts, you might want to check out how to use an interface and the contract address of that contract to play around with him.

Carlos Z