You could create a Network script object, and keep track of the total power on there, then when a brick is added, if its a power brick just add to the total power, and when a brick is deleted, if its a power brick, subtract from the total power. When two networks collide, merge them. The hardest part is getting networks to split up, you'll have to loop through everything each time a brick is removed.