Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the Gobang Game of everyone against each other in python

Shulou Source: shulou.com Published: 2022-05-31 18:29:58 09月15日 Update

This article mainly introduces the relevant knowledge of "how python realizes the Gobang game against everyone". The editor shows you the operation process through the actual case, the operation method is simple and fast, and the practicality is strong. I hope that this article "how to achieve Renren Gobang game with python" can help you solve the problem.

Checkerboard.py

From collections import namedtupleChessman = namedtuple ('Chessman',' Name Value Color') Point = namedtuple ('Point',' X Y') BLACK_CHESSMAN = Chessman ('sunspot', 1, (45,45,45)) WHITE_CHESSMAN = Chessman ('Baizi', 2, (219,219,219)) offset = [(1, 0), (0, 1), (1, 1)] class Checkerboard: def _ init__ (self) Line_points): self._line_points = line_points self._checkerboard = [[0] * line_points for _ in range (line_points)] def _ get_checkerboard (self): return self._checkerboard checkerboard = property (_ get_checkerboard) # determine whether def can_drop (self, point): return self._ checkerboard [point.Y] [point.X] = 0 def drop (self, chessman) Point): "param chessman:: param point: position: return: if the child falls, you can win. Then return to the winning party Otherwise, return None "" print (f'{chessman.Name} ({point.X}, {point.Y})') self._ checkerboard [point. Y] [point.X] = chessman.Value if self._win (point): print (f'{chessman.Name} win') return chessman # to determine whether def _ win (self) is won. Point): cur_value = self._ checkerboard [point.Y] [point.X] for os in offset: if self._get_count_on_direction (point, cur_value, os [0], os [1]): return True def _ get_count_on_direction (self, point, value, x_offset, y_offset): count = 1 for step in range (1 5): X = point.X + step * x_offset y = point.Y + step * y_offset if 0 = Line_Points or y > = Line_Points: return None return Point (x, y) if _ name__ = ='_ main__': main ()

This is the end of the introduction of "how to realize the Gobang game between everyone in python". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Chessboard Gobang Gobang border everyone chess pieces knowledge grid location coordinates actual width screen industry different practical between content area radius Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB Microsoft Apple Xiaomi