If Player O never accepts, Player X should be able to cancel and get their stake back.
Tracking Credits:
First, add a mapping that stores how much ETH each address can withdraw: mapping(address => uint256) public credits;
A mapping is a key-value store. Here the key is a player address and the value is the amount owed.
The next lesson uses this same mapping to build the withdraw function.
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;
Then create the cancelUnaccepted() function.