Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Gobang Game with python Code

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use python code to achieve Gobang game" related knowledge, the editor through the actual case to show you the operation process, the operation method is simple and fast, practical, I hope that this "how to use python code to achieve Gobang game" article can help you solve the problem.

Put the code first.

# call the pygame library import pygameimport sys# call the commonly used keyword constant from pygame.locals import QUIT,KEYDOWNimport numpy as np# to initialize pygamepygame.init () # to get access to the display system, and create a window screen# window size 670x670screen = pygame.display.set_mode ((670670)) screen_color= [238jue 154je 73] # set canvas color, [238jue 154jue 73] corresponds to brownish yellow line_color = [0J 0c0] # set line color Corresponding to black def check_win (over_pos): # judge Wuzi Lianxin mp=np.zeros ([15recover15]) Dtype=int) for val in over_pos: x=int ((val [0] [0]-27) / 44) y=int ((val [0] [1]-27) / 44) if val [1] = white_color: mp [x] [y] = white else: mp [x] [y] = sunspot for i in range (15): Pos1= [] pos2= [] for j in range (15): if mp [I] [j] = = 1: pos1.append ([I) J]) else: pos1= [] if mp [I] [j] = 2: pos2.append ([iMagnej]) else: pos2= [] if len (pos1) > = 5purl # Wuzi Lianxin return [1m POS 1] if len (pos2) > = 5: return [2 Pos2] for j in range (15): pos1= [] pos2= [] for i in range (15): if mp [I] [j] = = 1: pos1.append ([iMae j]) else: pos1= [] if mp [I] [j] = 2: pos2.append ([I] J]) else: pos2= [] if len (pos1) > = 5: return [1mempos1] if len (pos2) > = 5: return [2 Pos2] for i in range (15): for j in range (15): pos1= [] pos2= [] for k in range (15): if or > = 15: break if mp [iExk] [junik] = = 1: pos1.append ) else: pos1= [] if mp [iExk] [junik] = = 2: pos2.append ([ionomkMagazine]) else: pos2= [] if len (pos1) > = 5: return [1 Pos1] if len (pos2) > = 5: return [2 or j-k=5 pos2] for i in range (15): for j in range (15): pos1= [] pos2= [] for k in range (15): if iTunk > = 15 or j-k=5: return [1 Pos1] if len (pos2) > = 5: return [2mempos2] return [0, [] def find_pos (x Y): # find the location shown where you can fall for i in range (27 and x=R1 and y=L1 and x=R1 and y=L1 and x=R1 and y=L1 and x=R1 and 670 Magazine 44): for j in range (27 record670 Magazine 44): L1=i-22 L2=i+22 R1=j-22 R2=j+22 if x > = L1 and x=R1 and y=L1 and x=R1 and y=L1 and x=R1 and y=L1 and x=R1 and yellow5 L1=i-22 L2=i+22 R1=j-22 R2=j+22 if # five sons linked to the heart return [1 Pos1] if len (pos2) > = 5: return [2 pos1.append 2] for j in range (15): pos1= [] pos2= [] for i in range (15): if mp [I] [j] = 1: pos1.append ([I] J]) else: pos1= [] if mp [I] [j] = 2: pos2.append ([iMagnej]) else: pos2= [] if len (pos1) > = 5: return [1 if len] if len (pos2) > = 5: return [2 Pos2] for i in range (15): for j in range (15): pos1= [] pos2= [] for k in range (15): if or > = 15: break if mp [iExk] [junik] = = 1: pos1.append ) else: pos1= [] if mp [iExk] [junik] = = 2: pos2.append ([ionomkMagazine]) else: pos2= [] if len (pos1) > = 5: return [1 Pos1] if len (pos2) > = 5: return [2 or j-k=5 pos2] for i in range (15): for j in range (15): pos1= [] pos2= [] for k in range (15): if iTunk > = 15 or j-k=5: return [1 Pos1] if len (pos2) > = 5: return [2mempos2] return [0, []]

If the run is not successful, download pip install pygame,pip install numpy on pycharm

My version is pycharm3.7.

On "how to use python code to achieve Gobang game" content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report