gomoku: fix off-by-one error when deciding that the game is a tie

This commit is contained in:
rillig 2022-05-27 20:35:58 +00:00
parent 42e4930deb
commit 9aebef9fb0
1 changed files with 31 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: makemove.c,v 1.21 2022/05/27 19:59:56 rillig Exp $ */ /* $NetBSD: makemove.c,v 1.22 2022/05/27 20:35:58 rillig Exp $ */
/* /*
* Copyright (c) 1994 * Copyright (c) 1994
@ -34,7 +34,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
/* @(#)makemove.c 8.2 (Berkeley) 5/3/95 */ /* @(#)makemove.c 8.2 (Berkeley) 5/3/95 */
__RCSID("$NetBSD: makemove.c,v 1.21 2022/05/27 19:59:56 rillig Exp $"); __RCSID("$NetBSD: makemove.c,v 1.22 2022/05/27 20:35:58 rillig Exp $");
#include "gomoku.h" #include "gomoku.h"
@ -79,7 +79,35 @@ makemove(int us, int mv)
/* make move */ /* make move */
sp->s_occ = us; sp->s_occ = us;
movelog[nmoves++] = mv; movelog[nmoves++] = mv;
if (nmoves + 1 == BSZ * BSZ) /* FIXME: off-by-one */
/*
* FIXME: The last spot on the board can still complete a frame.
*
* Example game: A1 B1 C1 D1 E1 F1 G1 H1 J1 K1 L1 M1 N1 O1 P1 Q1 R1
* S1 T1 A2 B2 C2 D2 E2 F2 G2 H2 J2 K2 L2 M2 N2 O2 P2 Q2 R2 S2 T2 A3
* B3 C3 D3 E3 F3 G3 H3 J3 K3 L3 M3 N3 O3 P3 Q3 R3 S3 T3 A4 B4 C4 D4
* E4 F4 G4 H4 J4 K4 L4 M4 N4 O4 P4 Q4 R4 S4 T4 B5 C5 D5 E5 F5 G5 H5
* J5 K5 L5 M5 N5 O5 P5 Q5 R5 S5 T5 B6 C6 D6 E6 F6 G6 H6 J6 K6 L6 M6
* N6 O6 P6 Q6 R6 S6 T6 B7 C7 D7 E7 F7 G7 H7 J7 K7 L7 M7 N7 O7 P7 Q7
* R7 S7 T7 A8 B8 C8 D8 E8 F8 G8 H8 J8 K8 L8 M8 N8 O8 P8 Q8 R8 S8 T8
* A9 B9 C9 D9 E9 F9 G9 H9 J9 K9 L9 M9 N9 O9 P9 Q9 R9 S9 T9 A10 B10
* C10 D10 E10 F10 G10 H10 J10 K10 L10 M10 N10 O10 P10 Q10 R10 S10
* T10 B11 C11 D11 E11 F11 G11 H11 J11 K11 L11 M11 N11 O11 P11 Q11
* R11 S11 T11 B12 C12 D12 E12 F12 G12 H12 J12 K12 L12 M12 N12 O12
* P12 Q12 R12 S12 T12 B13 C13 D13 E13 F13 G13 H13 J13 K13 L13 M13
* N13 O13 P13 Q13 R13 S13 T13 A14 B14 C14 D14 E14 F14 G14 H14 J14
* K14 L14 M14 N14 O14 P14 Q14 R14 S14 T14 A15 B15 C15 D15 E15 F15
* G15 H15 J15 K15 L15 M15 N15 O15 P15 Q15 R15 S15 T15 A16 B16 C16
* D16 E16 F16 G16 H16 J16 K16 L16 M16 N16 O16 P16 Q16 R16 S16 T16
* B17 C17 D17 E17 F17 G17 H17 J17 K17 L17 M17 N17 O17 P17 Q17 R17
* S17 T17 B18 C18 D18 E18 F18 G18 H18 J18 K18 L18 M18 N18 O18 P18
* Q18 R18 S18 T18 A11 A5 A12 A6 A13 A7 A18 A17 A19 B19 C19 D19 E19
* F19 G19 H19 J19 K19 L19 T19 M19 S19 N19 R19 O19 Q19
*
* Now P19 is the last remaining spot, and when Black plays there,
* the frame L19-P19 is complete.
*/
if (nmoves == BSZ * BSZ)
return TIE; return TIE;
/* compute new frame values */ /* compute new frame values */