minor code improvements

Fri, 27 Mar 2026 18:11:42 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 27 Mar 2026 18:11:42 +0100
changeset 87
d4d67105d4e1
parent 86
f187e97f845e
child 88
e4a648fe6ce7

minor code improvements

src/chess/game-info.c file | annotate | diff | comparison | revisions
src/chess/rules.c file | annotate | diff | comparison | revisions
src/chess/rules.h file | annotate | diff | comparison | revisions
src/game.c file | annotate | diff | comparison | revisions
src/main.c file | annotate | diff | comparison | revisions
src/network.c file | annotate | diff | comparison | revisions
--- a/src/chess/game-info.c	Sun Nov 30 22:42:46 2025 +0100
+++ b/src/chess/game-info.c	Fri Mar 27 18:11:42 2026 +0100
@@ -48,8 +48,7 @@
 }
 
 void gamestate_cleanup(GameState *gamestate) {
-    MoveList *elem;
-    elem = gamestate->movelist;
+    MoveList *elem = gamestate->movelist;
     while (elem) {
         MoveList *cur = elem;
         elem = elem->next;
--- a/src/chess/rules.c	Sun Nov 30 22:42:46 2025 +0100
+++ b/src/chess/rules.c	Fri Mar 27 18:11:42 2026 +0100
@@ -184,7 +184,7 @@
     }
 }
 
-unsigned char* getpieceunicode(uint8_t piece) {
+char* getpieceunicode(uint8_t piece) {
     switch (piece & PIECE_MASK) {
     case PAWN: return "\u265f";
     case ROOK: return "\u265c";
@@ -537,11 +537,11 @@
         
         bool result = false;
         uint8_t kingfile = 0, kingrow = 0;
-        for (uint8_t row = 0 ; row < 8 ; row++) {
-            for (uint8_t file = 0 ; file < 8 ; file++) {
-                if (gamestate->board[row][file] == (color|KING)) {
-                    kingfile = file;
-                    kingrow = row;
+        for (uint8_t r = 0 ; r < 8 ; r++) {
+            for (uint8_t f = 0 ; f < 8 ; f++) {
+                if (gamestate->board[r][f] == (color|KING)) {
+                    kingfile = f;
+                    kingrow = r;
                 }
             }
         }
--- a/src/chess/rules.h	Sun Nov 30 22:42:46 2025 +0100
+++ b/src/chess/rules.h	Fri Mar 27 18:11:42 2026 +0100
@@ -99,7 +99,7 @@
  * @param piece the piece to dispaly
  * @return unicode character sequence for the specified piece
  */
-unsigned char* getpieceunicode(uint8_t piece);
+char* getpieceunicode(uint8_t piece);
 
 /**
  * Checks, if a specified field is covered by a piece of a certain color.
--- a/src/game.c	Sun Nov 30 22:42:46 2025 +0100
+++ b/src/game.c	Fri Mar 27 18:11:42 2026 +0100
@@ -84,10 +84,10 @@
         for (uint8_t x = 0 ; x < 8 ; x++) {
             uint8_t col = gamestate->board[y][x] & COLOR_MASK;
             uint8_t piece = gamestate->board[y][x] & PIECE_MASK;
-            unsigned char piecestr[5];
+            char piecestr[5];
             if (piece) {
                 if (unicode) {
-                    unsigned char* uc = getpieceunicode(piece);
+                    char* uc = getpieceunicode(piece);
                     strncpy(piecestr, uc, 5);
                 } else {
                     piecestr[0] = piece == PAWN ? 'P' : getpiecechr(piece);
@@ -395,9 +395,9 @@
         FD_ZERO(&readfds);
         FD_SET(opponent, &readfds);
         timeout.tv_sec = 0;
-        timeout.tv_usec = 1e5;
+        timeout.tv_usec = 100000;
         
-        // TODO: allow commands
+        // TODO: allow commands while waiting (e.g. resign, offer draw)
         
         int result = select(opponent+1, &readfds, NULL, NULL, &timeout);
         if (result == -1) {
--- a/src/main.c	Sun Nov 30 22:42:46 2025 +0100
+++ b/src/main.c	Fri Mar 27 18:11:42 2026 +0100
@@ -112,8 +112,6 @@
 "  -h            This help page\n"
 "  -p            TCP port to use (default: 27015)\n"
 "  -U            Disables unicode pieces\n"
-// TODO: implement and activate feature
-//"  -S <PGN file> Compute and print statistics for the specified game\n"
 "  -v            Print version information and exits\n"
 "\nServer options\n"
 "  -a <time>     Specifies the time to add after each move\n"
@@ -154,8 +152,7 @@
 }
 
 static Settings default_settings() {
-    Settings settings;
-    memset(&settings, 0, sizeof(Settings));
+    Settings settings = {0};
     settings.gameinfo.servercolor = WHITE;
     settings.port = "27015";
     settings.unicode = !!setlocale(LC_CTYPE, "C.UTF-8");
--- a/src/network.c	Sun Nov 30 22:42:46 2025 +0100
+++ b/src/network.c	Fri Mar 27 18:11:42 2026 +0100
@@ -57,8 +57,7 @@
 }
 
 static int getaddrinfo_intrnl(char *host, char *port, struct addrinfo **info) {
-    struct addrinfo hints;
-    memset(&hints, 0, sizeof(hints));
+    struct addrinfo hints = {0};
     hints.ai_socktype = SOCK_STREAM;
     hints.ai_protocol = IPPROTO_TCP;
     

mercurial