Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #James Nguyen
- DIRECTIONS = [[0,-1],[-1,1],[1,-2],[0,1],[-1,1],[1,1],[-1,0],[1,0]]
- class Game_state:
- def __init__(self,row_col,player):
- self.first_player = player
- self.second_player = self.switch_player(player)
- self.row = row_col[1]
- self.col = row_col[0]
- self.board = self.create_board(player)
- def create_board(self,startingplayer):
- board_list = []
- for row in range(self.col):
- list_items = []
- for col in range(self.row):
- list_items.append(' ')
- board_list.append(list_items)
- #print(board_list[0] == # of columns
- #rowcol[1] = COLUMN
- #rowcol[0] == row
- opposite_player = self.switch_player(startingplayer)
- pos1 = int(self.col/2)
- pos2 = int(self.row/2)
- board_list[pos1][pos2-1] = startingplayer
- board_list[pos1][pos2] = opposite_player
- board_list[pos1-1][pos2]= startingplayer
- board_list[pos1-1][pos2-1]= opposite_player
- return board_list
- def make_move(self,player):
- cur_player = player
- print('It\'s ' + str(player)+ 's turn')
- print('Select row and column to make move')
- row = int(input('Row: '))
- col = int(input('Col: '))
- # self.isValid(row,col)
- #self.validmoves(cur_player)
- self.valid_moves(cur_player)
- def switch_player(self,player):
- if player == 'W':
- return 'B'
- else:
- return 'W'
- ## def _checkDisc(self,row,col):
- ## '''Checks if there is an empty cell'''
- ##
- ## if self.board[row][col] == ' ':
- ## return True
- ## else:
- ## return False
- ##
- def valid_moves(self,player):
- for row in range(len(self.board)):
- for col in range(self.col):
- if self.board[col][row] == player: # returns the position of a player
- for direction in DIRECTIONS: # goes through all possible directions
- self.search_directions(direction,col,row,player)
- def search_directions(self,direction,row,col,player):
- #while True:
- col_move = col #+ #direction[0]
- row_move = row #+ direction[1]
- cur_list = []
- if not self._is_in_board(row_move,col_move):
- return False
- print('it works1')
- while True:
- col_move+=direction[0]
- row_move+=direction[1]
- print('it works asdfadf')
- if self._is_in_board(row_move,col_move):
- if self.board[col_move][row_move] == self.switch_player(player):
- print('it works2')
- self.continue_direction(col_move,row_move,direction)
- else:
- return True
- #elif not self._is_in_board(row_move,col_move) or self.board[col_move][row_move] == player:
- # return False
- else:
- print(col_move,row_move)
- for i in self.board:
- print(i)
- break
- print(cur_list)
- def continue_direction(self,col,row,direction):
- while True:
- col+=direction[0]
- row+=direction[1]
- list1 = []
- if self.board[col][row] == ' ':
- list1.append([col,row])
- print(list1)
- for i in self.board:
- print(i)
- return False
- else:
- return True
- def _is_in_board(self,row,col)->bool:
- return col >=0 and col<= self.col -1 and row >= 0 and row<= self.row-1
- def _isEmpty(self):
- pass
- def _isColor(self,row,col,player):
- return self.board[col][row] == player
- def check_winner(self):
- pass
- def _tilesflip(self):
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement