From 433f7a31ac5ec2e16b5d6085db93c52d9046026a Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Thu, 19 Sep 2024 23:35:51 +0200 Subject: [PATCH] add score --- function.c | 14 ++++++++++++++ function.h | 2 ++ reversi.c | 2 ++ 3 files changed, 18 insertions(+) diff --git a/function.c b/function.c index d4a7b74..7968f33 100644 --- a/function.c +++ b/function.c @@ -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: */ diff --git a/function.h b/function.h index af8eed9..b74a7ff 100644 --- a/function.h +++ b/function.h @@ -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: */ diff --git a/reversi.c b/reversi.c index a6222b8..7e486cc 100644 --- a/reversi.c +++ b/reversi.c @@ -7,6 +7,7 @@ #include #include #include +#include #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 */ -- 2.30.2