Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Breadth First Search
- ArrayDeque<Pair<Int, Int>>().let { zeroes ->
- zeroes.addLast(xc to yc)
- val open = { xcc: Int, ycc: Int ->
- if (!(bts[xcc][ycc][1] as Boolean)) {
- (bts[xcc][ycc][0] as JButton).icon =
- ImageIcon(
- getScaledImage(
- ImageIO.read(
- File("src/main/kotlin/utils/${numberTable[xcc][ycc]}.png")
- ),
- bt.width,
- bt.height
- )
- )
- bts[xcc][ycc][1] = true
- cellsLeft--
- if (numberTable[xcc][ycc] == 0)
- zeroes.addLast(xcc to ycc)
- }
- }
- while (zeroes.isNotEmpty()) {
- zeroes.first().let { (xc2, yc2) ->
- if (xc2 > 0) open(xc2 - 1, yc2)
- if (xc2 < x - 1) open(xc2 + 1, yc2)
- if (yc2 > 0) open(xc2, yc2 - 1)
- if (yc2 < y - 1) open(xc2, yc2 + 1)
- if (xc2 > 0 && yc2 > 0) open(xc2 - 1, yc2 - 1)
- if (xc2 > 0 && yc2 < y - 1) open(xc2 - 1, yc2 + 1)
- if (xc2 < x - 1 && yc2 > 0) open(xc2 + 1, yc2 - 1)
- if (xc2 < x - 1 && yc2 < y - 1) open(xc2 + 1, yc2 + 1)
- }
- zeroes.removeFirst()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement