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 realize the Gobang Game of everyone against each other in python

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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.

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