is_player_char - 1Fr3aK2/Cub3d GitHub Wiki

๐Ÿ“ is_player_char

Checks whether a given character represents a valid player symbol in the game map.

โš™๏ธ Parameters

Parameter Type Description
c char The character to be checked against the set of valid player characters defined in PLAYER.

๐Ÿ” Returns

Return value Description
true The character c matches one of the valid player characters.
false The character c does not match any valid player characters.

๐Ÿ“– Description

The is_player_char function iterates through the predefined PLAYER character array to determine if the input character corresponds to a playerโ€™s starting position on the map. It is typically used during map parsing to identify the playerโ€™s initial location and orientation.

Step-by-step process:

  1. Initialize index โ€“ Starts at i = 0.
  2. Iterate through PLAYER array โ€“ Loops over each character in the PLAYER array.
  3. Check for match โ€“ If c equals PLAYER[i], immediately return true.
  4. Continue iteration โ€“ If no match is found, increment i and check the next character.
  5. Return false if not found โ€“ If the loop completes without finding a match, return false.

This function is lightweight and ensures that only valid player characters are accepted during map validation.

๐Ÿ’ก Example Usage

char c = 'N';

if (is_player_char(c))
{
    printf("%c is a valid player character.\n", c);
}
else
{
    printf("%c is NOT a valid player character.\n", c);
}