From 29822a5d0f63bf0c1b34da636ddf27ecf22ca3cb Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Mon, 1 Jun 2026 12:18:28 +0530 Subject: handling recv better & sending smaller packs so i don't need to handle more conditions --- src/engine.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/engine.c') diff --git a/src/engine.c b/src/engine.c index 52aa83b..187be28 100644 --- a/src/engine.c +++ b/src/engine.c @@ -40,19 +40,20 @@ int main(void) { get_moves(&moves, position); send_queue(tx, "Sending", 8); - char buf[128]; - for (int i = 0; i <= moves.length / 32; i++) { - for (int ii = 0; ii < 32; ii++) { - if (moves.length <= 4 * i + ii) continue; - struct sqrstr from_str = sqr_to_str(moves.moves[4 * i + ii].from); - struct sqrstr to_str = sqr_to_str(moves.moves[4 * i + ii].to); - buf[4 * ii + 0] = from_str.data[0]; - buf[4 * ii + 1] = from_str.data[1]; - buf[4 * ii + 2] = to_str.data[0]; - buf[4 * ii + 3] = to_str.data[1]; - buf[4 * ii + 4] = 0; + char buf[65]; + int k = 0; + for (int i = 0; i < moves.length; i++) { + struct sqrstr from_str = sqr_to_str(moves.moves[i].from); + struct sqrstr to_str = sqr_to_str(moves.moves[i].to); + buf[k++] = from_str.data[0]; + buf[k++] = from_str.data[1]; + buf[k++] = to_str.data[0]; + buf[k++] = to_str.data[1]; + if (k == 64) { + buf[k] = 0; + send_queue(tx, buf, sizeof(buf)); + k = 0; } - send_queue(tx, buf, sizeof(buf)); } } -- cgit v1.2.3