src/game.c

changeset 37
bcf624518909
parent 35
6c64b7a073af
child 42
21cb830efe91
--- a/src/game.c	Thu Apr 10 11:44:55 2014 +0200
+++ b/src/game.c	Thu Apr 10 12:10:09 2014 +0200
@@ -172,11 +172,12 @@
     }
 }
 
+#define MOVESTR_BUFLEN 8
 static int domove_singlemachine(GameState *gamestate, GameInfo *gameinfo) {
     
-    const size_t buflen = 8;
+
     size_t bufpos = 0;
-    char movestr[buflen];
+    char movestr[MOVESTR_BUFLEN];
     
     flushinp();
     while (1) {
@@ -191,14 +192,14 @@
             "Type your move: ");
         clrtoeol();
         
-        if (asyncgetnstr(movestr, &bufpos, buflen)) {
-            if (strncmp(movestr, "surr", buflen) == 0) {
+        if (asyncgetnstr(movestr, &bufpos, MOVESTR_BUFLEN)) {
+            if (strncmp(movestr, "surr", MOVESTR_BUFLEN) == 0) {
                 printw("%s surrendered!",
                     gamestate->mycolor==WHITE?"White":"Black");
                 clrtoeol();
                 refresh();
                 return 1;
-            } else if (strncmp(movestr, "remis", buflen) == 0) {
+            } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) {
                 printw("Game ends remis.");
                 clrtoeol();
                 refresh();
@@ -236,9 +237,8 @@
 
 static int sendmove(GameState *gamestate, GameInfo *gameinfo, int opponent) {
     
-    const size_t buflen = 8;
     size_t bufpos = 0;
-    char movestr[buflen];
+    char movestr[MOVESTR_BUFLEN];
     _Bool remisrejected = FALSE;
     uint8_t code;
     
@@ -263,14 +263,14 @@
         }
         clrtoeol();
         
-        if (asyncgetnstr(movestr, &bufpos, buflen)) {
-            if (strncmp(movestr, "surr", buflen) == 0) {
+        if (asyncgetnstr(movestr, &bufpos, MOVESTR_BUFLEN)) {
+            if (strncmp(movestr, "surr", MOVESTR_BUFLEN) == 0) {
                 printw("You surrendered!");
                 clrtoeol();
                 refresh();
                 net_send_code(opponent, NETCODE_SURRENDER);
                 return 1;
-            } else if (strncmp(movestr, "remis", buflen) == 0) {
+            } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) {
                 if (!remisrejected) {
                     net_send_code(opponent, NETCODE_REMIS);
                     printw("Remis offer sent - waiting for acceptance...");

mercurial