Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use python to make a simple version of Intelligent Gobang

Shulou Source: shulou.com Published: 2022-06-03 10:54:58 10月03日 Update

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

Tags: Chessboard Gobang Gobang blanks borders simplicity production man-machine code content each other square pieces chess pieces grid intelligence both ends that is location coordinates width Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Apple NVidia Redmi Huawei