Explain solidity>complex conditions

Complex Conditions

Right now, anyone can make a move. We need to ensure only the correct player can move on their turn.

Combining Concepts:

We can use the ternary operator inside a require statement to check different conditions.

The Logic:

• If it's X's turn (xTurn is true), require that msg.sender == playerX

• If it's O's turn (xTurn is false), require that msg.sender == playerO



Using Ternary in Require:

require(xTurn ? msg.sender == playerX : msg.sender == playerO, "Not your turn");

This reads as: "Require that if xTurn is true, the sender is playerX, otherwise the sender is playerO."



Add this validation to makeMove after the other require statements to ensure players can only move on their turn.

Validate correct player's turn
0%
Requirements:
Has turn validation require
Uses ternary operator in require
Checks playerX when xTurn is true
Checks playerO when xTurn is false
Inside makeMove function