so I'm making a chess game and I've got the Rook a...
# announcements
o
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.
Copy code
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
What do you mean by “to increase row and column of 2d array?”
g
Maybe something like a cross join using flatmap and map to “loop” through the 2d array?
Copy code
(0..(8-x)).flatMap { m -> (0..(8-y)).map { n -> m to n } }
p
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.