highlight losing moves

This commit is contained in:
Thomas Lindner 2023-06-21 23:04:31 +02:00
parent fa079d3a5e
commit b7c1f73a9b

View file

@ -44,6 +44,25 @@ int loser(void) {
return 0;
}
bool selected_edge_loses(void) {
for (int i = 0; i < 6; i++) {
for (int j = i + 1; j < 6; j++) {
for (int k = j + 1; k < 6; k++) {
int a = EDGE(i, j) == selected_edge ? active_player
: edge_color[EDGE(i, j)];
int b = EDGE(j, k) == selected_edge ? active_player
: edge_color[EDGE(j, k)];
int c = EDGE(i, k) == selected_edge ? active_player
: edge_color[EDGE(i, k)];
if (a && a == b && a == c) {
return true;
}
}
}
}
return false;
}
void input(SDL_KeyboardEvent *event) {
switch (event->keysym.scancode) {
case SDL_SCANCODE_UP:
@ -115,7 +134,11 @@ void draw(SDL_Renderer *renderer) {
for (int i = 0; i < 6; i++) {
for (int j = i + 1; j < 6; j++) {
if (EDGE(i, j) == selected_edge) {
ECHK_SDL(thickLineRGBA(renderer, VERTEX(i), VERTEX(j), 10, WHITE));
if (selected_edge_loses()) {
ECHK_SDL(thickLineRGBA(renderer, VERTEX(i), VERTEX(j), 10, RED));
} else {
ECHK_SDL(thickLineRGBA(renderer, VERTEX(i), VERTEX(j), 10, WHITE));
}
} else {
switch (edge_color[EDGE(i, j)]) {
case -1: