In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to achieve Gobang game based on Python". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to achieve Gobang game based on Python" can help you solve your doubts.
Everyone against each other
The rules of the game: p1 is sunspot, p2 is white, sunspot is first hand, one side reaches the connection of five sons is the victory.
Dynamic demonstration
Source code sharing
Cheackboard.py
Define the black and white, the location of the fallen, and the winning rules.
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)
Execution file
If _ _ name__ = ='_ _ main__': main () man-machine war
Dynamic demonstration
After reading this, the article "how to realize Gobang Game based on Python" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.