def __init__(self, app, game_controller, user_interaction, *args, **kwargs): super().__init__(*args, **kwargs) ''' params:- app : Visualliser : Object that has spawned this one game_controller : Game assigned to this board user_interaction : bool : True if you want the user to be able to interact with the visuals else False ''' self.cols = 2 board_grid = GridLayout() self.app = app self.game_controller = game_controller # will hold all squares created by below function for later callback self.squares = [] board_map = game_controller.get_map() # Makes a vertical board board_grid.cols = board_map._size[0] board_grid.rows = board_map._size[1] * board_map._size[2] # Loops through all map coords for z, y, x in loops(range(board_map._size[2]), range(board_map._size[1]), range(board_map._size[0])): current = board_map.get_gridpoi(x, y, z) temp = Square(app, game_controller, x, y, z) temp.update_square(x, y, z, current) self.squares.append(temp) board_grid.add_widget(temp) self.add_widget(board_grid) if user_interaction: attack_board_ui = GridLayout() attack_board_ui.size_hint_x = None attack_board_ui.width = 50 attack_board_ui.cols = len(board_map._get_attack_board_array()[0]) attack_board_ui.rows = len(board_map._get_attack_board_array()) for y, x in loops( range(len(board_map._get_attack_board_array())), range(len(board_map._get_attack_board_array()[0]))): temp = Square(app, game_controller, x, y, 'AttackBoard') attack_board_ui.add_widget(temp) self.add_widget(attack_board_ui)
def get_pieces_search(self, poisitive, team=None, piece_type=None): ''' params:- team : str : Team to look for peices returns:- [((int,int,int), Piece_subclass), ...] : Searchs entire board and returns the coordinates and piece object of the piece found ''' pieces = [] for x, y, z in loops(range(self._size[0]), range(self._size[1]), range(self._size[2])): # Check if at x,y,z in board it is a subclass of Piece and part of team if issubclass(type(self.get_gridpoi(x, y, z)), Piece): checks = poisitive if team != None and self.get_gridpoi(x, y, z).team != team: checks = not poisitive if piece_type != None and type(self.get_gridpoi( x, y, z)) != piece_type: checks = not poisitive if checks: pieces.append(((x, y, z), self.get_gridpoi(x, y, z))) return pieces
def valid_move_coords(self, board, x, y, z): ''' params:- board : Map : Board with respect to x,y,z : int : Coords of piece returns:- [{'coords' : (int,int,int), 'mv_type' : str}, ...] : List of all moves that can be made from this piece ''' testable_moves = [] for dx, dy, dz in loops(range(-1, 2), range(-1, 2), range(-1, 2)): if not (dx == 0 and dy == 0 and dz == 0): current = self.test_coord(board, x + dx, y + dy, z + dz) if current != False and current['mv_type'] != 'Defending': # Simulates map and if in check then not a untested valid move simulated_map = copy.deepcopy(board) simulated_map.move_piece(x, y, z, x + dx, y + dy, z + dz) if not simulated_map.is_in_check(self.team, type(self)): testable_moves.append([x + dx, y + dy, z + dz]) elif current != False and current['mv_type'] == 'Defending': testable_moves.append([x + dx, y + dy, z + dz]) # Tests all moves return self.test_coords(board, testable_moves)
def get_diffrence_area_coords(self): area_coords = [] for dx, dy in loops([0, 1], [0, 1]): area_coords.append((dx, dy, 0)) return area_coords
def valid_move_coords(self, board, x, y, z): ''' params:- board : Map : Board with respect to x,y,z : int : Coords of piece returns:- [{'coords' : (int,int,int), 'mv_type' : str}, ...] : List of all moves that can be made from this piece ''' testable_moves = [] # Creates all moves that horse could create on x axis for dx, dy, dz in loops([-2, 2], [-1, 1], [-1, 0, 1]): testable_moves.append([x + dx, y + dy, z + dz]) # Creates all moves that horse could create on y axis for dx, dy, dz in loops([-1, 1], [-2, 2], [-1, 0, 1]): testable_moves.append([x + dx, y + dy, z + dz]) # Tests all moves return self.test_coords(board, testable_moves)
def get_all_pieces(self): ''' params:- None returns:- [((int,int,int), Piece_subclass), ...] : Searchs entire board and returns the coordinates and piece object of the piece found ''' all_pieces = [] for x, y, z in loops(range(self._size[0]), range(self._size[1]), range(self._size[2])): # Check if at x,y,z in board it is a subclass of Piece if issubclass(type(self.get_gridpoi(x, y, z)), Piece): all_pieces.append(((x, y, z), self.get_gridpoi(x, y, z))) return all_pieces
def valid_move_coords(self, board, x,y,z): ''' params:- board : Map : Board with respect to x,y,z : int : Coords of piece returns:- [{'coords' : (int,int,int), 'mv_type' : str}, ...] : List of all moves that can be made from this piece ''' valid_moves = [] for dx,dy,dz in loops([-1,1], [-1,1], range(-1,2)): for i in self.rec_line_StarTrek(board, x+dx, y+dy, z+dz, dx,dy, []): if not(i in valid_moves): valid_moves.append(i) return valid_moves
def valid_move_coords(self, map, ax, ay): ''' params:- map : Map : Board of which respect to ax,ay : int : Poistion of attack board in the attackmap returns:- [(int,int), ...] : Suitable coords for attack board to be able to move to ''' valid_moves = [] for dx, dy in loops([-1, 0, 1], [-1, 0, 1]): if not (dx == dy): current = map.get_attack_gridpoi(ax + dx, ay + dy) if type(current) == tuple: valid_moves.append((ax + dx, ay + dy)) return valid_moves
def valid_move_coords(self, board, x, y, z): ''' params:- board : Map : Board with respect to x,y,z : int : Coords of piece returns:- [{'coords' : (int,int,int), 'mv_type' : str}, ...] : List of all moves that can be made from this piece ''' moves = [] for dz in range(-1, 2): # Forward movements current = self.test_coord(board, x + self.facing[0], y + self.facing[1], z + dz) if current != False and current['mv_type'] == 'Move': moves.append(current) if self.moved == False: current = self.test_coord(board, x + self.facing[0] * 2, y + self.facing[1] * 2, z + dz) if current != False and current['mv_type'] == 'Move': moves.append(current) # Taking movements for dx, dy in loops(range(-1, 2), range(-1, 2)): # Checks whether diffrence between facing and dx,dy is less than 90 degress # And are not equal if sum([i * j for (i, j) in zip(self.facing, [dx, dy]) ]) > 0 and (dx, dy) != self.facing: current = self.test_coord(board, x + dx, y + dy, z + dz) if current != False and current['mv_type'] == 'Take': moves.append(current) return moves
def valid_move_coords_untested(self, board, x, y, z): ''' params:- board : Map : Board with respect to x,y,z : int : Coords of piece returns:- [{'coords' : (int,int,int), 'mv_type' : str}, ...] : List of all moves that can be made from this piece, not tested to see if in check after the move. This is needed due to a recursion error in is_in_checkmate ''' testable_moves = [] for dx, dy, dz in loops(range(-1, 2), range(-1, 2), range(-1, 2)): if not (dx == 0 and dy == 0 and dz == 0): testable_moves.append([x + dx, y + dy, z + dz]) # Tests all moves return self.test_coords(board, testable_moves)
def valid_move_coords(self, board, x, y, z): ''' params:- board : Map : Board with respect to x,y,z : int : Coords of piece returns:- [{'coords' : (int,int,int), 'mv_type' : str}, ...] : List of all moves that can be made from this piece ''' valid_moves = [] for dx, dy, dz in loops(range(-1, 2), range(-1, 2), range(-1, 2)): # Can't test along line of dx, dy == 0 because thats a point if not (dx == 0 and dy == 0): # Due to being StarTrek movement repeats can come from this func # so needs to be filtered for i in self.rec_line_StarTrek(board, x + dx, y + dy, z + dz, dx, dy, []): if not (i in valid_moves): valid_moves.append(i) return valid_moves