✅ having stupidity. why can THE ROOOOOOOOOOOOOOOOK!!! move through the first pawn?
here is the valid moves code:
38 Replies
shouldn't you break instead of continue, otherwise; yes you cannot move on top of another piece but you shouldn't be able to move through the piece
I'm not really a chess player however, I prefer Sudoku
verify this by adding two pawns at: F4, G4 then see if you can move your D4 to H4
you will see the problem is not that you can move through the first pawn but you can move through pieces in general
i can infact move through pieces
breaking instead of continuing has the same effect
i feel like the only solution i can think of is having 4 for loops instead of 2
if you break at the first collision then it should not happen right?
that's the issue - if i break too early, then the other position wont be considered (the other side of the rook which is not blocked)
so i think i should try 4 for loops
oh I see what you mean, you are checking the horizontal / vertical moves in one pass from left / right and top/bottom
yeah maybe if you check each side it may be more applicable
yes
ok i'll see if it works
i think its working now
🥳
nevermind
yeah that's not right 😭
what does your loop look like
this is pretty trash but
you are just not looping the correct distance it looks like
iooooh
your right
i should do x >= 0
not > 0
silly me
maybe something like this
no wait
that's for the left move
how would I get distance from left side board
take your current position I guess actually
if the left side of the board = 0
depends on how your coordinate system works
wouldnt distance from left side just be position.x
yeah that's what I just said
yeah
you could technically use Board.Width because you dispose of any moves outside of the board, but that's really inefficient
yeaah
then for the right move to calculate the distance to check you can just take Board.Width and subtract your Position.x
like that?
try it and see
nothing
i think tis catching myself
yeah I was just going to mention
the loop actually starts at 0
because
new Position(Position.x + x, Position.y);
where x = 0
is just
Positionit's going to hit yourself
💀
just make it start at 1
my bad
malding, seething, coping simultaneously rn
post your loop
its just that but with 1 as the initial value and I added the y axis as well
I guess just debug it with a breakpoint and ensure each value you are seeing is what you expect
step through the code using the debugger
time to do random shit and hope it works edition
(news flash - it worked!)
adding one to position.x / ychanged it