Browse Source

Plan 9 from Bell Labs 2004-09-28

David du Colombier 20 years ago
parent
commit
0feb113f1f
5 changed files with 232 additions and 3 deletions
  1. 9 1
      dist/replica/_plan9.db
  2. 6 1
      dist/replica/plan9.db
  3. 9 0
      dist/replica/plan9.log
  4. 28 1
      sys/man/1/games
  5. 180 0
      sys/src/games/juggle.c

+ 9 - 1
dist/replica/_plan9.db

@@ -239,6 +239,10 @@
 386/bin/fs/v10fs - 775 sys sys 1085077058 92404
 386/bin/fs/v10fs - 775 sys sys 1085077058 92404
 386/bin/fs/v6fs - 775 sys sys 1085077059 92322
 386/bin/fs/v6fs - 775 sys sys 1085077059 92322
 386/bin/ftpfs - 775 sys sys 1093489558 146386
 386/bin/ftpfs - 775 sys sys 1093489558 146386
+386/bin/games - 20000000775 sys sys 1096298711 0
+386/bin/games/juggle - 775 sys sys 1096307527 123161
+386/bin/games/mahjongg - 775 sys sys 1096298712 161454
+386/bin/games/sokoban - 775 sys sys 1096298711 157093
 386/bin/getmap - 775 sys sys 1085077059 63150
 386/bin/getmap - 775 sys sys 1085077059 63150
 386/bin/gif - 775 sys sys 1085077060 155975
 386/bin/gif - 775 sys sys 1085077060 155975
 386/bin/grap - 775 sys sys 1094040086 280301
 386/bin/grap - 775 sys sys 1094040086 280301
@@ -4685,7 +4689,7 @@ sys/man/1/filter - 664 sys sys 1041108741 4403
 sys/man/1/fmt - 664 sys sys 1070032221 1557
 sys/man/1/fmt - 664 sys sys 1070032221 1557
 sys/man/1/fortune - 664 sys sys 944959673 449
 sys/man/1/fortune - 664 sys sys 944959673 449
 sys/man/1/freq - 664 sys sys 944959673 735
 sys/man/1/freq - 664 sys sys 944959673 735
-sys/man/1/games - 664 sys sys 1095792424 1853
+sys/man/1/games - 664 sys sys 1096308821 2280
 sys/man/1/grap - 664 sys sys 944959675 6417
 sys/man/1/grap - 664 sys sys 944959675 6417
 sys/man/1/graph - 664 sys sys 944959673 2858
 sys/man/1/graph - 664 sys sys 944959673 2858
 sys/man/1/grep - 664 sys sys 969512677 2224
 sys/man/1/grep - 664 sys sys 969512677 2224
@@ -11271,6 +11275,7 @@ sys/src/fs/sony/mem.h - 664 sys sys 1015110103 2865
 sys/src/fs/sony/mkfile - 664 sys sys 1091803623 1594
 sys/src/fs/sony/mkfile - 664 sys sys 1091803623 1594
 sys/src/fs/worms - 664 sys sys 1015110031 2806
 sys/src/fs/worms - 664 sys sys 1015110031 2806
 sys/src/games - 20000000775 sys sys 1095792091 0
 sys/src/games - 20000000775 sys sys 1095792091 0
+sys/src/games/juggle.c - 664 sys sys 1096307525 4105
 sys/src/games/mahjongg - 20000000775 sys sys 1095792293 0
 sys/src/games/mahjongg - 20000000775 sys sys 1095792293 0
 sys/src/games/mahjongg/graphics.c - 644 sys sys 1095792293 5794
 sys/src/games/mahjongg/graphics.c - 644 sys sys 1095792293 5794
 sys/src/games/mahjongg/level.c - 644 sys sys 1095792293 2522
 sys/src/games/mahjongg/level.c - 644 sys sys 1095792293 2522
@@ -12377,3 +12382,6 @@ usr/glenda/lib/profile - 664 glenda glenda 1021580005 847
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/tmp - 20000000775 glenda glenda 1018802620 0
 usr/glenda/tmp - 20000000775 glenda glenda 1018802620 0
+386/bin/games/juggle - 775 sys sys 1096341940 123161
+386/bin/games/mahjongg - 775 sys sys 1096341940 161454
+386/bin/games/sokoban - 775 sys sys 1096341940 157093

