Select the Mode

Learn how to select the mode.

What we have

We have initialized the board as the first step toward preparing the game for the player(s). It is the stage where we should apply the configurations as per the user’s choice. For Tic-Tac-Toe, we have the possibility to set the game mode: “One Player” or “Two Players”.

When the game starts, it asks us to select a game mode. Let’s create a function that asks the user if they want to play against another human or a computer as the second player.

There are a total of two game modes:

  • One Player

  • Two Players

Requirements of this module

We can ask the user to select an option, store the option in a variable, and return it. We need to perform these steps to complete this task:

  • Display the modes as a prompt for the user.
  • Input the mode (1 or 2 as a character) from the user.
  • Validate the user input: if it’s anything other than 1 or 2, then input again.
  • Return the valid input value.

Sample output

Select game mode:
1. One Player
2. Two Players

Try it yourself

All the functions are already defined. You just have to implement the given function and execute the code.

Get hands-on with 1400+ tech skills courses.