add ai (first)
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 23 Sep 2024 17:13:58 +0000 (19:13 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 23 Sep 2024 17:13:58 +0000 (19:13 +0200)
ai.c
function.h
reversi.c
time.c [new file with mode: 0644]
time.h [new file with mode: 0644]

diff --git a/ai.c b/ai.c
index 58da3bf27e8dd8b3c877b180787619d70bc5150b..08fab73c7ecc678dfd1241f062c0f27d6db88fc3 100644 (file)
--- a/ai.c
+++ b/ai.c
@@ -21,7 +21,7 @@ int play (board_t *board, int id)
                 if (ns > s) {
                     x = i;
                     y = j;
-                    ns = s;
+                    s = ns;
                 }
             }
             freeboard (newboard);
index b74a7ffe50e902e4b6eb0af84e7c44a209f3352e..7e9629f0cca84df366a8ab336d55b0491da362ed 100644 (file)
@@ -47,6 +47,8 @@ int find (board_t *board, int id);
 
 int count (board_t *board, int id);
 
+void msleep (int msec);
+
 #endif /* __FUNCTION_H__ */
 
 /* vim: set ts=4 sw=4 et: */
index 6ccb6401262d0fa8413c0e20a442eb21abee05d9..6a12da79fb2049654ebdd83f09d7a8bf1ec78463 100644 (file)
--- a/reversi.c
+++ b/reversi.c
@@ -1,8 +1,8 @@
 /* depend: */
 /* cflags: */
-/* linker: ai.o block.o color.c constant.o debug.o display.o function.o -lcurses */
-/* doslnk: ai.o block.o color.c constant.o debug.o display.o function.o -lpdc~1 */
-/* winlnk: ai.o block.o color.c constant.o debug.o display.o function.o -lpdcurses */
+/* linker: ai.o block.o color.c constant.o debug.o display.o function.o time.o -lcurses */
+/* doslnk: ai.o block.o color.c constant.o debug.o display.o function.o time.o -lpdc~1 */
+/* winlnk: ai.o block.o color.c constant.o debug.o display.o function.o time.o -lpdcurses */
 
 #include <curses.h>
 #include <stdio.h>
@@ -232,16 +232,21 @@ int main (int argc, char *argv[])
                     } else {
                         break;
                     }
-                } else {
+                } else { // id == ai
                     if (!play (board, id)) {
                         sprintf (msg, "Skip %s", id ? "Two" : "One");
                         id = id ? 0 : 1;
                         test++;
                     } else {
+                        boardwindow (board, 0);
+                        msleep (500);
+                        freeboard (boardturn);
+                        boardturn = copyboard (board);
+                        id = id ? 0 : 1;
                         test = 0;
                     }
                 }
-            } while (test == 2);
+            } while (test != 2);
             if (test == 2) {
                 sprintf (msg, "End of game");
                 mode = 1;
diff --git a/time.c b/time.c
new file mode 100644 (file)
index 0000000..ba0084e
--- /dev/null
+++ b/time.c
@@ -0,0 +1,10 @@
+#include <unistd.h>
+
+#include "time.h"
+
+void msleep (int msec)
+{
+    usleep (msec * 1000);
+}
+
+/* vim: set ts=4 sw=4 et: */
diff --git a/time.h b/time.h
new file mode 100644 (file)
index 0000000..bc21d7f
--- /dev/null
+++ b/time.h
@@ -0,0 +1,8 @@
+#ifndef __TIME_H__
+#define __TIME_H__
+
+void msleep (int msec);
+
+#endif /* __TIME_H__ */
+
+/* vim: set ts=4 sw=4 et: */