Module Name: src
Committed By: rillig
Date: Sun May 22 08:36:15 UTC 2022
Modified Files:
src/games/gomoku: main.c
Log Message:
gomoku: extract declare_winner from main
To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/games/gomoku/main.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/main.c
diff -u src/games/gomoku/main.c:1.54 src/games/gomoku/main.c:1.55
--- src/games/gomoku/main.c:1.54 Sun May 22 08:31:12 2022
+++ src/games/gomoku/main.c Sun May 22 08:36:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.54 2022/05/22 08:31:12 rillig Exp $ */
+/* $NetBSD: main.c,v 1.55 2022/05/22 08:36:15 rillig Exp $ */
/*
* Copyright (c) 1994
@@ -36,7 +36,7 @@
__COPYRIGHT("@(#) Copyright (c) 1994\
The Regents of the University of California. All rights reserved.");
/* @(#)main.c 8.4 (Berkeley) 5/4/95 */
-__RCSID("$NetBSD: main.c,v 1.54 2022/05/22 08:31:12 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.55 2022/05/22 08:36:15 rillig Exp $");
#include <sys/stat.h>
#include <curses.h>
@@ -230,6 +230,31 @@ again:
}
}
+static void
+declare_winner(int outcome, const enum input_source *input, int color)
+{
+
+ move(BSZ + 3, 0);
+ switch (outcome) {
+ case WIN:
+ if (input[color] == PROGRAM)
+ addstr("Ha ha, I won");
+ else if (input[0] == USER && input[1] == USER)
+ addstr("Well, you won (and lost)");
+ else
+ addstr("Rats! you won");
+ break;
+ case TIE:
+ addstr("Wow! It's a tie");
+ break;
+ case ILLEGAL:
+ addstr("Illegal move");
+ break;
+ }
+ clrtoeol();
+ bdisp();
+}
+
int
main(int argc, char **argv)
{
@@ -330,25 +355,7 @@ again:
bdisp();
}
if (interactive) {
- move(BSZ + 3, 0);
- switch (outcome) {
- case WIN:
- if (input[color] == PROGRAM)
- addstr("Ha ha, I won");
- else if (input[0] == USER && input[1] == USER)
- addstr("Well, you won (and lost)");
- else
- addstr("Rats! you won");
- break;
- case TIE:
- addstr("Wow! It's a tie");
- break;
- case ILLEGAL:
- addstr("Illegal move");
- break;
- }
- clrtoeol();
- bdisp();
+ declare_winner(outcome, input, color);
if (outcome != RESIGN) {
replay:
ask("Play again? ");