-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve documentation prior submission.
- Loading branch information
Showing
11 changed files
with
129 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
/* Module for communicating to Stockfish `engine.py` via UART. */ | ||
/* | ||
* Module for communicating to Stockfish `engine.py` via UART. | ||
* | ||
* See `engine.py` for details on how the protocol works. | ||
* | ||
* Author: Ellen Xu <[email protected]> | ||
*/ | ||
|
||
#include "assert.h" | ||
#include "chess.h" | ||
|
@@ -15,9 +21,11 @@ static rb_ptr_t *rb; | |
void chess_get_move(char buf[], size_t bufsize) { | ||
assert(bufsize >= 8); | ||
|
||
// When we receive information from the host laptop, there is a chance that | ||
// it might be a command, in which case we enqueue it and jump back to the | ||
// top of the function. | ||
char move[256]; | ||
|
||
/* Gets the move from Stockfish */ | ||
int i = 0; | ||
char ch; | ||
|
||
|
@@ -26,37 +34,36 @@ void chess_get_move(char buf[], size_t bufsize) { | |
ch = uart_getchar(); | ||
move[i++] = ch; | ||
|
||
if (i >= 7 && move[0] != '/') | ||
if (i >= 7 && move[0] != '/') // if not command and too long, break | ||
break; | ||
else if (i >= sizeof(move) - 1) | ||
else if (i >= sizeof(move) - 1) // if command and too long for command | ||
break; | ||
|
||
} while (ch != '\n' && ch != '\0'); | ||
|
||
move[i] = '\0'; | ||
|
||
if (move[0] == '/') { // command | ||
if (move[0] == '/') { // found command | ||
char *cmd = malloc(i); | ||
memcpy(cmd, move + 1, i); | ||
rb_ptr_enqueue(rb, (uintptr_t)cmd); | ||
printf("Enque command: '%s'\n", cmd); | ||
|
||
// caller is expecting a move, so we jump back and see if we get one | ||
i = 0; | ||
goto was_command; | ||
} else { | ||
// copy the move to buffer | ||
memcpy(buf, move, bufsize); | ||
} | ||
} | ||
|
||
char *chess_next_command(void) { | ||
uintptr_t ptr = 0; | ||
rb_ptr_dequeue(rb, &ptr); | ||
if (ptr) | ||
printf("Deq command: '%s'\n", (char *)ptr); | ||
return (char *)ptr; | ||
} | ||
|
||
void chess_send_move(const char* move) { | ||
/* Sends a move to Stockfish (\n terminated)*/ | ||
uart_putstring("\nMOVE_BEGIN\n"); | ||
uart_putstring(move); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
* Module for Stockfish. Communicates over UART with Python script running | ||
* Stockfish on a powerful machine (the Mango Pi would struggle). | ||
* | ||
* See `engine.py` for details on how the protocol works. | ||
* | ||
* Author: Ellen Xu <[email protected]> | ||
* Author: Javier Garcia Nieto <[email protected]> | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Module for chess GUI. Displays a chess board on the screen. Includes | ||
* function to update UI based on new move. | ||
* function to update UI based on new move, sidebar, handling of chess rules | ||
* like passant, promotion and castling. | ||
* | ||
* Author: Ellen Xu <[email protected]> | ||
* Author: Javier Garcia Nieto <[email protected]> | ||
|
@@ -315,6 +316,9 @@ static void sidebar_draw(void) { | |
|
||
line += 3; | ||
|
||
// We figured stats where getting in the way of mvoe history, so we have | ||
// commented them out: | ||
|
||
// draw_text_centered( | ||
// "Stats:", | ||
// SQUARE_SIZE * 8, | ||
|
@@ -400,37 +404,33 @@ static void draw_promote(int cursor) { | |
"Queen" | ||
}; | ||
|
||
if (0 <= cursor && cursor <= 3) { | ||
int char_h = gl_get_char_height(); | ||
|
||
for (int i = 0; i < 4; i++) { | ||
gl_draw_string( | ||
SQUARE_SIZE * 8 + 5, | ||
SQUARE_SIZE * 6 + (char_h + 5) * (i + 1), | ||
PROMOTION_PIECES[i], | ||
cursor == i ? GL_RED : SIDEBAR_FT); | ||
} | ||
} else { | ||
gl_draw_rect( | ||
SQUARE_SIZE * 8, | ||
SQUARE_SIZE * 6, | ||
SCREEN_WIDTH - SQUARE_SIZE * 8, | ||
SCREEN_HEIGHT - SQUARE_SIZE * 6, | ||
SIDEBAR_BG); | ||
int char_h = gl_get_char_height(); | ||
|
||
for (int i = 0; i < 4; i++) { | ||
gl_draw_string( | ||
SQUARE_SIZE * 8 + 5, | ||
SQUARE_SIZE * 6 + (char_h + 5) * (i + 1), | ||
PROMOTION_PIECES[i], | ||
cursor == i ? GL_RED : SIDEBAR_FT); | ||
} | ||
} | ||
|
||
void chess_gui_promote(int cursor) { | ||
draw_promote(cursor); | ||
gl_swap_buffer(); | ||
draw_promote(cursor); | ||
if (0 <= cursor && cursor <= 3) { | ||
draw_promote(cursor); | ||
gl_swap_buffer(); | ||
draw_promote(cursor); | ||
} else { | ||
chess_gui_sidebar(); | ||
} | ||
} | ||
|
||
void chess_gui_draw_cursor(int cursor_col, int cursor_row, bool is_piece_chosen) { | ||
if (is_piece_chosen && !cursor.has_chosen) { | ||
cursor.chosen_col = cursor.col; | ||
cursor.chosen_row = cursor.row; | ||
} else if (!is_piece_chosen && cursor.has_chosen) { | ||
// edge case: easier to just redraw whole board | ||
stale_everything(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ | |
* Module for chess GUI. Displays a chess board on the screen. Includes | ||
* function to update UI based on new move. | ||
* | ||
* For efficiency, the module does its best to only redraw parts of the | ||
* chessboard that are stale by keeping track of updates. It also uses | ||
* DOUBLEBUFFER to avoid artifacts on the screen. | ||
* | ||
* Author: Ellen Xu <[email protected]> | ||
* Author: Javier Garcia Nieto <[email protected]> | ||
*/ | ||
|
Oops, something went wrong.