In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to use Python to achieve simple Gobang game related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this article on how to use Python to achieve simple Gobang game will have a harvest, let's take a look.
The specific code is as follows
Class CheckerBoard ():''chessboard class' 'def _ _ init__ (self,col=0,row=0 Piece_type='--'): self.col = col self.row = row self.piece_type = piece_type self.labelx = range (self.col) self.labely = range (self.row) def chessboard (self):''chessboard initialization data (state of pieces)' 'checkerboardl = [] for y in self.labely: Heading_list = [] checkerboardl.append (heading_list) for x in self.labelx: heading_list.append (self.piece_type) return checkerboardl def chess_show (self Checkerboardl):''display the status of the pieces' print') for x_title in self.labelx: print (str (x_title) .zfill (2), end='') for y_title in range (len (checkerboardl)): print ('\ nFirst (y_title) .zfill (2) End='') for instans in checkerboardl [y _ title]: print (instans,end='') class User ():''player Class' def _ _ init__ (self,id,name Piece_type):''constructor id: player id ID name: player name piece_type: chess piece status' self.id = id self.name = name self.piece_type = piece_type def play (self,x,y,pool) Data):''play (): the player plays the chess piece x: the x coordinate of the chess piece y: the y coordinate of the chess piece pool: the state set of the chess piece data: the state data of the chess piece on the chessboard' if data [y] [x] not in pool: data [y] [x] = self.piece_type return data True else: print ('\ nposition error) You already have pieces, re-enter:') return data,False def _ _ col_list (self, x, y, col,row) Data):''get the state of all the pieces on the x axis x: the x coordinates of the chess pieces y: the y coordinates of the chess pieces col: the maximum horizontal coordinates of the chessboard row: the maximum vertical coordinates of the chessboard data: the state data of the pieces in the chessboard''# slist = [] slist = data [y] print (slist '_ _ col_list') return slist def _ _ row_list (self, x, y, col,row Data):''get the state of all the pieces on the y axis of the chess board x: the x coordinates of the chess pieces y: the y coordinates of the chess pieces col: the maximum horizontal coordinates of the chessboard row: the maximum vertical coordinates of the chessboard data: in the chessboard The state data of the chess piece''slist = [] for i in data: slist.append (I [x]) print (slist '_ _ row_list') return slist def _ _ left_cut_list (self, x, y, col,row Data):''get the state of all pieces at the left oblique angle of the chess piece x: the x coordinate of the chess piece y: the y coordinate of the chess piece col: the maximum horizontal coordinate of the chessboard row: the maximum vertical coordinate of the chessboard data: the chessboard State data of chess pieces in 'slist = [] if 0 x and y_val_init: x_val_init = x\ x\ y y_val_init = 0 while x_val_init > = 0 and y_val_init 0 and y_val_init
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.