From: Laurent MAZET Date: Mon, 23 Sep 2024 17:13:58 +0000 (+0200) Subject: add ai (first) X-Git-Tag: v1.1~2 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=667980ac51928e55507bcd20f643e322b1c3c7e5;p=reversi.git add ai (first) --- diff --git a/ai.c b/ai.c index 58da3bf..08fab73 100644 --- 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); diff --git a/function.h b/function.h index b74a7ff..7e9629f 100644 --- a/function.h +++ b/function.h @@ -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: */ diff --git a/reversi.c b/reversi.c index 6ccb640..6a12da7 100644 --- 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 #include @@ -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 index 0000000..ba0084e --- /dev/null +++ b/time.c @@ -0,0 +1,10 @@ +#include + +#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 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: */