2048: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,633: | Line 1,633: | ||
fun shiftCellsLeft(grid: Array<Array<Int>>): Array<Array<Int>> = |
fun shiftCellsLeft(grid: Array<Array<Int>>): Array<Array<Int>> = |
||
grid.map { row -> |
grid.map { row -> mergeAndOrganizeCells(row) }.toTypedArray() |
||
fun shiftCellsRight(grid: Array<Array<Int>>): Array<Array<Int>> = |
fun shiftCellsRight(grid: Array<Array<Int>>): Array<Array<Int>> = |
||
grid.map { row -> |
grid.map { row -> mergeAndOrganizeCells(row.reversed().toTypedArray()).reversed().toTypedArray() }.toTypedArray() |
||
fun shiftCellsUp(grid: Array<Array<Int>>): Array<Array<Int>> { |
fun shiftCellsUp(grid: Array<Array<Int>>): Array<Array<Int>> { |
||
Line 1,649: | Line 1,649: | ||
rows.map { row -> |
rows.map { row -> |
||
mergeAndOrganizeCells(row) |
|||
}.forEachIndexed { rowIdx, row -> |
}.forEachIndexed { rowIdx, row -> |
||
updatedGrid[0][rowIdx] = row[0] |
updatedGrid[0][rowIdx] = row[0] |
||
Line 1,671: | Line 1,671: | ||
rows.map { row -> |
rows.map { row -> |
||
mergeAndOrganizeCells(row) |
|||
}.forEachIndexed { rowIdx, row -> |
}.forEachIndexed { rowIdx, row -> |
||
updatedGrid[3][rowIdx] = row[0] |
updatedGrid[3][rowIdx] = row[0] |
||
Line 1,682: | Line 1,682: | ||
} |
} |
||
fun |
fun mergeAndOrganizeCells(row: Array<Int>): Array<Int> = organize(merge(row.copyOf())) |
||
fun merge(row: Array<Int>, idxToMatch: Int = 0, idxToCompare: Int = 1): Array<Int> { |
fun merge(row: Array<Int>, idxToMatch: Int = 0, idxToCompare: Int = 1): Array<Int> { |