summaryrefslogtreecommitdiffstats
path: root/robots
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>1999-05-15 23:56:35 +0000
committerchristos <christos@NetBSD.org>1999-05-15 23:56:35 +0000
commit36e0b3e5fe951ef4265a0da56201960d52ed7ee6 (patch)
tree6b71e3215f92724a7dac1883a247d5b15aba483c /robots
parent8da3d5189a9a79e6cd764ad062df763e1cb5a962 (diff)
downloadbsdgames-darwin-36e0b3e5fe951ef4265a0da56201960d52ed7ee6.tar.gz
bsdgames-darwin-36e0b3e5fe951ef4265a0da56201960d52ed7ee6.tar.zst
bsdgames-darwin-36e0b3e5fe951ef4265a0da56201960d52ed7ee6.zip
Add -A for automatic playing mode.
Make the score file MI
Diffstat (limited to 'robots')
-rw-r--r--robots/Makefile4
-rw-r--r--robots/auto.c380
-rw-r--r--robots/extern.c8
-rw-r--r--robots/main.c39
-rw-r--r--robots/make_level.c6
-rw-r--r--robots/move.c9
-rw-r--r--robots/move_robs.c7
-rw-r--r--robots/robots.69
-rw-r--r--robots/robots.h18
-rw-r--r--robots/score.c113
10 files changed, 531 insertions, 62 deletions
diff --git a/robots/Makefile b/robots/Makefile
index 521b92f1..6237c712 100644
--- a/robots/Makefile
+++ b/robots/Makefile
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.14 1998/02/18 22:37:32 jtc Exp $
+# $NetBSD: Makefile,v 1.15 1999/05/15 23:56:35 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= robots
CPPFLAGS+=-DMAX_PER_UID=5
-SRCS= extern.c init_field.c main.c make_level.c move.c move_robs.c \
+SRCS= auto.c extern.c init_field.c main.c make_level.c move.c move_robs.c \
play_level.c query.c rnd_pos.c score.c flush_in.c
MAN= robots.6
DPADD= ${LIBCURSES}
diff --git a/robots/auto.c b/robots/auto.c
new file mode 100644
index 00000000..f2621fff
--- /dev/null
+++ b/robots/auto.c
@@ -0,0 +1,380 @@
+/* $NetBSD: auto.c,v 1.1 1999/05/15 23:56:35 christos Exp $ */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Automatic move.
+ * intelligent ?
+ * Algo :
+ * IF scrapheaps don't exist THEN
+ * IF not in danger THEN
+ * stay at current position;
+ * ELSE move away from the closest robot;
+ * FI
+ * ELSE
+ * find closest heap;
+ * find closest robot;
+ * IF scrapheap is adjacenHEN
+ * move behind the scrapheap
+ * ELSE
+ * move away from the closest robot
+ * FI
+ * ELSE
+ * take the move that takes you away from the
+ * robots and closest to the heap
+ * FI
+ * FI
+ */
+#include "robots.h"
+
+#define ABS(a) (((a)>0)?(a):-(a))
+#define MIN(a,b) (((a)>(b))?(b):(a))
+#define MAX(a,b) (((a)<(b))?(b):(a))
+
+#define CONSDEBUG(a)
+
+
+/* distance():
+ * return "move" number distance of the two coordinates
+ */
+static int
+distance(x1, y1, x2, y2)
+ int x1, y1, x2, 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;
+{
+ switch(dir) {
+ case 'b':
+ case 'h':
+ case 'y':
+ return -1;
+ case 'l':
+ case 'n':
+ case 'u':
+ return 1;
+ case 'j':
+ case 'k':
+ default:
+ return 0;
+ }
+}
+
+/* yinc():
+ * Return y coordinate moves
+ */
+static int
+yinc(dir)
+ int dir;
+{
+ switch(dir) {
+ case 'k':
+ case 'u':
+ case 'y':
+ return -1;
+ case 'b':
+ case 'j':
+ case 'n':
+ return 1;
+ case 'h':
+ case 'l':
+ default:
+ return 0;
+ }
+}
+
+/* find_moves():
+ * Find possible moves
+ */
+static char *
+find_moves()
+{
+ int x, y;
+ COORD test;
+ char *m, *a;
+ static char moves[] = ".hjklyubn";
+ static char ans[sizeof moves];
+ a = ans;
+
+ 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++) {
+ move(y, x);
+ if(winch(stdscr) == ROBOT)
+ goto bad;
+ }
+ }
+ *a++ = *m;
+ }
+ bad:;
+ }
+ *a = 0;
+ if(ans[0])
+ a = ans;
+ else
+ a = "t";
+ return a;
+}
+
+/* closest_robot():
+ * return the robot closest to us
+ * and put in dist its distance
+ */
+static COORD *
+closest_robot(dist)
+ int *dist;
+{
+ COORD *rob, *end, *minrob;
+ int tdist, mindist;
+
+ mindist = 1000000;
+ end = &Robots[MAXROBOTS];
+ for (rob = Robots; rob < end; rob++) {
+ tdist = distance(My_pos.x, My_pos.y, rob->x, rob->y);
+ if (tdist < mindist) {
+ minrob = rob;
+ mindist = tdist;
+ }
+ }
+ *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;
+{
+ COORD *hp, *end, *minhp;
+ int mindist, tdist;
+
+ mindist = 1000000;
+ end = &Scrap[MAXROBOTS];
+ for (hp = Scrap; hp < end; hp++) {
+ if (hp->x == 0 && hp->y == 0)
+ break;
+ tdist = distance(My_pos.x, My_pos.y, hp->x, hp->y);
+ if (tdist < mindist) {
+ minhp = hp;
+ mindist = tdist;
+ }
+ }
+ *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;
+{
+ char ok_moves[10], best_move;
+ char *ptr;
+ int move_judge, cur_judge, mvx, mvy;
+
+ (void)strcpy(ok_moves, find_moves());
+ best_move = ok_moves[0];
+ if (best_move != 'F') {
+ mvx = xinc(best_move);
+ mvy = yinc(best_move);
+ move_judge = ABS(mvx - dx) + ABS(mvy - dy);
+ for (ptr = &ok_moves[1]; *ptr != '\0'; ptr++) {
+ mvx = xinc(*ptr);
+ mvy = yinc(*ptr);
+ cur_judge = ABS(mvx - dx) + ABS(mvy - dy);
+ if (cur_judge < move_judge) {
+ move_judge = cur_judge;
+ best_move = *ptr;
+ }
+ }
+ }
+ return best_move;
+} /* end move_towards */
+
+/* move_away():
+ * move away form the robot given
+ */
+static char
+move_away(rob)
+ 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;
+{
+ char ok_moves[10], best_move;
+ char *ptr;
+ int move_judge, cur_judge, dx, dy, mvx, mvy;
+ float slope, cons;
+
+ /* equation of the line between us and the closest robot */
+ if (My_pos.x == rob->x) {
+ /*
+ * me and the robot are aligned in x
+ * change my x so I get closer to the heap
+ * and my y far from the robot
+ */
+ dx = - sign(My_pos.x - hp->x);
+ dy = sign(My_pos.y - rob->y);
+ CONSDEBUG(("aligned in x"));
+ }
+ else if (My_pos.y == rob->y) {
+ /*
+ * me and the robot are aligned in y
+ * change my y so I get closer to the heap
+ * and my x far from the robot
+ */
+ dx = sign(My_pos.x - rob->x);
+ dy = -sign(My_pos.y - hp->y);
+ CONSDEBUG(("aligned in y"));
+ }
+ else {
+ CONSDEBUG(("no aligned"));
+ slope = (My_pos.y - rob->y) / (My_pos.x - rob->x);
+ cons = slope * rob->y;
+ if (ABS(My_pos.x - rob->x) > ABS(My_pos.y - rob->y)) {
+ /*
+ * we are closest to the robot in x
+ * move away from the robot in x and
+ * close to the scrap in y
+ */
+ dx = sign(My_pos.x - rob->x);
+ dy = sign(((slope * ((float) hp->x)) + cons) -
+ ((float) hp->y));
+ }
+ else {
+ dx = sign(((slope * ((float) hp->x)) + cons) -
+ ((float) hp->y));
+ dy = sign(My_pos.y - rob->y);
+ }
+ }
+ 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;
+{
+ /* I = @ */
+ if (hp->x > rob->x && My_pos.x < rob->x)
+ return 0;
+ /* @ = I */
+ if (hp->x < rob->x && My_pos.x > rob->x)
+ return 0;
+ /* @ */
+ /* = */
+ /* I */
+ if (hp->y < rob->y && My_pos.y > rob->y)
+ return 0;
+ /* I */
+ /* = */
+ /* @ */
+ 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()
+{
+#if 0
+ return find_moves()[0];
+#else
+ COORD *robot_close;
+ COORD *heap_close;
+ int robot_dist, robot_heap, heap_dist;
+
+ robot_close = closest_robot(&robot_dist);
+ if (robot_dist > 1)
+ return('.');
+ if (!Num_scrap)
+ /* no scrap heaps just run away */
+ return move_away(robot_close);
+
+ heap_close = closest_heap(&heap_dist);
+ robot_heap = distance(robot_close->x, robot_close->y,
+ heap_close->x, heap_close->y);
+ if (robot_heap <= heap_dist && !between(robot_close, heap_close)) {
+ /*
+ * robot is closest to us from the heap. Run away!
+ */
+ return move_away(robot_close);
+ }
+
+ return move_between(robot_close, heap_close);
+#endif
+} /* end get_move */
diff --git a/robots/extern.c b/robots/extern.c
index 81b4df5e..80c2e909 100644
--- a/robots/extern.c
+++ b/robots/extern.c
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.c,v 1.4 1997/10/12 14:09:56 lukem Exp $ */
+/* $NetBSD: extern.c,v 1.5 1999/05/15 23:56:35 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: extern.c,v 1.4 1997/10/12 14:09:56 lukem Exp $");
+__RCSID("$NetBSD: extern.c,v 1.5 1999/05/15 23:56:35 christos Exp $");
#endif
#endif /* not lint */
@@ -52,6 +52,7 @@ bool Newscore; /* There was a new score added */
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 */
@@ -69,7 +70,9 @@ char Run_ch; /* Character for the direction we are running */
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 */
int Score; /* Current score */
int Start_level = 1; /* Level on which to start */
int Wait_bonus; /* bonus for waiting */
@@ -78,5 +81,6 @@ COORD Max; /* Max area robots take up */
COORD Min; /* Min area robots take up */
COORD My_pos; /* Player's current position */
COORD Robots[MAXROBOTS]; /* Robots' current positions */
+COORD Scrap[MAXROBOTS]; /* ScrapHeap' current position */
jmp_buf End_move; /* Jump to on Real_time */
diff --git a/robots/main.c b/robots/main.c
index 27263b9d..b1c2ff36 100644
--- a/robots/main.c
+++ b/robots/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.7 1997/10/12 14:16:26 lukem Exp $ */
+/* $NetBSD: main.c,v 1.8 1999/05/15 23:56:36 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: main.c,v 1.7 1997/10/12 14:16:26 lukem Exp $");
+__RCSID("$NetBSD: main.c,v 1.8 1999/05/15 23:56:36 christos Exp $");
#endif
#endif /* not lint */
@@ -63,6 +63,7 @@ main(ac, av)
extern int Max_per_uid;
show_only = FALSE;
+ Num_games = 1;
if (ac > 1) {
bad_arg = FALSE;
for (++av; ac > 1 && *av[0]; av++, ac--)
@@ -88,6 +89,9 @@ main(ac, av)
else
for (sp = &av[0][1]; *sp; sp++)
switch (*sp) {
+ case 'A':
+ Auto_bot = TRUE;
+ break;
case 's':
show_only = TRUE;
break;
@@ -97,12 +101,16 @@ main(ac, av)
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: uknown option: %c\n", *sp);
bad_arg = TRUE;
@@ -140,16 +148,25 @@ main(ac, av)
if (Real_time)
signal(SIGALRM, move_robots);
do {
- init_field();
- for (Level = Start_level; !Dead; Level++) {
- make_level();
- play_level();
+ while (Num_games--) {
+ init_field();
+ for (Level = Start_level; !Dead; Level++) {
+ make_level();
+ play_level();
+ if (Auto_bot)
+ sleep(1);
+ }
+ move(My_pos.y, My_pos.x);
+ printw("AARRrrgghhhh....");
+ refresh();
+ if (Auto_bot)
+ sleep(1);
+ score();
+ if (Auto_bot)
+ sleep(1);
+ refresh();
}
- move(My_pos.y, My_pos.x);
- printw("AARRrrgghhhh....");
- refresh();
- score();
- } while (another());
+ } while (!Auto_bot && another());
quit(0);
/* NOTREACHED */
return(0);
diff --git a/robots/make_level.c b/robots/make_level.c
index b67d4d74..d4f15b4f 100644
--- a/robots/make_level.c
+++ b/robots/make_level.c
@@ -1,4 +1,4 @@
-/* $NetBSD: make_level.c,v 1.5 1997/10/12 14:16:27 lukem Exp $ */
+/* $NetBSD: make_level.c,v 1.6 1999/05/15 23:56:36 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)make_level.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: make_level.c,v 1.5 1997/10/12 14:16:27 lukem Exp $");
+__RCSID("$NetBSD: make_level.c,v 1.6 1999/05/15 23:56:36 christos Exp $");
#endif
#endif /* not lint */
@@ -78,6 +78,8 @@ make_level()
if ((i = Level * 10) > MAXROBOTS)
i = MAXROBOTS;
Num_robots = i;
+ memset(Scrap, 0, sizeof(Scrap[0]) * MAXROBOTS);
+ Num_scrap = 0;
while (i-- > 0) {
cp = rnd_pos();
Robots[i] = *cp;
diff --git a/robots/move.c b/robots/move.c
index ff8476cd..db08c84c 100644
--- a/robots/move.c
+++ b/robots/move.c
@@ -1,4 +1,4 @@
-/* $NetBSD: move.c,v 1.7 1998/07/24 23:28:02 hubertf Exp $ */
+/* $NetBSD: move.c,v 1.8 1999/05/15 23:56:36 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: move.c,v 1.7 1998/07/24 23:28:02 hubertf Exp $");
+__RCSID("$NetBSD: move.c,v 1.8 1999/05/15 23:56:36 christos Exp $");
#endif
#endif /* not lint */
@@ -94,7 +94,10 @@ get_move()
#endif
else {
over:
- c = getchar();
+ if (Auto_bot)
+ c = automove();
+ else
+ c = getchar();
if (isdigit(c)) {
Count = (c - '0');
while (isdigit(c = getchar()))
diff --git a/robots/move_robs.c b/robots/move_robs.c
index b45357cd..be354e0b 100644
--- a/robots/move_robs.c
+++ b/robots/move_robs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: move_robs.c,v 1.4 1997/10/12 14:10:00 lukem Exp $ */
+/* $NetBSD: move_robs.c,v 1.5 1999/05/15 23:56:36 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)move_robs.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: move_robs.c,v 1.4 1997/10/12 14:10:00 lukem Exp $");
+__RCSID("$NetBSD: move_robs.c,v 1.5 1999/05/15 23:56:36 christos Exp $");
#endif
#endif /* not lint */
@@ -91,6 +91,7 @@ move_robots(was_sig)
Dead = TRUE;
else if (Field[rp->y][rp->x] > 1) {
mvaddch(rp->y, rp->x, HEAP);
+ Scrap[Num_scrap++] = *rp;
rp->y = -1;
Num_robots--;
if (Waiting)
@@ -122,7 +123,7 @@ move_robots(was_sig)
move(Max.y, Max.x);
addch(inch());
standend();
-# endif DEBUG
+# endif /* DEBUG */
if (Real_time)
alarm(3);
}
diff --git a/robots/robots.6 b/robots/robots.6
index 19f7d387..cc77763d 100644
--- a/robots/robots.6
+++ b/robots/robots.6
@@ -1,4 +1,4 @@
-.\" $NetBSD: robots.6,v 1.6 1997/10/12 14:10:03 lukem Exp $
+.\" $NetBSD: robots.6,v 1.7 1999/05/15 23:56:36 christos Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -41,7 +41,7 @@
.Nd fight off villainous robots
.Sh SYNOPSIS
.Nm
-.Op Fl sjta
+.Op Fl Asjtan
.Op Ar scorefile
.Sh DESCRIPTION
.Nm
@@ -138,9 +138,14 @@ This is a little disconcerting until you get used to it, and then it is
very nice.
.It Fl a
Advance into the higher levels directly, skipping the lower, easier levels.
+.It Fl A
+Auto-bot mode. Let's the game play itself.
+.It Fl n
+Increase the number of games played by one.
.El
.Sh AUTHOR
Ken Arnold
+Christos Zoulas (autobot mode)
.Sh FILES
.Bl -tag -width /var/games/robots_roll -compact
.It Pa /var/games/robots_roll
diff --git a/robots/robots.h b/robots/robots.h
index b572ec87..d0737505 100644
--- a/robots/robots.h
+++ b/robots/robots.h
@@ -1,4 +1,4 @@
-/* $NetBSD: robots.h,v 1.8 1998/09/13 15:27:29 hubertf Exp $ */
+/* $NetBSD: robots.h,v 1.9 1999/05/15 23:56:36 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -85,9 +85,11 @@ typedef struct {
} COORD;
typedef struct {
- int s_uid;
- int s_score;
- char s_name[MAXNAME];
+ u_int32_t s_uid;
+ u_int32_t s_score;
+ u_int32_t s_auto;
+ u_int32_t s_level;
+ char s_name[MAXNAME];
} SCORE;
typedef struct passwd PASSWD;
@@ -97,7 +99,7 @@ typedef struct passwd PASSWD;
*/
extern bool Dead, Full_clear, Jump, Newscore, Real_time, Running,
- Teleport, Waiting, Was_bonus;
+ Teleport, Waiting, Was_bonus, Auto_bot;
#ifdef FANCY
extern bool Pattern_roll, Stand_still;
@@ -106,10 +108,10 @@ extern bool Pattern_roll, Stand_still;
extern char Cnt_move, Field[Y_FIELDSIZE][X_FIELDSIZE], *Next_move,
*Move_list, Run_ch;
-extern int Count, Level, Num_robots, Num_scores, Score,
- Start_level, Wait_bonus;
+extern int Count, Level, Num_robots, Num_scrap, Num_scores, Score,
+ Start_level, Wait_bonus, Num_games;
-extern COORD Max, Min, My_pos, Robots[];
+extern COORD Max, Min, My_pos, Robots[], Scrap[];
extern jmp_buf End_move;
diff --git a/robots/score.c b/robots/score.c
index c43e4011..7781e3ad 100644
--- a/robots/score.c
+++ b/robots/score.c
@@ -1,4 +1,4 @@
-/* $NetBSD: score.c,v 1.5 1997/10/12 14:16:28 lukem Exp $ */
+/* $NetBSD: score.c,v 1.6 1999/05/15 23:56:36 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: score.c,v 1.5 1997/10/12 14:16:28 lukem Exp $");
+__RCSID("$NetBSD: score.c,v 1.6 1999/05/15 23:56:36 christos Exp $");
#endif
#endif /* not lint */
@@ -51,6 +51,62 @@ int Max_per_uid = MAX_PER_UID;
static SCORE Top[MAXSCORES];
+static u_int32_t numscores, max_uid;
+
+/*
+ * read_score:
+ * Read the score file in MI format
+ */
+static void
+read_score(inf)
+ int inf;
+{
+ SCORE *scp;
+
+ if (read(inf, &max_uid, sizeof max_uid) == sizeof max_uid) {
+ 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);
+ scp->s_auto = ntohl(scp->s_auto);
+ scp->s_level = ntohl(scp->s_level);
+ }
+ }
+ else {
+ for (scp = Top; scp < &Top[MAXSCORES]; scp++)
+ scp->s_score = 0;
+ max_uid = Max_per_uid;
+ }
+}
+
+/*
+ * write_score:
+ * Write the score file in MI format
+ */
+static void
+write_score(inf)
+ int inf;
+{
+ SCORE *scp;
+
+ lseek(inf, 0L, 0);
+
+ max_uid = htonl(max_uid);
+ write(inf, &max_uid, sizeof max_uid);
+
+ for (scp = Top; scp < &Top[MAXSCORES]; scp++) {
+ scp->s_uid = htonl(scp->s_uid);
+ scp->s_score = htonl(scp->s_score);
+ scp->s_auto = htonl(scp->s_auto);
+ scp->s_level = htonl(scp->s_level);
+ }
+
+ write(inf, Top, sizeof Top);
+}
+
+
/*
* score:
* Post the player's score, if reasonable, and then print out the
@@ -59,11 +115,10 @@ static SCORE Top[MAXSCORES];
void
score()
{
- int inf;
- SCORE *scp;
- int uid;
- bool done_show = FALSE;
- static int numscores, max_uid;
+ int inf;
+ SCORE *scp;
+ int uid;
+ bool done_show = FALSE;
Newscore = FALSE;
if ((inf = open(Scorefile, O_RDWR)) < 0) {
@@ -71,13 +126,7 @@ score()
return;
}
- if (read(inf, &max_uid, sizeof max_uid) == sizeof max_uid)
- read(inf, Top, sizeof Top);
- else {
- for (scp = Top; scp < &Top[MAXSCORES]; scp++)
- scp->s_score = -1;
- max_uid = Max_per_uid;
- }
+ read_score(inf);
uid = getuid();
if (Top[MAXSCORES-1].s_score <= Score) {
@@ -89,6 +138,8 @@ score()
break;
scp->s_score = Score;
scp->s_uid = uid;
+ scp->s_auto = Auto_bot;
+ scp->s_level = Level;
set_name(scp);
Newscore = TRUE;
break;
@@ -96,6 +147,8 @@ score()
if (scp == &Top[MAXSCORES]) {
Top[MAXSCORES-1].s_score = Score;
Top[MAXSCORES-1].s_uid = uid;
+ Top[MAXSCORES-1].s_auto = Auto_bot;
+ Top[MAXSCORES-1].s_level = Level;
set_name(&Top[MAXSCORES-1]);
Newscore = TRUE;
}
@@ -111,13 +164,19 @@ score()
else
Full_clear = TRUE;
+ move(1, 15);
+ printw("%5.5s %5.5s %-9.9s %-8.8s %5.5s", "Rank", "Score", "User",
+ " ", "Level");
+
for (scp = Top; scp < &Top[MAXSCORES]; scp++) {
- if (scp->s_score < 0)
+ if (scp->s_score == 0)
break;
- move((scp - Top) + 1, 15);
+ move((scp - Top) + 2, 15);
if (!done_show && scp->s_uid == uid && scp->s_score == Score)
standout();
- printw(" %d\t%d\t%-8.8s ", (scp - Top) + 1, scp->s_score, scp->s_name);
+ printw("%5.5d %5.5d %-8.8s %-9.9s %5.5d",
+ (scp - Top) + 1, scp->s_score, scp->s_name,
+ Auto_bot ? "(autobot)" : "", scp->s_level);
if (!done_show && scp->s_uid == uid && scp->s_score == Score) {
standend();
done_show = TRUE;
@@ -127,9 +186,7 @@ score()
refresh();
if (Newscore) {
- lseek(inf, 0L, 0);
- write(inf, &max_uid, sizeof max_uid);
- write(inf, Top, sizeof Top);
+ write_score(inf);
}
close(inf);
}
@@ -165,22 +222,20 @@ show_score()
{
SCORE *scp;
int inf;
- static int max_score;
if ((inf = open(Scorefile, O_RDONLY)) < 0) {
warn("opening `%s'", Scorefile);
return;
}
- for (scp = Top; scp < &Top[MAXSCORES]; scp++)
- scp->s_score = -1;
-
- read(inf, &max_score, sizeof max_score);
- read(inf, Top, sizeof Top);
+ read_score(inf);
close(inf);
inf = 1;
+ printf("%5.5s %5.5s %-9.9s %-8.8s %5.5s\n", "Rank", "Score", "User",
+ " ", "Level");
for (scp = Top; scp < &Top[MAXSCORES]; scp++)
- if (scp->s_score >= 0)
- printf("%d\t%d\t%.*s\n", inf++, scp->s_score,
- (int)(sizeof(scp->s_name)), scp->s_name);
+ if (scp->s_score > 0)
+ printf("%5.5d %5.5d %-8.8s %-9.9s %5.5d\n",
+ inf++, scp->s_score, scp->s_name,
+ scp->s_auto ? "(autobot)" : "", scp->s_level);
}