Explain solidity>input validation

Input Validation

When starting a game, we need to make sure the opponent address is valid.

Invalid Opponents:

There are two types of invalid opponent addresses:

1. address(0) - The zero address can't play

2. msg.sender - You can't play against yourself!



Using != Operator:

!= means "not equal to"

It's the opposite of == (equal to)



Adding Validation:

In startGame, add two require statements:

require(_opponent != address(0), "Invalid opponent");

require(_opponent != msg.sender, "Cannot play yourself");



These checks ensure only valid games can start.

Add opponent validation
0%
Requirements:
Checks opponent is not address(0)
Includes error message for address(0)
Checks opponent is not msg.sender
Includes error message for self-play
Validations are in startGame
Validations before state changes