add score
authorLaurent Mazet <mazet@softndesign.org>
Thu, 19 Sep 2024 21:35:51 +0000 (23:35 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Thu, 19 Sep 2024 21:35:51 +0000 (23:35 +0200)
function.c
function.h
reversi.c

index d4a7b74814c18fae348096857fc85fba58ad1366..7968f3397a52c6b977c6cef23fd8a23299e5aaf2 100644 (file)
@@ -320,4 +320,18 @@ int find (board_t *board, int id)
     return ret;
 }
 
+int count (board_t *board, int id)
+{
+    int nb = 0;
+    int x, y;
+    for (x = 0; x < board->width; x++) {
+        for (y = 0; y < board->height; y++) {
+            if (*getcell (board, x, y) == '0' + id) {
+                nb++;
+            }
+        }
+    }
+    return nb;
+}
+
 /* vim: set ts=4 sw=4 et: */
index af8eed9b68e7fba41dc1baa1e3c8f0d5b00c2777..b74a7ffe50e902e4b6eb0af84e7c44a209f3352e 100644 (file)
@@ -45,6 +45,8 @@ int putdisk (board_t *board, int x, int y, int id);
 
 int find (board_t *board, int id);
 
+int count (board_t *board, int id);
+
 #endif /* __FUNCTION_H__ */
 
 /* vim: set ts=4 sw=4 et: */
index a6222b8122067df2678b00136171f1b6d4929c60..7e486cce4b00dd07932ac030de0cd4e5a9b3e6dd 100644 (file)
--- a/reversi.c
+++ b/reversi.c
@@ -7,6 +7,7 @@
 #include <curses.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "constant.h"
 #include "debug.h"
@@ -199,6 +200,7 @@ int main (int argc, char *argv[])
         }
 
         /* message */
+        sprintf (msg + strlen (msg), " [%02d|%02d]", count (board, 0), count (board, 1));
         msgwindow (msg, xmsg, ymsg, lmsg);
 
         /* get key press */