/// <summary>
    /// Determines the board links and neighbors.
    /// Each board piece will have the reference to its direct neighbor (Top, TopRight, Right, etc.) or null for border pieces.
    /// Also, each board piece will have the reference to its logical linked neighbor (TopLink, TopRightLink, etc.) or null if they don't have
    /// any link in a certain direction.
    /// The logical links are mostly used for the logic behind the tiles gravity system.
    /// For example when dealing with empty board pieces, the piece above the empty slot will have logical link to the non-empty-piece below the empty slot.
    /// Thus it will fall through the empty pieces.
    /// </summary>
    public void DetermineBoardLinksAndNeighbors()
    {
        // Auto-determine board pieces neighbors. (only for pieces that have the "autoDetermineNeighbors" flag set)
        Board.ApplyActionToAll((boardPiece) =>
        {
            Match3BoardPiece match3Piece = boardPiece as Match3BoardPiece;
            match3Piece.UpdateNeighbors();

            if (match3Piece.autoDetermineLinks)
            {
                match3Piece.UpdateLinks();
            }
        });

        if (OnDetermineBoardLinksAndNeighbors != null)
        {
            OnDetermineBoardLinksAndNeighbors();
        }
    }