Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use pygame to realize simple Gobang Game

Shulou Source: shulou.com Published: 2022-06-02 00:54:38 09月23日 Update

< -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 space border Gobang Gobang position content other party square piece chess piece article grid both ends that is coordinates width screen not much between code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple MariaDB Microsoft OPPO Reno