Jump to content

2048: Difference between revisions

No edit summary
Line 1,633:
 
fun shiftCellsLeft(grid: Array<Array<Int>>): Array<Array<Int>> =
grid.map { row -> mergeAndShiftCellsmergeAndOrganizeCells(row) }.toTypedArray()
 
fun shiftCellsRight(grid: Array<Array<Int>>): Array<Array<Int>> =
grid.map { row -> mergeAndShiftCellsmergeAndOrganizeCells(row.reversed().toTypedArray()).reversed().toTypedArray() }.toTypedArray()
 
fun shiftCellsUp(grid: Array<Array<Int>>): Array<Array<Int>> {
Line 1,649:
 
rows.map { row ->
mergeAndShiftCellsmergeAndOrganizeCells(row)
}.forEachIndexed { rowIdx, row ->
updatedGrid[0][rowIdx] = row[0]
Line 1,671:
 
rows.map { row ->
mergeAndShiftCellsmergeAndOrganizeCells(row)
}.forEachIndexed { rowIdx, row ->
updatedGrid[3][rowIdx] = row[0]
Line 1,682:
}
 
fun mergeAndShiftCellsmergeAndOrganizeCells(row: Array<Int>): Array<Int> = organize(merge(row.copyOf()))
 
fun merge(row: Array<Int>, idxToMatch: Int = 0, idxToCompare: Int = 1): Array<Int> {
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.