chess icon indicating copy to clipboard operation
chess copied to clipboard

Add king check highlighting feature

Open Sama-004 opened this issue 1 year ago • 20 comments

image

https://github.com/code100x/chess/assets/70210929/fc2a98c1-6e94-48f2-ae91-a7a7f8861f8d

Sama-004 avatar Apr 21 '24 04:04 Sama-004

@hkirat can you review the changes

Sama-004 avatar Apr 22 '24 05:04 Sama-004

@hkirat can you review the changes

Can you please impove the algorithm a bit. This is so much important. We cannot check with a 2 loops running and rerendering things in every single piece move. @hkirat Am I right?

SujithThirumalaisamy avatar Apr 22 '24 08:04 SujithThirumalaisamy

@SujithThirumalaisamy @Sama-004

Just use chess.inCheck()

nimit9 avatar Apr 22 '24 08:04 nimit9

@SujithThirumalaisamy @Sama-004

Just use chess.inCheck()

that is being used but how would you highlight the square king is on

Sama-004 avatar Apr 22 '24 08:04 Sama-004

When mapping through the board in the code, we get the access to piece and colour, can use that.

something like piece === "k" and chess.inCheck() And change the background colour if it's true

nimit9 avatar Apr 22 '24 08:04 nimit9

@SujithThirumalaisamy @Sama-004

Just use chess.inCheck()

Oh he said there was no functions for that. My bad

SujithThirumalaisamy avatar Apr 22 '24 08:04 SujithThirumalaisamy

@SujithThirumalaisamy @Sama-004 Just use chess.inCheck()

that is being used but how would you highlight the square king is on

use a global var or state somewhere. just mutate it when a new move comes. And if and only if the move is of a king. Update the state with the new king's location . Simple. You dont even want to itterate. Just get the king from the state. Do the check and update it. @nimit9 Your view on this man?

SujithThirumalaisamy avatar Apr 22 '24 09:04 SujithThirumalaisamy

When mapping through the board in the code, we get the access to piece and colour, can use that.

something like piece === "k" and chess.inCheck() And change the background colour if it's true

@SujithThirumalaisamy this is how you should do it. We're using chess.js which gives you all the required information. No need to have a global state, or anything of that sort

nimit9 avatar Apr 22 '24 09:04 nimit9

When mapping through the board in the code, we get the access to piece and colour, can use that. something like piece === "k" and chess.inCheck() And change the background colour if it's true

@SujithThirumalaisamy this is how you should do it. We're using chess.js which gives you all the required information. No need to have a global state, or anything of that sort

trying this out

Sama-004 avatar Apr 22 '24 09:04 Sama-004

When mapping through the board in the code, we get the access to piece and colour, can use that. something like piece === "k" and chess.inCheck() And change the background colour if it's true

@SujithThirumalaisamy this is how you should do it. We're using chess.js which gives you all the required information. No need to have a global state, or anything of that sort

Perfect, Got it!

SujithThirumalaisamy avatar Apr 22 '24 09:04 SujithThirumalaisamy

When mapping through the board in the code, we get the access to piece and colour, can use that. something like piece === "k" and chess.inCheck() And change the background colour if it's true

@SujithThirumalaisamy this is how you should do it. We're using chess.js which gives you all the required information. No need to have a global state, or anything of that sort

trying this out

No need of the extra function or extra loops, just add this to where we're looping through the board array and rendering the squares. @Sama-004

nimit9 avatar Apr 22 '24 09:04 nimit9

@nimit9 @SujithThirumalaisamy check this out

Sama-004 avatar Apr 22 '24 09:04 Sama-004

Have added the comments, also it'd be great if you can add a video recording of the feature.

nimit9 avatar Apr 22 '24 09:04 nimit9

Have added the comments, also it'd be great if you can add a video recording of the feature.

added

Sama-004 avatar Apr 22 '24 10:04 Sama-004

The color looks bad, can you use the same color as chess.com?

nimit9 avatar Apr 22 '24 10:04 nimit9

@Sama-004 could you please address the comments and make the changes?

nimit9 avatar Apr 22 '24 10:04 nimit9

@Sama-004 could you please address the comments and make the changes?

can't see any comment :(

Sama-004 avatar Apr 22 '24 10:04 Sama-004

Ohh, I'm unable to comment on the PR. They're in the pending state. @hkirat will have to approve the comments for it to show.

Screenshot_2024-04-22-16-29-26-04_320a9a695de7cdce83ed5281148d6f19.jpg

nimit9 avatar Apr 22 '24 10:04 nimit9

@nimit9 anything else?

Sama-004 avatar Apr 22 '24 11:04 Sama-004

@nimit9 anything else?

Haha, no, it's perfect now. Can be merged @hkirat

nimit9 avatar Apr 22 '24 11:04 nimit9

merging for now but there's a small issue I've pointed in the comments

hkirat avatar Apr 25 '24 13:04 hkirat

Ohh, I'm unable to comment on the PR. They're in the pending state. @hkirat will have to approve the comments for it to show.

Screenshot_2024-04-22-16-29-26-04_320a9a695de7cdce83ed5281148d6f19.jpg

@nimit9 fyi: you need to press finish your review. Github collects your reviews thats why it is pending https://github.com/orgs/community/discussions/10369

T0biii avatar Apr 27 '24 02:04 T0biii