In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
 
            
                     
                
2025-10-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you the relevant knowledge about how to achieve the console version of the simple Gobang game with python. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Running effect:
Complete code + comments:
Finish = False # whether the game ends flagNum = 1 # current chess player mark flagch ='*'# current chess player piece x = 0 # Abscissa y = 0 # current piece ordinate print ('- Gobang game (console version) -') # board initialization checkerboard= [] for i in range (10) : checkerboard.append ([]) for j in range (10): checkerboard [I] .append ('-') def msg (): # output the final winning chessboard print ("\ 033 [1) 37 44m Mustang-") print (" 1 2 3 4 5 6 7 8 9 10 ") for i in range (len (checkerboard)): print (chr (I + ord ('A')) +", end='') for j in range (len (checkerboard [I]): print (checkerboard [I] [j] + ") End='') print () print ("- -\ 033 [0m") # output winner if (flagNum = = 1): print ('\ 033 [32m * win! * * 033 [0m') else: print ('033 [32mochess victory! * 033 [0m') while not finish: # print chessboard print ("\ 033 [1x 30th 46m villages -") print ("1 2 3 4 5 6 7 8 9 10") for i in range (len (checkerboard)): print (chr (I + ord ('A')) + ", end='') For j in range (len (checkerboard [I]): print (checkerboard [I] [j] + ", end='') print () print ("--\ 033 [0m ") # judge the current chess player if flagNum = = 1: flagch ='* 'print ('\ 033 [1] 37Ton40m Please * enter the coordinates of the chess pieces (e.g. A1):\ 033 [0mm, end='') # else: flagch ='o' print ('\ 033 [1x] 30) 42m Please enter the pawn coordinates (for example, J5):\ 033 [0mm, end='') # Black word green background # enter the pawn coordinates str = input () ch = str [0] # get the uppercase form of the first character x = ord (ch)-65 y = int (str [1])-1 # determine whether the coordinates are in the chessboard if (x
< 0 or x >9 or y
< 0 or y >9): print ('\ 033 [31m coordinates] * Please re-enter the coordinates you entered incorrectly! *\ 033 [0m') continue # determine whether there are pieces on the coordinates if (checkerboard [x] [y] = ='-'): if (flagNum = = 1): checkerboard [x] [y] ='* 'else: checkerboard [x] [y] =' o' else: print ('\ 033 [31m * there are already other pieces in your input position Please re-enter! \ 033 [0m') continue # judge the left side if (y-4 > = 0): if (checkerboard [x] [y-1] = = flagch and checkerboard [x] [y-2] = = flagch and checkerboard [x] [y-3] = = flagch and checkerboard [x] [y-4] = = flagch): finish = True Msg () # judge the right if (y + 4 = 0): if (checkerboard [x-1] [y] = = flagch and checkerboard [x-2] [y] = = flagch and checkerboard [x-3] [y] = = flagch and checkerboard [x-4] [y] = = flagch): finish = True msg () # judge if (x + 4 = 0 and y-4 > = 0): if (checkerboard [x-1] [y-1] = = flagch and checkerboard [x-2] [y-2] = = flagch and checkerboard [x-3] [y-3] = = flagch and checkerboard [x-4] [y-4] = = flagch): finish = True msg () # judge the lower right direction if (x + 4 = 0): if (checkerboard [x + 1] [y-1] = = flagch and checkerboard [x + 2] [y-2] = = flagch and checkerboard [x + 3] [y-3] = = flagch and checkerboard [x + 4] [y-4] = = flagch): Finish = True msg () # judge the upper left direction of the chess piece if (x-4 > = 0 and y + 4
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about

The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r


A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from

Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





 
             
            About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.