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 python to make a simple version of Intelligent Gobang

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

Share

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

Today, I will talk to you about how to use python to make an easy version of intelligent Gobang, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Some time ago, I made an upgraded version of Gobang!

But some fans sent me a private message saying:

"ready to get the code and play with ok! it's too hard to get ready to put favorites."

< -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