+ 6 - 1
dist/replica/plan9.db

@@ -239,6 +239,10 @@
 386/bin/fs/v10fs - 775 sys sys 1085077058 92404
 386/bin/fs/v10fs - 775 sys sys 1085077058 92404
 386/bin/fs/v6fs - 775 sys sys 1085077059 92322
 386/bin/fs/v6fs - 775 sys sys 1085077059 92322
 386/bin/ftpfs - 775 sys sys 1093489558 146386
 386/bin/ftpfs - 775 sys sys 1093489558 146386
+386/bin/games - 20000000775 sys sys 1096298711 0
+386/bin/games/juggle - 775 sys sys 1096341940 123161
+386/bin/games/mahjongg - 775 sys sys 1096341940 161454
+386/bin/games/sokoban - 775 sys sys 1096341940 157093
 386/bin/getmap - 775 sys sys 1085077059 63150
 386/bin/getmap - 775 sys sys 1085077059 63150
 386/bin/gif - 775 sys sys 1085077060 155975
 386/bin/gif - 775 sys sys 1085077060 155975
 386/bin/grap - 775 sys sys 1094040086 280301
 386/bin/grap - 775 sys sys 1094040086 280301
@@ -4685,7 +4689,7 @@ sys/man/1/filter - 664 sys sys 1041108741 4403
 sys/man/1/fmt - 664 sys sys 1070032221 1557
 sys/man/1/fmt - 664 sys sys 1070032221 1557
 sys/man/1/fortune - 664 sys sys 944959673 449
 sys/man/1/fortune - 664 sys sys 944959673 449
 sys/man/1/freq - 664 sys sys 944959673 735
 sys/man/1/freq - 664 sys sys 944959673 735
-sys/man/1/games - 664 sys sys 1095792424 1853
+sys/man/1/games - 664 sys sys 1096308821 2280
 sys/man/1/grap - 664 sys sys 944959675 6417
 sys/man/1/grap - 664 sys sys 944959675 6417
 sys/man/1/graph - 664 sys sys 944959673 2858
 sys/man/1/graph - 664 sys sys 944959673 2858
 sys/man/1/grep - 664 sys sys 969512677 2224
 sys/man/1/grep - 664 sys sys 969512677 2224
@@ -11271,6 +11275,7 @@ sys/src/fs/sony/mem.h - 664 sys sys 1015110103 2865
 sys/src/fs/sony/mkfile - 664 sys sys 1091803623 1594
 sys/src/fs/sony/mkfile - 664 sys sys 1091803623 1594
 sys/src/fs/worms - 664 sys sys 1015110031 2806
 sys/src/fs/worms - 664 sys sys 1015110031 2806
 sys/src/games - 20000000775 sys sys 1095792091 0
 sys/src/games - 20000000775 sys sys 1095792091 0
+sys/src/games/juggle.c - 664 sys sys 1096307525 4105
 sys/src/games/mahjongg - 20000000775 sys sys 1095792293 0
 sys/src/games/mahjongg - 20000000775 sys sys 1095792293 0
 sys/src/games/mahjongg/graphics.c - 644 sys sys 1095792293 5794
 sys/src/games/mahjongg/graphics.c - 644 sys sys 1095792293 5794
 sys/src/games/mahjongg/level.c - 644 sys sys 1095792293 2522
 sys/src/games/mahjongg/level.c - 644 sys sys 1095792293 2522

+ 9 - 0
dist/replica/plan9.log

@@ -16763,3 +16763,12 @@
 1096083150 1 c 386/bin/ip/ppp - 775 sys sys 1096081599 216592
 1096083150 1 c 386/bin/ip/ppp - 775 sys sys 1096081599 216592
 1096084951 0 c 386/bin/stats - 775 sys sys 1096083840 187903
 1096084951 0 c 386/bin/stats - 775 sys sys 1096083840 187903
 1096084951 1 c 386/bin/ip/ppp - 775 sys sys 1096083839 216592
 1096084951 1 c 386/bin/ip/ppp - 775 sys sys 1096083839 216592
