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 use pygame to realize simple Gobang Game

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

< -Inside_Width or pos_y < -Inside_Width: return None x = pos_x // SIZE y = pos_y // SIZE if pos_x % SIZE >

Stone_Radius: X + = 1 if pos_y% SIZE > Stone_Radius: y + = 1 if x > = Line_Points or y > = Line_Points: return None return Point (x, y) class AI: def _ init__ (self, line_points) Chessman): self._line_points = line_points self._my = chessman self._opponent = BLACK_CHESSMAN if chessman = = WHITE_CHESSMAN else WHITE_CHESSMAN self._checkerboard = [[0] * line_points for _ in range (line_points)] def get_opponent_drop (self Point): self._ checkerboard [point.Y] [point.X] = self._opponent.Value def AI_drop (self): point = None score = 0 for i in range (self._line_points): for j in range (self._line_points): if self._checkerboard [j] [I] = 0: _ score = Self._get_point_score (Point (I J) if _ score > score: score = _ score point = Point (I, j) elif _ score = = score and _ score > 0: r = random.randint (0 If r% 2 = 0: point = Point (I, j) self._ checkerboard[ point.Y] [point.X] = self._my.Value return point def _ get_point_score (self, point): score = 0 for os in offset: score + = self._get_direction_score (point, os [0] Os [1]) return score def _ get_direction_score (self, point, x_offset Y_offset): count = 0 # the number of contiguous sons of our side _ count = 0 # the number of contiguous sons of the other party space = None # whether there are spaces in our continuum _ space = None # whether there are spaces in the continuum of the other party both = 0 # whether there is a barrier at both ends of our continuum _ both = 0 # each other Whether there is a barrier at both ends of the continuum # if it is 1, it means that the side is our prescription. 2 means flag = self._get_stone_color (point, x_offset, y_offset, True) if flag! = 0: for step in range (1,6): X = point.X + step * x_offset y = point.Y + step * y_offset if 0

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