Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/gomoku gomoku: extract set_input_sources from main
details: https://anonhg.NetBSD.org/src/rev/00d64ec73924
branches: trunk
changeset: 366297:00d64ec73924
user: rillig <rillig%NetBSD.org@localhost>
date: Sun May 22 08:22:43 2022 +0000
description:
gomoku: extract set_input_sources from main
No functional change.
diffstat:
games/gomoku/main.c | 61 +++++++++++++++++++++-------------------------------
1 files changed, 25 insertions(+), 36 deletions(-)
diffs (96 lines):
diff -r c58cc34f9ef8 -r 00d64ec73924 games/gomoku/main.c
--- a/games/gomoku/main.c Sun May 22 08:18:49 2022 +0000
+++ b/games/gomoku/main.c Sun May 22 08:22:43 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.51 2022/05/22 08:18:49 rillig Exp $ */
+/* $NetBSD: main.c,v 1.52 2022/05/22 08:22:43 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.51 2022/05/22 08:18:49 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.52 2022/05/22 08:22:43 rillig Exp $");
#include <sys/stat.h>
#include <curses.h>
@@ -155,6 +155,27 @@
err(1, "%s", *argv);
}
+static void
+set_input_sources(enum input_source *input, int color)
+{
+ switch (test) {
+ case 0: /* user versus program */
+ input[color] = USER;
+ input[color != BLACK ? BLACK : WHITE] = PROGRAM;
+ break;
+
+ case 1: /* user versus user */
+ input[BLACK] = USER;
+ input[WHITE] = USER;
+ break;
+
+ case 2: /* program versus program */
+ input[BLACK] = PROGRAM;
+ input[WHITE] = PROGRAM;
+ break;
+ }
+}
+
int
main(int argc, char **argv)
{
@@ -230,22 +251,7 @@
input[BLACK] = INPUTF;
input[WHITE] = INPUTF;
} else {
- switch (test) {
- case 0: /* user versus program */
- input[color] = USER;
- input[color != BLACK ? BLACK : WHITE] = PROGRAM;
- break;
-
- case 1: /* user versus user */
- input[BLACK] = USER;
- input[WHITE] = USER;
- break;
-
- case 2: /* program versus program */
- input[BLACK] = PROGRAM;
- input[WHITE] = PROGRAM;
- break;
- }
+ set_input_sources(input, color);
}
if (interactive) {
plyr[BLACK] = input[BLACK] == USER ? user : prog;
@@ -262,24 +268,7 @@
curmove = readinput(inputfp);
if (curmove != EOF)
break;
- /* Switch to another input source. */
- switch (test) {
- case 0: /* user versus program */
- input[color] = USER;
- input[color != BLACK ? BLACK : WHITE] =
- PROGRAM;
- break;
-
- case 1: /* user versus user */
- input[BLACK] = USER;
- input[WHITE] = USER;
- break;
-
- case 2: /* program versus program */
- input[BLACK] = PROGRAM;
- input[WHITE] = PROGRAM;
- break;
- }
+ set_input_sources(input, color);
plyr[BLACK] = input[BLACK] == USER ? user : prog;
plyr[WHITE] = input[WHITE] == USER ? user : prog;
bdwho();
Home |
Main Index |
Thread Index |
Old Index