Skip to content

Commit 894411e

Browse files
authored
Merge pull request #8 from ripred/codex/find-and-fix-bug-document-solution
Fix LED king color indexing
2 parents 2aaa1c6 + 0d7f135 commit 894411e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ This project isn’t just a chess engine—it’s a blueprint for building lean,
1919

2020
## License
2121
MicroChess is licensed under the MIT License. See the [LICENSE](https://github.com/ripred/MicroChess/blob/main/LICENSE) file for details.
22+
23+
## Bug Fixes
24+
25+
- **LED Strip King Colors**: Kings were sometimes displayed with incorrect LED colors
26+
because the color lookup indexed beyond the end of the color table. The index
27+
now wraps correctly so both white and black kings use the right colors.

led_strip.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ void set_led_strip(index_t const flash /* = -1 */)
6666
static index_t constexpr values_per_led = index_t(3);
6767
static index_t constexpr values_per_side = index_t(sizeof(piece_colors) / 2);
6868

69-
clr = (vars.type * values_per_led) + (vars.side * values_per_side);
69+
// There are only six color definitions per side in piece_colors.
70+
// Piece type values range from 0 (Empty) to 6 (King) so using the
71+
// raw type value would index beyond the table for Kings.
72+
// Mod the type by six to keep the index within bounds.
73+
clr = ((vars.type % 6) * values_per_led) +
74+
(vars.side * values_per_side);
7075

7176
leds[vars.led_index] = (Empty == vars.type) ?
7277
// empty spots

0 commit comments

Comments
 (0)