TwentyOne

First Flight #29
Beginner FriendlyGameFiFoundrySolidity
100 EXP
View results
Submission Details
Severity: medium
Invalid

Function `hit` does not return value for cards

Summary

After calling the hit function, users do not receive any immediate information about the final total value of their cards. Instead, they must invoke the playersHand function to determine whether to receive another card or stop.

Impact

Lack of real-time feedback and increased function calls: Users cannot see their cards value immediately after hitting, forcing them to repeatedly call playerHand to assess their situation.

Tools Used

Manual code review.

Recommendations

Apply this code:

+ function hit() public returns(uint256) {
require(
playersDeck[msg.sender].playersCards.length > 0,
"Game not started"
);
uint256 handBefore = playersHand(msg.sender);
require(handBefore <= 21, "User is bust");
uint256 newCard = drawCard(msg.sender);
addCardForPlayer(msg.sender, newCard);
uint256 handAfter = playersHand(msg.sender);
if (handAfter > 21) {
emit PlayerLostTheGame("Player is bust", handAfter);
endGame(msg.sender, false);
}
+ return handAfter;
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.