57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package day22
|
|
|
|
type Space struct {
|
|
MaxZ uint
|
|
SettledOnZ [][]*Block
|
|
MaxSettledOnXY map[XY]*Block
|
|
UnsettledByZ [][]*Block
|
|
}
|
|
|
|
func NewSpace(blocksByZ [][]*Block) Space {
|
|
return Space{
|
|
UnsettledByZ: blocksByZ,
|
|
MaxZ: uint(len(blocksByZ)),
|
|
MaxSettledOnXY: make(map[XY]*Block),
|
|
SettledOnZ: make([][]*Block, len(blocksByZ)),
|
|
}
|
|
}
|
|
|
|
// settle all blocks in Z, remove Z from UnsettledByZ
|
|
func (s *Space)SettleZ(z uint) {
|
|
|
|
}
|
|
|
|
// for the block:
|
|
// check all XY in MaxSettledOnXY
|
|
// if there are any settled blocks on these XY, find max of their Z
|
|
// for all blocks with that Z - add block to their 'supports'
|
|
// set Z for block to Z+1, settled to true
|
|
// add block as highest settled for all the XY
|
|
// add block to MaxSettledOnXY
|
|
func (s *Space)SettleBlock(block *Block) {
|
|
underZMax := uint(0)
|
|
underZBlocks := make([]*Block, 0)
|
|
for _, xy := range block.getXY() {
|
|
underBlock, found := s.MaxSettledOnXY[xy]
|
|
// if block.NameNum
|
|
if found {
|
|
if underBlock.Z > underZMax {
|
|
underZBlocks = []*Block{underBlock}
|
|
underZMax = underBlock.Z
|
|
} else if underBlock.Z == underZMax {
|
|
underZBlocks = append(underZBlocks, underBlock)
|
|
}
|
|
}
|
|
s.MaxSettledOnXY[xy] = block
|
|
}
|
|
|
|
for _, settledUnderblock := range underZBlocks {
|
|
settledUnderblock.Supports = append(settledUnderblock.Supports, block)
|
|
}
|
|
|
|
block.Z = underZMax + 1
|
|
block.IsSettled = true
|
|
|
|
s.SettledOnZ[block.Z] = append(s.SettledOnZ[block.Z], block)
|
|
}
|