you could use graphs and connections to diagram the network and check for a power source. each node in the graph (brick, in this case) would contain a reference to the graph and trigger the graph to dissapate energy or whatever when the graph is changed.
look up graphs and trees and graph representations in terms of computer science; id post some stuff myself here but im on mobile and cant conveniently bring up good resources.