func (plan *Plan) canPutStone(x, y int, stone *materials.Stone) bool { for stoneX := 0; stoneX < stone.Width(); stoneX++ { for stoneY := 0; stoneY < stone.Height(); stoneY++ { if !stone.Get(stoneX, stoneY) { continue } if plan.Get(x+stoneX, y+stoneY) { return false } } } return true }
func (plan *Plan) Put(x, y int, stone *materials.Stone) bool { if !plan.puttable(x, y, stone) { return false } // put stone plan.positions = append(plan.positions, &Position{ x: x, y: y, stone: stone, }) plan.refreshBuffer(buffer.Rect{x, y, stone.Height(), stone.Width()}) return true }
func (plan *Plan) isExistRelatedStone(x, y int, stone *materials.Stone) bool { for stoneX := 0; stoneX < stone.Width(); stoneX++ { for stoneY := 0; stoneY < stone.Height(); stoneY++ { if !stone.Get(stoneX, stoneY) { continue } if plan.GetStoneDot(stoneX+x-1, stoneY+y) || plan.GetStoneDot(stoneX+x, stoneY+y-1) || plan.GetStoneDot(stoneX+x+1, stoneY+y) || plan.GetStoneDot(stoneX+x, stoneY+y+1) { return true } } } return false }