Explain solidity>credits system

Credits System

If Player O never accepts, Player X should be able to cancel and get their stake back.

Cancel Requirements:

Only Player X can cancel:

require(msg.sender == playerX, "Only starter can cancel");

The accept deadline must have passed:

require(block.timestamp > acceptDeadline, "Accept period not expired");

Game hasn't been accepted yet:

require(!gameAccepted, "Game already accepted");



Refunding the Stake:

We'll use a credits system for safety. Store the refund amount:

credits[playerX] += stake;

Then reset the game state:

stake = 0;
gameActive = false;



First, add the state variable: mapping(address => uint256) public credits;

Then create the cancelUnaccepted() function.

Add cancel and credits system
0%
Requirements:
Declares credits mapping
Declares cancelUnaccepted function
cancelUnaccepted is public
Checks msg.sender is playerX
Checks deadline expired
Checks game not accepted
Credits playerX the stake
Resets stake to 0
Resets gameActive to false