+1096299055 0 a 386/bin/games - 20000000775 sys sys 1096298711 0
+1096299055 1 a 386/bin/games/mahjongg - 775 sys sys 1096298712 161454
+1096299055 2 a 386/bin/games/sokoban - 775 sys sys 1096298711 157093
+1096308055 0 a 386/bin/games/juggle - 775 sys sys 1096307527 123161
+1096308055 1 a sys/src/games/juggle.c - 664 sys sys 1096307525 4105
+1096309855 0 c sys/man/1/games - 664 sys sys 1096308821 2280
+1096342261 0 c 386/bin/games/juggle - 775 sys sys 1096341940 123161
+1096342261 1 c 386/bin/games/mahjongg - 775 sys sys 1096341940 161454
+1096342261 2 c 386/bin/games/sokoban - 775 sys sys 1096341940 157093

+ 28 - 1
sys/man/1/games

@@ -2,6 +2,18 @@
 .SH NAME
 .SH NAME
 mahjongg, sokoban \- time wasters
 mahjongg, sokoban \- time wasters
 .SH SYNOPSIS
 .SH SYNOPSIS
+.B games/juggle
+[
+.B -d
+.I delay
+] [
+.B -h
+.I hands
+] [
+.I start
+]
+.I pattern
+.br
 .B games/mahjongg
 .B games/mahjongg
 [
 [
 .B -c
 .B -c
@@ -18,12 +30,27 @@ mahjongg, sokoban \- time wasters
 .br
 .br
 .B games/sokoban
 .B games/sokoban
 [
 [
-.B level
+.I level
 ]
 ]
 .SH DESCRIPTION
 .SH DESCRIPTION
 There are a few games in
 There are a few games in
 .BR /bin/games :
 .BR /bin/games :
 .TP
 .TP
+.B juggle
+Display the juggling
+.I pattern
+using the optional initial
+.I start
+pattern.
+The number of hands involved (default 2) can be specified with
+.BR -h ,
+and
+.I delay
+can be used to speed up or slow down the action (default is 20).
+Try the pattern 333333441333333 or 333353505151512333333
+(see
+.IR http://seehuhn.de/jong/theory.html ).
+.TP
 .B mahjongg
 .B mahjongg
 Remove all tiles
 Remove all tiles
 from the board. Click on tiles with the same face that
 from the board. Click on tiles with the same face that

+ 180 - 0
sys/src/games/juggle.c

@@ -0,0 +1,180 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <event.h>
+#define	NSTEP	10		/* number of steps between throws */
+#define	RBALL	10		/* radius of ball images */
+#define	NBALL	100
+int nhand=2;
+int delay=20;			/* ms delay between steps */
+int nball;
+int maxhgt;
+Rectangle win;
+
+#define add addpt
+#define sub subpt
+#define inset insetrect
+
+/*
+ * pattern lists the heights of a repeating sequence of throws.
+ * At time t, hand t%nhand throws.  At that time, it must
+ * hold exactly one ball, unless it executes a 0 throw,
+ * in which case it must hold no ball.  A throw of height h
+ * at time t lands at time t+h in hand (t+h)%nhand.
+ */
+typedef struct Ball Ball;
+struct Ball{
+	int oldhand;	/* hand that previously held the ball */
+	int hgt;	/* how high the throw from oldhand was */
+	int time;	/* time at which ball will arrive */
+	int hand;	/* hand in which ball will rest on arrival */
+};
+Ball ball[NBALL];
+void throw(int t, int hgt){
+	int hand=t%nhand;
+	int i, b, n;
+	b=n=0;
+	for(i=0;i!=nball;i++) if(ball[i].hand==hand && ball[i].time<=t){
+		n++;
+		b=i;
+	}
+	if(hgt==0){
+		if(n!=0){
+			print("bad zero throw at t=%d, nball=%d\n", t, n);
+			exits("bad");
+		}
+	}
+	else if(n!=1){
+		print("bad ball count at t=%d, nball=%d\n", t, n);
+		exits("bad");
+	}
+	else{
+		ball[b].oldhand=hand;
+		ball[b].hgt=hgt;
+		ball[b].time=t+hgt;
+		ball[b].hand=(hand+hgt)%nhand;
+	}
+}
+Point bpos(int b, int step, int t){
+	Ball *bp=&ball[b];
+	double dt=t-1+(step+1.)/NSTEP-(bp->time-bp->hgt);
+	double hgt=(bp->hgt*dt-dt*dt)*4./(maxhgt*maxhgt);
+	double alpha=(bp->oldhand+(bp->hand-bp->oldhand)*dt/bp->hgt)/(nhand-1);
+	return (Point){win.min.x+(win.max.x-win.min.x)*alpha,
+		       win.max.y-1+(win.min.y-win.max.y)*hgt};
+}
+Image *image, *disk;
+void move(int t){
+	int i, j;
+	for(i=0;i!=NSTEP;i++){
+		if(ecanmouse()) emouse();
+		draw(image, inset(image->r, 3), display->white, nil, ZP);
+		for(j=0;j!=nball;j++)
+			draw(image, rectaddpt(disk->r, sub(bpos(j, i, t), Pt(RBALL, RBALL))),
+				disk, nil, ZP);
+		draw(screen, screen->r, image, nil, image->r.min);
+		flushimage(display, 1);
+		if(delay>0)
+			sleep(delay);
+	}
+}
+
+void
+usage(char *name)
+{
+	fprint(2, "usage: %s [start] pattern\n", name);
+	exits("usage");
+}
+
+void 
+eresized(int new){
+	if(new && getwindow(display, Refnone) < 0) {
+		sysfatal("can't reattach to window");
+	}
+	if(image) freeimage(image);
+	image=allocimage(display, screen->r, screen->chan, 0, DNofill);
+	draw(image, image->r, display->black, nil, ZP);
+	win=inset(screen->r, 4+2*RBALL);
+}
+void
+main(int argc, char *argv[]){
+	int sum, i, t, hgt, nstart, npattern;
+	char *s, *start = nil, *pattern = nil;
+
+	ARGBEGIN{
+	default:
+		usage(argv0);
+	case 'd':
+		s = ARGF();
+		if(s == nil)
+			usage(argv0);
+		delay = strtol(argv[0], &s, 0);
+		if(delay < 0 || s == argv[0] || *s != '\0')
+			usage(argv0);
+		break;
+	case 'h':
+		s = ARGF();
+		if(s == nil)
+			usage(argv0);
+		nhand = strtol(argv[0], &s, 0);
+		if(nhand <= 0 || s == argv[0] || *s != '\0')
+			usage(argv0);
+		break;
+	}ARGEND
+	
+	switch(argc) {
+	case 1: 
+			start=""; 
+			pattern=argv[0]; 
+			break;
+	case 2: 
+			start=argv[0]; 
+			pattern=argv[1]; 
+			break;
+	default: 
+			usage(argv0);
+	}
+	sum=0;
+	maxhgt=0;
+	for(s=pattern;*s;s++){
+		hgt=*s-'0';
+		sum+=hgt;
+		if(maxhgt<hgt) maxhgt=hgt;
+	}
+	npattern=s-pattern;
+	for(s=start;*s;s++){
+		hgt=*s-'0';
+		if(maxhgt<hgt) maxhgt=hgt;
+	}
+	if(sum%npattern){
+		print("%s: non-integral ball count\n",argv[0]);
+		exits("partial ball");
+	}
+	nball=sum/npattern;
+	for(i=0;i!=nball;i++){
+		ball[i].oldhand=(i-nball)%nhand;
+		if(ball[i].oldhand<0) ball[i].oldhand+=nhand;
+		ball[i].hgt=nball;
+		ball[i].time=i;
+		ball[i].hand=i%nhand;
+	}
+	if(initdraw(nil, nil, "juggle") < 0)
+		sysfatal("initdraw failed: %r");
+	einit(Emouse);
+	disk=allocimage(display, Rect(0, 0, 2*RBALL+1, 2*RBALL+1), screen->chan, 0, DWhite);
+	fillellipse(disk, Pt(RBALL, RBALL), RBALL, RBALL, display->black, ZP);
+	eresized(0);
+	if(image==0){
+		print("can't allocate bitmap");
+		exits("no space");
+	}
+	for(t=0;start[t];t++){
+		move(t);
+		throw(t, start[t]-'0');
+	}
+	nstart=t;
+	for(;;t++){
+		move(t);
+		throw(t, pattern[(t-nstart)%npattern]-'0');
+	}
+}