private fun turn22(grid: IntGrid2D, x: Int, y: Int) { val p1: Int val p2: Int val p3: Int val p4: Int p1 = grid.get(grid.stx(x), grid.sty(y)) p2 = grid.get(grid.stx(x + 1), grid.sty(y)) p3 = grid.get(grid.stx(x + 1), grid.sty(y + 1)) p4 = grid.get(grid.stx(x), grid.sty(y + 1))if (p.r.nextBoolean()) { grid.set(grid.stx(x), grid.sty(y), p4) grid.set(grid.stx(x + 1), grid.sty(y), p1) grid.set(grid.stx(x + 1), grid.sty(y + 1), p2) grid.set(grid.stx(x), grid.sty(y + 1), p3) } else { grid.set(grid.stx(x), grid.sty(y), p2) grid.set(grid.stx(x + 1), grid.sty(y), p3) grid.set(grid.stx(x + 1), grid.sty(y + 1), p4) grid.set(grid.stx(x), grid.sty(y + 1), p1) } }
Diffuse a 2x2 block clockwise or counter-clockwise . This procedure was published by Toffoli and Margolus to simulate the diffusion in an ideal gas . The 2x2 blocks will be turned by random in one direction ( clockwise or counter clockwise ) . Usually a second run will be done but this time with a offset of one to the previous run