https://kotlinlang.org logo
Title
o

otakusenpai

12/27/2018, 4:25 AM
so I'm making a chess game and I've got the Rook and pawn's move function ready but I'm having some problem with the Knight's move function.
for(m in 0..(8-x))
                        for(n in 0..(8-y)) {
                            if(board.board[m][n].group != this.group) {
                            }
                        }
All I want is that the 2d array should have the ability to increase or decrease its row and column....without a for loop. Thnx
p

Pavlo Liapota

12/27/2018, 8:04 AM
What do you mean by “to increase row and column of 2d array?”
g

griffio

12/27/2018, 9:07 AM
Maybe something like a cross join using flatmap and map to “loop” through the 2d array?
(0..(8-x)).flatMap { m -> (0..(8-y)).map { n -> m to n } }
p

Pavlo Liapota

12/27/2018, 9:37 AM
Look at https://github.com/korlibs/kds It has
Array2
implementation based on one-dimensional array, so you can just get
data
and iterate though all elements.