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