engine.py
def possible_moves(self, game_state, from_position):
        """Return all moves this piece can make if it's located at from_position"""
        # Row and column for the position.
        [from_r, from_c] = [from_position // 8, from_position % 8]
        capture_move_list = []
        non_capture_move_list = []

        # Moves up right.
        r = from_r + 1
        c = from_c + 1
        while r < 8 and c < 8:
            to_position = r * 8 + c
            piece = game_state.board[to_position]
            if piece:
                # If capture.
                if piece.white != self.white:
                    move = Move()
                    move.add_change(from_position, self, None)
                    move.add_change(to_position, piece, self)
                    capture_move_list.append(move)
                break
            else:
                move = Move()
                move.add_change(from_position, self, None)
                move.add_change(to_position, None, self)
                non_capture_move_list.append(move)
            c += 1
            r += 1

        # Moves up left.
        r = from_r + 1
        c = from_c - 1
        while r < 8 and c >= 0:
            to_position = r * 8 + c
            piece = game_state.board[to_position]
            if piece:
                # If capture.
                if piece.white != self.white:
                    move = Move()
                    move.add_change(from_position, self, None)
                    move.add_change(to_position, piece, self)
                    capture_move_list.append(move)
                break
            else:
                move = Move()
                move.add_change(from_position, self, None)
                move.add_change(to_position, None, self)
                non_capture_move_list.append(move)
            c -= 1
            r += 1

        # Moves down right.
        r = from_r - 1
        c = from_c + 1
        while r >= 0 and c < 8:
            to_position = r * 8 + c
            piece = game_state.board[to_position]
            if piece:
                # If capture.
                if piece.white != self.white:
                    move = Move()
                    move.add_change(from_position, self, None)
                    move.add_change(to_position, piece, self)
                    capture_move_list.append(move)
                break
            else:
                move = Move()
                move.add_change(from_position, self, None)
                move.add_change(to_position, None, self)
                non_capture_move_list.append(move)
            c += 1
            r -= 1

        # Moves down left.
        r = from_r - 1
        c = from_c - 1
        while r >= 0 and c >= 0:
            to_position = r * 8 + c
            piece = game_state.board[to_position]
            if piece:
                # If capture.
                if piece.white != self.white:
                    move = Move()
                    move.add_change(from_position, self, None)
                    move.add_change(to_position, piece, self)
                    capture_move_list.append(move)
                break
            else:
                move = Move()
                move.add_change(from_position, self, None)
                move.add_change(to_position, None, self)
                non_capture_move_list.append(move)
            c -= 1
            r -= 1

        return (capture_move_list, non_capture_move_list)
Return all moves this piece can make if it's located at from_position
Return all moves this piece can make if it's located at from_position
Return all moves this piece can make if it ' s located at from_position
def possible_moves(self, game_state, from_position):
        [from_r, from_c] = [from_position // 8, from_position % 8]
        capture_move_list = []
        non_capture_move_list = []
        r = from_r + 1
        c = from_c + 1
        while r < 8 and c < 8:
            to_position = r * 8 + c
            piece = game_state.board[to_position]
            if piece:
                if piece.white != self.white:
                    move = Move()
                    move.add_change(from_position, self, None)
                    move.add_change(to_position, piece, self)
                    capture_move_list.append(move)
                break
            else:
                move = Move()
                move.add_change(from_position, self, None)
                move.add_change(to_position, None, self)
                non_capture_move_list.append(move)
            c += 1
            r += 1
        r = from_r + 1
        c = from_c - 1
        while r < 8 and c >= 0:
            to_position = r * 8 + c
            piece = game_state.board[to_position]
            if piece:
                if piece.white != self.white:
                    move = Move()
                    move.add_change(from_position, self, None)
                    move.add_change(to_position, piece, self)
                    capture_move_list.append(move)
                break
            else:
                move = Move()
                move.add_change(from_position, self, None)
                move.add_change(to_position, None, self)
                non_capture_move_list.append(move)
            c -= 1
            r += 1
        r = from_r - 1
        c = from_c + 1
        while r >= 0 and c < 8:
            to_position = r * 8 + c
            piece = game_state.board[to_position]
            if piece:
                if piece.white != self.white:
                    move = Move()
                    move.add_change(from_position, self, None)
                    move.add_change(to_position, piece, self)
                    capture_move_list.append(move)
                break
            else:
                move = Move()
                move.add_change(from_position, self, None)
                move.add_change(to_position, None, self)
                non_capture_move_list.append(move)
            c += 1
            r -= 1
        r = from_r - 1
        c = from_c - 1
        while r >= 0 and c >= 0:
            to_position = r * 8 + c
            piece = game_state.board[to_position]
            if piece:
                if piece.white != self.white:
                    move = Move()
                    move.add_change(from_position, self, None)
                    move.add_change(to_position, piece, self)
                    capture_move_list.append(move)
                break
            else:
                move = Move()
                move.add_change(from_position, self, None)
                move.add_change(to_position, None, self)
                non_capture_move_list.append(move)
            c -= 1
            r -= 1
        return (capture_move_list, non_capture_move_list)
def possible_moves ( self , game_state , from_position ) : [ from_r , from_c ] = [ from_position // 8 , from_position % 8 ] capture_move_list = [ ] non_capture_move_list = [ ] r = from_r + 1 c = from_c + 1 while r < 8 and c < 8 : to_position = r * 8 + c piece = game_state . board [ to_position ] if piece : if piece . white != self . white : move = Move ( ) move . add_change ( from_position , self , None ) move . add_change ( to_position , piece , self ) capture_move_list . append ( move ) break else : move = Move ( ) move . add_change ( from_position , self , None ) move . add_change ( to_position , None , self ) non_capture_move_list . append ( move ) c += 1 r += 1 r = from_r + 1 c = from_c - 1 while r < 8 and c >= 0 : to_position = r * 8 + c piece = game_state . board [ to_position ] if piece : if piece . white != self . white : move = Move ( ) move . add_change ( from_position , self , None ) move . add_change ( to_position , piece , self ) capture_move_list . append ( move ) break else : move = Move ( ) move . add_change ( from_position , self , None ) move . add_change ( to_position , None , self ) non_capture_move_list . append ( move ) c -= 1 r += 1 r = from_r - 1 c = from_c + 1 while r >= 0 and c < 8 : to_position = r * 8 + c piece = game_state . board [ to_position ] if piece : if piece . white != self . white : move = Move ( ) move . add_change ( from_position , self , None ) move . add_change ( to_position , piece , self ) capture_move_list . append ( move ) break else : move = Move ( ) move . add_change ( from_position , self , None ) move . add_change ( to_position , None , self ) non_capture_move_list . append ( move ) c += 1 r -= 1 r = from_r - 1 c = from_c - 1 while r >= 0 and c >= 0 : to_position = r * 8 + c piece = game_state . board [ to_position ] if piece : if piece . white != self . white : move = Move ( ) move . add_change ( from_position , self , None ) move . add_change ( to_position , piece , self ) capture_move_list . append ( move ) break else : move = Move ( ) move . add_change ( from_position , self , None ) move . add_change ( to_position , None , self ) non_capture_move_list . append ( move ) c -= 1 r -= 1 return ( capture_move_list , non_capture_move_list )
Return all moves this piece can make if it's located at from_position
Return all moves this piece can make if it ' s located at from_position
"""Return all moves this piece can make if it's located at from_position""" # Row and column for the position. # Moves up right. # If capture. # Moves up left. # If capture. # Moves down right. # If capture. # Moves down left. # If capture.
self
game_state
from_position