Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/gomoku gomoku: announce tie as early as possible
details: https://anonhg.NetBSD.org/src/rev/aa9296432b20
branches: trunk
changeset: 366462:aa9296432b20
user: rillig <rillig%NetBSD.org@localhost>
date: Sat May 28 07:58:35 2022 +0000
description:
gomoku: announce tie as early as possible
diffstat:
games/gomoku/makemove.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diffs (49 lines):
diff -r 0ff6727f6b2b -r aa9296432b20 games/gomoku/makemove.c
--- a/games/gomoku/makemove.c Sat May 28 06:25:35 2022 +0000
+++ b/games/gomoku/makemove.c Sat May 28 07:58:35 2022 +0000
@@ -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 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 @@
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;
Home |
Main Index |
Thread Index |
Old Index