Module Name: src Committed By: rillig Date: Sat May 28 07:58:36 UTC 2022
Modified Files: src/games/gomoku: makemove.c Log Message: gomoku: announce tie as early as possible To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/games/gomoku/makemove.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/games/gomoku/makemove.c diff -u src/games/gomoku/makemove.c:1.29 src/games/gomoku/makemove.c:1.30 --- src/games/gomoku/makemove.c:1.29 Sat May 28 06:25:35 2022 +++ src/games/gomoku/makemove.c Sat May 28 07:58:35 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: makemove.c,v 1.29 2022/05/28 06:25:35 rillig Exp $ */ +/* $NetBSD: makemove.c,v 1.30 2022/05/28 07:58:35 rillig Exp $ */ /* * Copyright (c) 1994 @@ -34,7 +34,7 @@ #include <sys/cdefs.h> /* @(#)makemove.c 8.2 (Berkeley) 5/3/95 */ -__RCSID("$NetBSD: makemove.c,v 1.29 2022/05/28 06:25:35 rillig Exp $"); +__RCSID("$NetBSD: makemove.c,v 1.30 2022/05/28 07:58:35 rillig Exp $"); #include "gomoku.h" @@ -50,6 +50,17 @@ static const int weight[5] = { 0, 1, 7, static void update_overlap(struct spotstr *); +static bool +is_tie(void) +{ + + for (int y = 1; y <= BSZ; y++) + for (int x = 1; x <= BSZ; x++) + if (board[PT(x, y)].s_wval != 0) + return false; + return true; +} + /* * Return values: * MOVEOK everything is OK. @@ -199,11 +210,7 @@ makemove(int us, int mv) update_overlap(&board[mv]); - /* - * TODO: Declare a tie as soon as all frames are blocked. This is - * usually much earlier than when the whole board is filled. - */ - if (nmoves == BSZ * BSZ) + if (is_tie()) return TIE; return MOVEOK;