python Tic-Tac-Toe-text version (on)

Although the python tic-tac-toe game looks very simple, it is very worth learning.

Let's see how to play:

  1. Display the rule description, here is the description of the gameplay, and how to judge the outcome and so on.

  2. Decide who will go first.

  1. Print the chessboard.

  1. The player moves the chess, the computer moves the chess automatically (there is no algorithm calculation, but the empty position is automatically random)

  1. Judging the result, congratulations to the players.


The above is the process of playing, how to write the code?

To write a program with many steps, it is very important to plan the program before writing;

Fake code:

Print display gameplay

Decide who goes first

Create an empty chessboard

Print shows the current board

When no one wins and it is not a tie:

If it's the player's turn

Get the player's chess position

Change the board according to the position

otherwise

Calculate the computer's chess position

Change the board according to the position

Print shows the current board

Switch player

Congratulate the winner or explain the tie


The pseudo code actually shows all the steps very clearly, and it is easier to convert to the corresponding code;

Define a function for each step and adopt a top-down modular design idea;

The most important thing in modular design is to understand what is input and what is output;


Print display

No input or output is required, just print the text content directly.

Decide who goes first

There is interactive input, parameters can be passed in through variables, or input during operation. Here, the second type is used to output the corresponding sequential results.

The same principle applies to other methods. In this process, careful consideration of this design idea is very helpful for the future design of large-scale programs.

Create a chessboard

Show chess board

Player and computer play chess

Switch sides and judge whether you win or lose

Congratulations to players


If you want to break through your own bottleneck in programming, you must first have a very solid foundation, and then practice internal skills, which requires your own deliberate training;

In many cases, we wrote a lot of case code, but there was no essential breakthrough, resulting in no progress.


Recommended Posts

python Tic-Tac-Toe-text version (on)
python tic-tac-toe-text version (part 2)
Install TensorFlow (python2.7 version) on Ubuntu
Install the latest Python 3.6 version on Ubuntu
Ubuntu18.04 switch Python version
Ubuntu16.04 switch python version
Install Python3 on Ubuntu 14.04
Install Python3 on Ubuntu 16.04
PyCharm set Python version
Install Python3.7 on Ubuntu
Install Python 3.7 on Ubuntu 18.04 LTS
Python on image processing PIL
Install python3 on linux, keep python2
Python implements text version minesweeper
Python version of OpenCV installation
Python introductory notes [basic grammar (on)]
How to install Python 3.8 on CentOS 8
How to install Python 3.8 on Ubuntu 18.04
Python version business card management system
How to install Python on CentOS 8
Configure python3 environment on centos7 and
Detailed tutorial on installing python3.7 for ubuntu18
Error when installing Python module on Ubuntu
Draw personal footprint map based on Python
Which version of python does windows support
python drawing | scatter bubble drawing on space map
Check matrix calculation results based on python
Learn Python in one minute | Python functions (on)
How to install Python2 on Ubuntu20.04 ubuntu/focal64
Deploy python3 and nginx projects on ubuntu18.04
Use python3 to install third on ubuntu
Python implements AI automatic version greedy snake