CVS commit: src/games/robots
Module Name:src Committed By: mrg Date: Tue Apr 13 01:50:46 UTC 2021 Modified Files: src/games/robots: score.c Log Message: properly terminate after using strncpy(). To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/games/robots/score.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/robots/score.c diff -u src/games/robots/score.c:1.23 src/games/robots/score.c:1.24 --- src/games/robots/score.c:1.23 Wed Aug 12 08:30:55 2009 +++ src/games/robots/score.c Tue Apr 13 01:50:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: score.c,v 1.23 2009/08/12 08:30:55 dholland Exp $ */ +/* $NetBSD: score.c,v 1.24 2021/04/13 01:50:46 mrg Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: score.c,v 1.23 2009/08/12 08:30:55 dholland Exp $"); +__RCSID("$NetBSD: score.c,v 1.24 2021/04/13 01:50:46 mrg Exp $"); #endif #endif /* not lint */ @@ -198,9 +198,10 @@ set_name(SCORE *scp) struct passwd *pp; if ((pp = getpwuid(scp->s_uid)) == NULL) - strncpy(scp->s_name, "???", MAXNAME); + strncpy(scp->s_name, "???", MAXNAME - 1); else - strncpy(scp->s_name, pp->pw_name, MAXNAME); + strncpy(scp->s_name, pp->pw_name, MAXNAME - 1); + scp->s_name[MAXNAME - 1] = '\0'; } /*
CVS commit: src/games/robots
Module Name:src Committed By: nia Date: Sun Jul 26 15:38:22 UTC 2020 Modified Files: src/games/robots: main.c rnd_pos.c Log Message: robots: Use arc4random_uniform for better uniform distribution To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/games/robots/main.c cvs rdiff -u -r1.10 -r1.11 src/games/robots/rnd_pos.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/robots/main.c diff -u src/games/robots/main.c:1.32 src/games/robots/main.c:1.33 --- src/games/robots/main.c:1.32 Wed Aug 12 08:30:55 2009 +++ src/games/robots/main.c Sun Jul 26 15:38:22 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.32 2009/08/12 08:30:55 dholland Exp $ */ +/* $NetBSD: main.c,v 1.33 2020/07/26 15:38:22 nia Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.32 2009/08/12 08:30:55 dholland Exp $"); +__RCSID("$NetBSD: main.c,v 1.33 2020/07/26 15:38:22 nia Exp $"); #endif #endif /* not lint */ @@ -167,7 +167,6 @@ main(int argc, char **argv) stdscr = newwin(Y_SIZE, X_SIZE, 0, 0); } - srandom(time(NULL)); if (Real_time) signal(SIGALRM, move_robots); do { Index: src/games/robots/rnd_pos.c diff -u src/games/robots/rnd_pos.c:1.10 src/games/robots/rnd_pos.c:1.11 --- src/games/robots/rnd_pos.c:1.10 Wed Aug 12 08:30:55 2009 +++ src/games/robots/rnd_pos.c Sun Jul 26 15:38:22 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: rnd_pos.c,v 1.10 2009/08/12 08:30:55 dholland Exp $ */ +/* $NetBSD: rnd_pos.c,v 1.11 2020/07/26 15:38:22 nia Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: rnd_pos.c,v 1.10 2009/08/12 08:30:55 dholland Exp $"); +__RCSID("$NetBSD: rnd_pos.c,v 1.11 2020/07/26 15:38:22 nia Exp $"); #endif #endif /* not lint */ @@ -44,8 +44,6 @@ __RCSID("$NetBSD: rnd_pos.c,v 1.10 2009/ #define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x) -static int rnd(int); - /* * rnd_pos: * Pick a random, unoccupied position @@ -57,17 +55,10 @@ rnd_pos(void) static int call = 0; do { - pos.y = rnd(Y_FIELDSIZE - 1) + 1; - pos.x = rnd(X_FIELDSIZE - 1) + 1; + pos.y = arc4random_uniform(Y_FIELDSIZE - 1) + 1; + pos.x = arc4random_uniform(X_FIELDSIZE - 1) + 1; refresh(); } while (Field[pos.y][pos.x] != 0); call++; return &pos; } - -static int -rnd(int range) -{ - - return random() % range; -}
CVS commit: src/games/robots
Module Name:src Committed By: dholland Date: Wed Aug 12 08:30:55 UTC 2009 Modified Files: src/games/robots: main.c move.c rnd_pos.c robots.h score.c Log Message: sprinkle static To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/games/robots/main.c cvs rdiff -u -r1.15 -r1.16 src/games/robots/move.c cvs rdiff -u -r1.9 -r1.10 src/games/robots/rnd_pos.c cvs rdiff -u -r1.21 -r1.22 src/games/robots/robots.h cvs rdiff -u -r1.22 -r1.23 src/games/robots/score.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/robots/main.c diff -u src/games/robots/main.c:1.31 src/games/robots/main.c:1.32 --- src/games/robots/main.c:1.31 Wed Aug 5 19:34:09 2009 +++ src/games/robots/main.c Wed Aug 12 08:30:55 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.31 2009/08/05 19:34:09 christos Exp $ */ +/* $NetBSD: main.c,v 1.32 2009/08/12 08:30:55 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.31 2009/08/05 19:34:09 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.32 2009/08/12 08:30:55 dholland Exp $"); #endif #endif /* not lint */ @@ -57,6 +57,8 @@ extern const char *Scorefile; extern int Max_per_uid; +static bool another(void); + int main(int argc, char **argv) { @@ -210,7 +212,7 @@ * another: * See if another game is desired */ -bool +static bool another(void) { int y; Index: src/games/robots/move.c diff -u src/games/robots/move.c:1.15 src/games/robots/move.c:1.16 --- src/games/robots/move.c:1.15 Mon Jul 20 06:39:06 2009 +++ src/games/robots/move.c Wed Aug 12 08:30:55 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: move.c,v 1.15 2009/07/20 06:39:06 dholland Exp $ */ +/* $NetBSD: move.c,v 1.16 2009/08/12 08:30:55 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: move.c,v 1.15 2009/07/20 06:39:06 dholland Exp $"); +__RCSID("$NetBSD: move.c,v 1.16 2009/08/12 08:30:55 dholland Exp $"); #endif #endif /* not lint */ @@ -47,6 +47,10 @@ #define ESC '\033' +static bool do_move(int, int); +static bool eaten(const COORD *); +static bool must_telep(void); + /* * get_move: * Get and execute a move from the player @@ -212,7 +216,7 @@ * Must I teleport; i.e., is there anywhere I can move without * being eaten? */ -bool +static bool must_telep(void) { int x, y; @@ -244,7 +248,7 @@ * do_move: * Execute a move */ -bool +static bool do_move(int dy, int dx) { static COORD newpos; @@ -280,7 +284,7 @@ * eaten: * Player would get eaten at this place */ -bool +static bool eaten(const COORD *pos) { int x, y; Index: src/games/robots/rnd_pos.c diff -u src/games/robots/rnd_pos.c:1.9 src/games/robots/rnd_pos.c:1.10 --- src/games/robots/rnd_pos.c:1.9 Mon Jul 20 06:43:18 2009 +++ src/games/robots/rnd_pos.c Wed Aug 12 08:30:55 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rnd_pos.c,v 1.9 2009/07/20 06:43:18 dholland Exp $ */ +/* $NetBSD: rnd_pos.c,v 1.10 2009/08/12 08:30:55 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: rnd_pos.c,v 1.9 2009/07/20 06:43:18 dholland Exp $"); +__RCSID("$NetBSD: rnd_pos.c,v 1.10 2009/08/12 08:30:55 dholland Exp $"); #endif #endif /* not lint */ @@ -44,6 +44,8 @@ #define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x) +static int rnd(int); + /* * rnd_pos: * Pick a random, unoccupied position @@ -63,7 +65,7 @@ return &pos; } -int +static int rnd(int range) { Index: src/games/robots/robots.h diff -u src/games/robots/robots.h:1.21 src/games/robots/robots.h:1.22 --- src/games/robots/robots.h:1.21 Mon Jul 20 06:39:06 2009 +++ src/games/robots/robots.h Wed Aug 12 08:30:55 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: robots.h,v 1.21 2009/07/20 06:39:06 dholland Exp $ */ +/* $NetBSD: robots.h,v 1.22 2009/08/12 08:30:55 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -110,26 +110,19 @@ */ void add_score(int); -bool another(void); char automove(void); -int cmp_sc(const void *, const void *); -bool do_move(int, int); -bool eaten(const COORD *); void flush_in(void); void get_move(void); void init_field(void); bool jumping(void); void make_level(void); void move_robots(int); -bool must_telep(void); void play_level(void); int query(const char *); void quit(int) __dead; void reset_count(void); -int rnd(int); COORD *rnd_pos(void); void score(int); -void set_name(SCORE *); void show_score(void); int sign(int); void telmsg(int); Index: src/games/robots/score.c diff -u src/games/robots/score.c:1.22 src/games/robots/score.c:1.23 --- src/games/robots/score.c:1.22 Mon Aug 3 06:04:12 2009 +++ src/games/robots/score.c Wed Aug 12 08:30:55 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sco
CVS commit: src/games/robots
Module Name:src Committed By: christos Date: Wed Aug 5 19:34:09 UTC 2009 Modified Files: src/games/robots: main.c Log Message: don't use char values for functions that can return -1; chars are not always signed. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/games/robots/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/robots/main.c diff -u src/games/robots/main.c:1.30 src/games/robots/main.c:1.31 --- src/games/robots/main.c:1.30 Wed Aug 5 00:03:47 2009 +++ src/games/robots/main.c Wed Aug 5 15:34:09 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.30 2009/08/05 04:03:47 dholland Exp $ */ +/* $NetBSD: main.c,v 1.31 2009/08/05 19:34:09 christos Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.30 2009/08/05 04:03:47 dholland Exp $"); +__RCSID("$NetBSD: main.c,v 1.31 2009/08/05 19:34:09 christos Exp $"); #endif #endif /* not lint */ @@ -65,8 +65,7 @@ int score_wfd; /* high score writable file descriptor */ int score_err = 0; /* hold errno from score file open */ int maximum = 0; - char ch; - int i; + int ch, i; score_wfd = open(Scorefile, O_RDWR); if (score_wfd < 0)
CVS commit: src/games/robots
Module Name:src Committed By: dholland Date: Wed Aug 5 04:03:47 UTC 2009 Modified Files: src/games/robots: main.c robots.6 Log Message: Use getopt instead of hand-rolled options code. Document all the arguments and options. Don't allow the previously undocumented method to change the maximum number of scores kept per user to be used on the system-wide high score file. Sort options list in the man page. Bump its date. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/games/robots/main.c cvs rdiff -u -r1.14 -r1.15 src/games/robots/robots.6 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/robots/main.c diff -u src/games/robots/main.c:1.29 src/games/robots/main.c:1.30 --- src/games/robots/main.c:1.29 Mon Jul 20 06:43:18 2009 +++ src/games/robots/main.c Wed Aug 5 04:03:47 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.29 2009/07/20 06:43:18 dholland Exp $ */ +/* $NetBSD: main.c,v 1.30 2009/08/05 04:03:47 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.29 2009/07/20 06:43:18 dholland Exp $"); +__RCSID("$NetBSD: main.c,v 1.30 2009/08/05 04:03:47 dholland Exp $"); #endif #endif /* not lint */ @@ -58,13 +58,15 @@ extern int Max_per_uid; int -main(int ac, char **av) +main(int argc, char **argv) { - const char *sp; - bool bad_arg; + const char *word; bool show_only; int score_wfd; /* high score writable file descriptor */ int score_err = 0; /* hold errno from score file open */ + int maximum = 0; + char ch; + int i; score_wfd = open(Scorefile, O_RDWR); if (score_wfd < 0) @@ -77,64 +79,60 @@ show_only = false; Num_games = 1; - if (ac > 1) { - bad_arg = false; - for (++av; ac > 1 && *av[0]; av++, ac--) - if (av[0][0] != '-') -if (isdigit((unsigned char)av[0][0])) - Max_per_uid = atoi(av[0]); -else { - Scorefile = av[0]; - if (score_wfd >= 0) - close(score_wfd); - score_wfd = open(Scorefile, O_RDWR); - if (score_wfd < 0) - score_err = errno; + + while ((ch = getopt(argc, argv, "Aajnrst")) != -1) { + switch (ch) { + case 'A': + Auto_bot = true; + break; + case 'a': + Start_level = 4; + break; + case 'j': + Jump = true; + break; + case 'n': + Num_games++; + break; + case 'r': + Real_time = true; + break; + case 's': + show_only = true; + break; + case 't': + Teleport = true; + break; + default: + errx(1, + "Usage: robots [-Aajnrst] [maximum] [scorefile]"); + break; + } + } + + for (i = optind; i < argc; i++) { + word = argv[i]; + if (isdigit((unsigned char)word[0])) { + maximum = atoi(word); + } else { + Scorefile = word; + Max_per_uid = maximum; + if (score_wfd >= 0) +close(score_wfd); + score_wfd = open(Scorefile, O_RDWR); + if (score_wfd < 0) +score_err = errno; #ifdef FANCY - sp = strrchr(Scorefile, '/'); - if (sp == NULL) - sp = Scorefile; - if (strcmp(sp, "pattern_roll") == 0) - Pattern_roll = true; - else if (strcmp(sp, "stand_still") == 0) - Stand_still = true; - if (Pattern_roll || Stand_still) - Teleport = true; + word = strrchr(Scorefile, '/'); + if (word == NULL) +word = Scorefile; + if (strcmp(word, "pattern_roll") == 0) +Pattern_roll = true; + else if (strcmp(word, "stand_still") == 0) +Stand_still = true; + if (Pattern_roll || Stand_still) +Teleport = true; #endif -} - else -for (sp = &av[0][1]; *sp; sp++) - switch (*sp) { - case 'A': - Auto_bot = true; - break; - case 's': - show_only = true; - break; - case 'r': - Real_time = true; - break; - case 'a': - Start_level = 4; - break; - case 'n': - Num_games++; - break; - case 'j': - Jump = true; - break; - case 't': - Teleport = true; - break; - - default: - fprintf(stderr, "robots: unknown option: %c\n", *sp); - bad_arg = true; - break; - } - if (bad_arg) { - exit(1); - /* NOTREACHED */ } } Index: src/games/robots/robots.6 diff -u src/games/robots/robots.6:1.14 src/games/robots/robots.6:1.15 --- src/games/robots/robots.6:1.14 Thu Apr 9 03:52:54 2009 +++ src/games/robots/robots.6 Wed Aug 5 04:03:47 2009 @@ -1,4 +1,4 @@ -.\" $NetBSD: robots.6,v 1.14 2009/04/09 03:52:54 joerg Exp $ +.\" $NetBSD: robots.6,v 1.15 2009/08/05 04:03:47 dholland Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)robots.6 8.1 (Berkeley) 5/31/93 .\" -.Dd May 31, 1993 +.Dd August 4, 2009 .Dt ROBOTS 6 .Os .Sh NAME @@ -37,7 +37,8 @@ .Nd fight off villainous robots .Sh SYNOPSIS .Nm -.Op Fl Asjtan +.Op Fl Aajnrst +.Op Ar maximum
CVS commit: src/games/robots
Module Name:src Committed By: dholland Date: Mon Aug 3 06:04:13 UTC 2009 Modified Files: src/games/robots: score.c Log Message: don't ignore errors from read(); found by lint To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/games/robots/score.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/robots/score.c diff -u src/games/robots/score.c:1.21 src/games/robots/score.c:1.22 --- src/games/robots/score.c:1.21 Mon Jul 20 06:39:06 2009 +++ src/games/robots/score.c Mon Aug 3 06:04:12 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: score.c,v 1.21 2009/07/20 06:39:06 dholland Exp $ */ +/* $NetBSD: score.c,v 1.22 2009/08/03 06:04:12 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: score.c,v 1.21 2009/07/20 06:39:06 dholland Exp $"); +__RCSID("$NetBSD: score.c,v 1.22 2009/08/03 06:04:12 dholland Exp $"); #endif #endif /* not lint */ @@ -66,10 +66,9 @@ { SCORE *scp; - if (read(inf, &max_uid, sizeof max_uid) == sizeof max_uid) { + if (read(inf, &max_uid, sizeof max_uid) == sizeof max_uid && + read(inf, Top, sizeof Top) == sizeof Top) { max_uid = ntohl(max_uid); - - read(inf, Top, sizeof Top); for (scp = Top; scp < &Top[MAXSCORES]; scp++) { scp->s_uid = ntohl(scp->s_uid); scp->s_score = ntohl(scp->s_score);
CVS commit: src/games/robots
Module Name:src Committed By: dholland Date: Mon Jul 20 06:43:18 UTC 2009 Modified Files: src/games/robots: main.c rnd_pos.c Log Message: Use random() instead of rand(), and seed with time instead of pid. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/games/robots/main.c cvs rdiff -u -r1.8 -r1.9 src/games/robots/rnd_pos.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/robots/main.c diff -u src/games/robots/main.c:1.28 src/games/robots/main.c:1.29 --- src/games/robots/main.c:1.28 Mon Jul 20 06:39:06 2009 +++ src/games/robots/main.c Mon Jul 20 06:43:18 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.28 2009/07/20 06:39:06 dholland Exp $ */ +/* $NetBSD: main.c,v 1.29 2009/07/20 06:43:18 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.28 2009/07/20 06:39:06 dholland Exp $"); +__RCSID("$NetBSD: main.c,v 1.29 2009/07/20 06:43:18 dholland Exp $"); #endif #endif /* not lint */ @@ -50,6 +50,7 @@ #include #include #include +#include #include #include "robots.h" @@ -167,7 +168,7 @@ stdscr = newwin(Y_SIZE, X_SIZE, 0, 0); } - srand(getpid()); + srandom(time(NULL)); if (Real_time) signal(SIGALRM, move_robots); do { Index: src/games/robots/rnd_pos.c diff -u src/games/robots/rnd_pos.c:1.8 src/games/robots/rnd_pos.c:1.9 --- src/games/robots/rnd_pos.c:1.8 Mon Jul 20 06:39:06 2009 +++ src/games/robots/rnd_pos.c Mon Jul 20 06:43:18 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rnd_pos.c,v 1.8 2009/07/20 06:39:06 dholland Exp $ */ +/* $NetBSD: rnd_pos.c,v 1.9 2009/07/20 06:43:18 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: rnd_pos.c,v 1.8 2009/07/20 06:39:06 dholland Exp $"); +__RCSID("$NetBSD: rnd_pos.c,v 1.9 2009/07/20 06:43:18 dholland Exp $"); #endif #endif /* not lint */ @@ -67,5 +67,5 @@ rnd(int range) { - return rand() % range; + return random() % range; }
CVS commit: src/games/robots
Module Name:src Committed By: dholland Date: Mon Jul 20 06:39:06 UTC 2009 Modified Files: src/games/robots: auto.c extern.c flush_in.c init_field.c main.c make_level.c move.c move_robs.c play_level.c query.c rnd_pos.c robots.h score.c Log Message: Assorted minor cleanups, no functional change: - u_int* -> uint* - don't make private typedefs of system structures - use curses TRUE and FALSE only with curses booleans, otherwise true and false; - includes cleanup - group globals in extern.c by functionality Object file diffs inspected. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/games/robots/auto.c cvs rdiff -u -r1.9 -r1.10 src/games/robots/extern.c \ src/games/robots/make_level.c src/games/robots/move_robs.c cvs rdiff -u -r1.8 -r1.9 src/games/robots/flush_in.c \ src/games/robots/play_level.c src/games/robots/query.c cvs rdiff -u -r1.11 -r1.12 src/games/robots/init_field.c cvs rdiff -u -r1.27 -r1.28 src/games/robots/main.c cvs rdiff -u -r1.14 -r1.15 src/games/robots/move.c cvs rdiff -u -r1.7 -r1.8 src/games/robots/rnd_pos.c cvs rdiff -u -r1.20 -r1.21 src/games/robots/robots.h src/games/robots/score.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/robots/auto.c diff -u src/games/robots/auto.c:1.10 src/games/robots/auto.c:1.11 --- src/games/robots/auto.c:1.10 Mon Jul 20 06:00:56 2009 +++ src/games/robots/auto.c Mon Jul 20 06:39:06 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: auto.c,v 1.10 2009/07/20 06:00:56 dholland Exp $ */ +/* $NetBSD: auto.c,v 1.11 2009/07/20 06:39:06 dholland Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -50,6 +50,8 @@ * FI * FI */ +#include +#include #include "robots.h" #define ABS(a) (((a)>0)?(a):-(a)) Index: src/games/robots/extern.c diff -u src/games/robots/extern.c:1.9 src/games/robots/extern.c:1.10 --- src/games/robots/extern.c:1.9 Mon Jul 20 06:00:56 2009 +++ src/games/robots/extern.c Mon Jul 20 06:39:06 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: extern.c,v 1.9 2009/07/20 06:00:56 dholland Exp $ */ +/* $NetBSD: extern.c,v 1.10 2009/07/20 06:39:06 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,45 +34,48 @@ #if 0 static char sccsid[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: extern.c,v 1.9 2009/07/20 06:00:56 dholland Exp $"); +__RCSID("$NetBSD: extern.c,v 1.10 2009/07/20 06:39:06 dholland Exp $"); #endif #endif /* not lint */ #include "robots.h" +bool Real_time = false; /* Play in real time? */ +bool Auto_bot = false; /* Automatic mover */ +bool Jump = false; /* Jump while running, counting, or waiting */ +bool Teleport = false; /* Teleport automatically when player must */ + bool Dead; /* Player is now dead */ -bool Full_clear = TRUE; /* Lots of junk for init_field to clear */ -bool Jump = FALSE; /* Jump while running, counting, or waiting */ +bool Running = false; /* Currently in the middle of a run */ +bool Waiting; /* Player is waiting for end */ bool Newscore; /* There was a new score added */ +bool Was_bonus = false; /* Was a bonus last level */ +bool Full_clear = true; /* Lots of junk for init_field to clear */ + #ifdef FANCY -bool Pattern_roll = FALSE; /* Auto play for YHBJNLUK pattern */ -#endif -bool Real_time = FALSE; /* Play in real time? */ -bool Auto_bot = FALSE; /* Automatic mover */ -bool Running = FALSE; /* Currently in the middle of a run */ -#ifdef FANCY -bool Stand_still = FALSE; /* Auto play for standing still pattern */ +bool Pattern_roll = false; /* Auto play for YHBJNLUK pattern */ +bool Stand_still = false; /* Auto play for standing still pattern */ #endif -bool Teleport = FALSE; /* Teleport automatically when player must */ -bool Waiting; /* Player is waiting for end */ -bool Was_bonus = FALSE; /* Was a bonus last level */ char Cnt_move; /* Command which has preceded the count */ -char Field[Y_FIELDSIZE][X_FIELDSIZE]; /* the playing field itslef */ -const char *Next_move; /* Next move to be used in the pattern */ -const char *Move_list = "YHBJNLUK";/* List of moves in the pattern */ char Run_ch; /* Character for the direction we are running */ +char Field[Y_FIELDSIZE][X_FIELDSIZE]; /* the playing field itself */ + +const char *Next_move; /* Next move to be used in the pattern */ +const char *Move_list = "YHBJNLUK";/* List of moves in the pattern */ + int Count = 0; /* Command count */ int Level; /* Current level */ int Num_robots; /* Number of robots left */ int Num_scrap; /* Number of scrap heaps */ int Num_scores; /* Number of scores posted */ int Num_games; /* Number of games to play */ -u_int32_t Score; /* Current score */ int Start_level = 1; /* Level on which to start */ int Wait_bonus; /* bonus for waiting */ +uint32_t Score; /* Current score */ + COORD Max; /* Max area robots take up */ COORD Min; /* Min area robot
CVS commit: src/games/robots
Module Name:src Committed By: dholland Date: Mon Jul 20 06:09:29 UTC 2009 Modified Files: src/games/robots: init_field.c main.c Log Message: A bit more whitespace. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/games/robots/init_field.c cvs rdiff -u -r1.26 -r1.27 src/games/robots/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/robots/init_field.c diff -u src/games/robots/init_field.c:1.10 src/games/robots/init_field.c:1.11 --- src/games/robots/init_field.c:1.10 Mon Jul 20 06:00:56 2009 +++ src/games/robots/init_field.c Mon Jul 20 06:09:29 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: init_field.c,v 1.10 2009/07/20 06:00:56 dholland Exp $ */ +/* $NetBSD: init_field.c,v 1.11 2009/07/20 06:09:29 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,11 +34,11 @@ #if 0 static char sccsid[] = "@(#)init_field.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: init_field.c,v 1.10 2009/07/20 06:00:56 dholland Exp $"); +__RCSID("$NetBSD: init_field.c,v 1.11 2009/07/20 06:09:29 dholland Exp $"); #endif #endif /* not lint */ -# include "robots.h" +#include "robots.h" static int telx = 0; static int tely = 0; Index: src/games/robots/main.c diff -u src/games/robots/main.c:1.26 src/games/robots/main.c:1.27 --- src/games/robots/main.c:1.26 Mon Jul 20 06:00:56 2009 +++ src/games/robots/main.c Mon Jul 20 06:09:29 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.26 2009/07/20 06:00:56 dholland Exp $ */ +/* $NetBSD: main.c,v 1.27 2009/07/20 06:09:29 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.26 2009/07/20 06:00:56 dholland Exp $"); +__RCSID("$NetBSD: main.c,v 1.27 2009/07/20 06:09:29 dholland Exp $"); #endif #endif /* not lint */ @@ -81,7 +81,7 @@ score_wfd = open(Scorefile, O_RDWR); if (score_wfd < 0) score_err = errno; -# ifdef FANCY +#ifdef FANCY sp = strrchr(Scorefile, '/'); if (sp == NULL) sp = Scorefile; @@ -91,7 +91,7 @@ Stand_still = TRUE; if (Pattern_roll || Stand_still) Teleport = TRUE; -# endif +#endif } else for (sp = &av[0][1]; *sp; sp++)
CVS commit: src/games/robots
Module Name:src Committed By: dholland Date: Mon Jul 20 06:00:56 UTC 2009 Modified Files: src/games/robots: auto.c extern.c flush_in.c init_field.c main.c make_level.c move.c move_robs.c play_level.c query.c rnd_pos.c robots.h score.c Log Message: Whitespace. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/games/robots/auto.c \ src/games/robots/init_field.c cvs rdiff -u -r1.8 -r1.9 src/games/robots/extern.c \ src/games/robots/make_level.c src/games/robots/move_robs.c cvs rdiff -u -r1.7 -r1.8 src/games/robots/flush_in.c \ src/games/robots/play_level.c src/games/robots/query.c cvs rdiff -u -r1.25 -r1.26 src/games/robots/main.c cvs rdiff -u -r1.13 -r1.14 src/games/robots/move.c cvs rdiff -u -r1.6 -r1.7 src/games/robots/rnd_pos.c cvs rdiff -u -r1.19 -r1.20 src/games/robots/robots.h src/games/robots/score.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/robots/auto.c diff -u src/games/robots/auto.c:1.9 src/games/robots/auto.c:1.10 --- src/games/robots/auto.c:1.9 Mon Jul 20 05:44:02 2009 +++ src/games/robots/auto.c Mon Jul 20 06:00:56 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: auto.c,v 1.9 2009/07/20 05:44:02 dholland Exp $ */ +/* $NetBSD: auto.c,v 1.10 2009/07/20 06:00:56 dholland Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -32,14 +32,14 @@ /* * Automatic move. * intelligent ? - * Algo : + * Algo : * IF scrapheaps don't exist THEN - * IF not in danger THEN + * IF not in danger THEN *stay at current position * ELSE *move away from the closest robot * FI - * ELSE + * ELSE * find closest heap * find closest robot * IF scrapheap is adjacent THEN @@ -70,16 +70,16 @@ static int between(COORD *, COORD *); /* distance(): - * return "move" number distance of the two coordinates + * return "move" number distance of the two coordinates */ -static int +static int distance(int x1, int y1, int x2, int y2) { return MAX(ABS(ABS(x1) - ABS(x2)), ABS(ABS(y1) - ABS(y2))); } /* xinc(): - * Return x coordinate moves + * Return x coordinate moves */ static int xinc(int dir) @@ -101,7 +101,7 @@ } /* yinc(): - * Return y coordinate moves + * Return y coordinate moves */ static int yinc(int dir) @@ -123,7 +123,7 @@ } /* find_moves(): - * Find possible moves + * Find possible moves */ static const char * find_moves(void) @@ -136,17 +136,17 @@ static char ans[sizeof moves]; a = ans; -for(m = moves; *m; m++) { +for (m = moves; *m; m++) { test.x = My_pos.x + xinc(*m); test.y = My_pos.y + yinc(*m); move(test.y, test.x); switch(winch(stdscr)) { case ' ': case PLAYER: -for(x = test.x - 1; x <= test.x + 1; x++) { -for(y = test.y - 1; y <= test.y + 1; y++) { +for (x = test.x - 1; x <= test.x + 1; x++) { +for (y = test.y - 1; y <= test.y + 1; y++) { move(y, x); -if(winch(stdscr) == ROBOT) +if (winch(stdscr) == ROBOT) goto bad; } } @@ -155,15 +155,15 @@ bad:; } *a = 0; -if(ans[0]) +if (ans[0]) return ans; else return "t"; } /* closest_robot(): - * return the robot closest to us - * and put in dist its distance + * return the robot closest to us + * and put in dist its distance */ static COORD * closest_robot(int *dist) @@ -183,10 +183,10 @@ *dist = mindist; return minrob; } - + /* closest_heap(): - * return the heap closest to us - * and put in dist its distance + * return the heap closest to us + * and put in dist its distance */ static COORD * closest_heap(int *dist) @@ -210,9 +210,9 @@ } /* move_towards(): - * move as close to the given direction as possible + * move as close to the given direction as possible */ -static char +static char move_towards(int dx, int dy) { char ok_moves[10], best_move; @@ -220,7 +220,7 @@ int move_judge, cur_judge, mvx, mvy; (void)strcpy(ok_moves, find_moves()); - best_move = ok_moves[0]; + best_move = ok_moves[0]; if (best_move != 't') { mvx = xinc(best_move); mvy = yinc(best_move); @@ -239,7 +239,7 @@ } /* move_away(): - * move away form the robot given + * move away form the robot given */ static char move_away(COORD *rob) @@ -253,7 +253,7 @@ /* move_between(): - * move the closest heap between us and the closest robot + * move the closest heap between us and the closest robot */ static char move_between(COORD *rob, COORD *hp) @@ -263,8 +263,8 @@ /* equat
CVS commit: src/games/robots
Module Name:src Committed By: dholland Date: Mon Jul 20 05:44:02 UTC 2009 Modified Files: src/games/robots: auto.c flush_in.c init_field.c main.c make_level.c move.c move_robs.c play_level.c query.c rnd_pos.c robots.h score.c Log Message: ANSIfy. Use __dead. Object diffs checked. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/games/robots/auto.c \ src/games/robots/init_field.c cvs rdiff -u -r1.6 -r1.7 src/games/robots/flush_in.c \ src/games/robots/play_level.c src/games/robots/query.c cvs rdiff -u -r1.24 -r1.25 src/games/robots/main.c cvs rdiff -u -r1.7 -r1.8 src/games/robots/make_level.c \ src/games/robots/move_robs.c cvs rdiff -u -r1.12 -r1.13 src/games/robots/move.c cvs rdiff -u -r1.5 -r1.6 src/games/robots/rnd_pos.c cvs rdiff -u -r1.18 -r1.19 src/games/robots/robots.h src/games/robots/score.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/robots/auto.c diff -u src/games/robots/auto.c:1.8 src/games/robots/auto.c:1.9 --- src/games/robots/auto.c:1.8 Mon Apr 28 20:22:54 2008 +++ src/games/robots/auto.c Mon Jul 20 05:44:02 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: auto.c,v 1.8 2008/04/28 20:22:54 martin Exp $ */ +/* $NetBSD: auto.c,v 1.9 2009/07/20 05:44:02 dholland Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -73,18 +73,16 @@ * return "move" number distance of the two coordinates */ static int -distance(x1, y1, x2, y2) - int x1, y1, x2, y2; +distance(int x1, int y1, int x2, int y2) { return MAX(ABS(ABS(x1) - ABS(x2)), ABS(ABS(y1) - ABS(y2))); -} /* end distance */ +} /* xinc(): * Return x coordinate moves */ static int -xinc(dir) -int dir; +xinc(int dir) { switch(dir) { case 'b': @@ -106,8 +104,7 @@ * Return y coordinate moves */ static int -yinc(dir) -int dir; +yinc(int dir) { switch(dir) { case 'k': @@ -129,7 +126,7 @@ * Find possible moves */ static const char * -find_moves() +find_moves(void) { int x, y; COORD test; @@ -169,8 +166,7 @@ * and put in dist its distance */ static COORD * -closest_robot(dist) - int *dist; +closest_robot(int *dist) { COORD *rob, *end, *minrob = NULL; int tdist, mindist; @@ -186,15 +182,14 @@ } *dist = mindist; return minrob; -} /* end closest_robot */ +} /* closest_heap(): * return the heap closest to us * and put in dist its distance */ static COORD * -closest_heap(dist) - int *dist; +closest_heap(int *dist) { COORD *hp, *end, *minhp = NULL; int mindist, tdist; @@ -212,14 +207,13 @@ } *dist = mindist; return minhp; -} /* end closest_heap */ +} /* move_towards(): * move as close to the given direction as possible */ static char -move_towards(dx, dy) - int dx, dy; +move_towards(int dx, int dy) { char ok_moves[10], best_move; char *ptr; @@ -242,30 +236,27 @@ } } return best_move; -} /* end move_towards */ +} /* move_away(): * move away form the robot given */ static char -move_away(rob) - COORD *rob; +move_away(COORD *rob) { int dx, dy; dx = sign(My_pos.x - rob->x); dy = sign(My_pos.y - rob->y); return move_towards(dx, dy); -} /* end move_away */ +} /* move_between(): * move the closest heap between us and the closest robot */ static char -move_between(rob, hp) - COORD *rob; - COORD *hp; +move_between(COORD *rob, COORD *hp) { int dx, dy; float slope, cons; @@ -314,15 +305,13 @@ CONSDEBUG(("me (%d,%d) robot(%d,%d) heap(%d,%d) delta(%d,%d)", My_pos.x, My_pos.y, rob->x, rob->y, hp->x, hp->y, dx, dy)); return move_towards(dx, dy); -} /* end move_between */ +} /* between(): * Return true if the heap is between us and the robot */ int -between(rob, hp) - COORD *rob; - COORD *hp; +between(COORD *rob, COORD *hp) { /* I = @ */ if (hp->x > rob->x && My_pos.x < rob->x) @@ -341,14 +330,14 @@ if (hp->y > rob->y && My_pos.y < rob->y) return 0; return 1; -} /* end between */ +} /* automove(): * find and do the best move if flag * else get the first move; */ char -automove() +automove(void) { #if 0 return find_moves()[0]; @@ -376,4 +365,4 @@ return move_between(robot_close, heap_close); #endif -} /* end automove */ +} Index: src/games/robots/init_field.c diff -u src/games/robots/init_field.c:1.8 src/games/robots/init_field.c:1.9 --- src/games/robots/init_field.c:1.8 Thu Aug 7 09:37:36 2003 +++ src/games/robots/init_field.c Mon Jul 20 05:44:02 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: init_field.c,v 1.8 2003/08/07 09:37:36 agc Exp $ */ +/* $NetBSD: init_field.c,v 1.9 2009/07/20 05:44:02 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)init_field.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: init_field.c,v 1.8 2003/08/07 09:37:36 agc Exp $"); +__RCSID("$NetBSD: init_field.c,v 1.9 2009/07/20 05:44:02 dholland
CVS commit: src/games/robots
Module Name:src Committed By: joerg Date: Thu Apr 9 03:52:55 UTC 2009 Modified Files: src/games/robots: robots.6 Log Message: \@ is not a valid escape sequence. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/games/robots/robots.6 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/robots/robots.6 diff -u src/games/robots/robots.6:1.13 src/games/robots/robots.6:1.14 --- src/games/robots/robots.6:1.13 Thu Sep 15 02:09:41 2005 +++ src/games/robots/robots.6 Thu Apr 9 03:52:54 2009 @@ -1,4 +1,4 @@ -.\" $NetBSD: robots.6,v 1.13 2005/09/15 02:09:41 wiz Exp $ +.\" $NetBSD: robots.6,v 1.14 2009/04/09 03:52:54 joerg Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -63,7 +63,7 @@ and you (the good guy) by a -.Sq \@ . +.Sq @ . .Pp The commands are: .Bl -tag -width indent -compact