Python implements tic-tac-toe game

The examples in this article share the specific code of Python to implement the Tic-Tac-Toe game for your reference. The specific content is as follows

import os
 
def print_board(board):print(board['TL']+'|'+ board['TM']+'|'+ board['TR'])print('-+-+-')print(board['ML']+'|'+ board['MM']+'|'+ board['MR'])print('-+-+-')print(board['BL']+'|'+ board['BM']+'|'+ board['BR'])
 
 
def main():
 init_board ={'TL':' ','TM':' ','TR':' ','ML':' ','MM':' ','MR':' ','BL':' ','BM':' ','BR':' '}
 begin = True
 while begin:
 curr_board = init_board.copy()
 begin = False
 turn ='x'
 counter =0
 os.system('clear')print_board(curr_board)while counter <9:
 move =input('Turn%s move,Please enter location: '% turn)if curr_board[move]==' ':
 counter +=1
 curr_board[move]= turn
 if turn =='x':
  turn ='o'else:
  turn ='x'
 os.system('clear')print_board(curr_board)
 choice =input('Play another round?(yes|no)')
 begin = choice =='yes'if __name__ =='__main__':main()

Effect picture:

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python implements tic-tac-toe game
Python implements tic-tac-toe game
Python implements simple tic-tac-toe game
Python implements Tetris game
Python implements minesweeper game
Python implements guessing game
Python implements WeChat airplane game
Python implements word guessing game
Python implements a guessing game
Python implements digital bomb game
Python implements the brick-and-mortar game
Python simply implements the snake game
Python implements digital bomb game program
Python implements Super Mario
Python implements man-machine gobang
Python, PyGame game project
Python implements image stitching
Python implements the source code of the snake game
Python implements scanning tools
Python implements threshold regression
Python implements minesweeper games
Python implements electronic dictionary
Python implements simple tank battle
Python3 realizes airplane war game
Python implements udp chat window
python guess the word game
Python implements parking management system
Python realizes apple eating game
Python implements TCP file transfer
Python realizes the guessing game
Python numpy implements rolling case
OpenCV Python implements puzzle games
Python implements password strength verification
Python implements car management system
Python implements code block folding
Python implements panoramic image stitching
Python implements SMTP mail sending
Python implements multi-dimensional array sorting
How Python implements FTP function
Python implements mean-shift clustering algorithm
Python implements verification code recognition
Python implements gradient descent method
Python implements text version minesweeper
Python implements image stitching function
How Python implements the mail function
Python3 implements the singleton design pattern
Python implements exchange rate conversion operations
Python implements string and number splicing
Python implements ten classic sorting algorithms
Python implements a universal web framework
Python implements 126 mailboxes to send mail
Python implements AI face change function
Python implements the steepest descent method
Python implements the actual banking system
Python implements ftp file transfer function
Python implements username and password verification
How Python implements the timer function
Python implements the aircraft war project
Python implements horizontal stitching of pictures
Python implements GIF graph upside down
Python implements QQ mailbox to send mail