summaryrefslogtreecommitdiff
path: root/games/backgammon/teachgammon
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1995-10-18 08:53:40 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1995-10-18 08:53:40 +0000
commitd6583bb2a13f329cf0332ef2570eb8bb8fc0e39c (patch)
treeece253b876159b39c620e62b6c9b1174642e070e /games/backgammon/teachgammon
initial import of NetBSD tree
Diffstat (limited to 'games/backgammon/teachgammon')
-rw-r--r--games/backgammon/teachgammon/Makefile16
-rw-r--r--games/backgammon/teachgammon/data.c321
-rw-r--r--games/backgammon/teachgammon/teach.c170
-rw-r--r--games/backgammon/teachgammon/ttext1.c190
-rw-r--r--games/backgammon/teachgammon/ttext2.c199
-rw-r--r--games/backgammon/teachgammon/tutor.c161
-rw-r--r--games/backgammon/teachgammon/tutor.h47
7 files changed, 1104 insertions, 0 deletions
diff --git a/games/backgammon/teachgammon/Makefile b/games/backgammon/teachgammon/Makefile
new file mode 100644
index 00000000000..0fd1aff9409
--- /dev/null
+++ b/games/backgammon/teachgammon/Makefile
@@ -0,0 +1,16 @@
+# $NetBSD: Makefile,v 1.5 1995/03/21 15:06:07 cgd Exp $
+# @(#)Makefile 8.1 (Berkeley) 5/31/93
+
+PROG= teachgammon
+CFLAGS+=-DV7 -I${.CURDIR}/../common_source
+SRCS= allow.c board.c check.c data.c fancy.c init.c odds.c one.c save.c \
+ subs.c table.c teach.c ttext1.c ttext2.c tutor.c
+DPADD= ${LIBTERM} ${LIBCOMPAT}
+LDADD= -ltermcap -lcompat
+HIDEGAME=hidegame
+NOMAN= noman
+
+.PATH: ${.CURDIR}/../common_source
+
+.include "../../Makefile.inc"
+.include <bsd.prog.mk>
diff --git a/games/backgammon/teachgammon/data.c b/games/backgammon/teachgammon/data.c
new file mode 100644
index 00000000000..0c7b724ca91
--- /dev/null
+++ b/games/backgammon/teachgammon/data.c
@@ -0,0 +1,321 @@
+/* $NetBSD: data.c,v 1.3 1995/03/21 15:06:10 cgd Exp $ */
+
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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 University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)data.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: data.c,v 1.3 1995/03/21 15:06:10 cgd Exp $";
+#endif
+#endif /* not lint */
+
+#include "tutor.h"
+
+int maxmoves = 23;
+
+char *text0[] = {
+ "To start the game, I roll a 3, and you roll a 1. This means",
+ "that I get to start first. I move 8-5,6-5 since this makes a",
+ "new point and helps to trap your back men on 1. You should be",
+ "able to do a similar move with your roll.",
+ 0
+};
+
+char *text1[] = {
+ "Now you shall see a move using doubles. I just rolled double",
+ "5's. I will move two men from position 13 to position 3. The",
+ "notation for this is 13-8,13-8,8-3,8-3. You will also roll dou-",
+ "bles, but you will be able to make a much stronger move.",
+ 0
+};
+
+char *text2[] = {
+ "Excellent! As you can see, you are beginning to develop a wall",
+ "which is trapping my men on position 24. Also, moving your back",
+ "men forward not only improves your board position safely, but it",
+ "thwarts my effort to make a wall.",
+ "",
+ "My roll now is 5 6. Normally, I would use that roll to move from",
+ "position 24 to position 13 (24-18-13), but your new point prevents",
+ "that. Instead, I am forced to move from 13 to 2, where my man is",
+ "open but cannot be hit.",
+ 0
+};
+
+char *text3[] = {
+ "As you can see, although you left a man open, it is a rela-",
+ "tively safe move to an advantageous position, which might help",
+ "you make a point later. Only two rolls (4 5 or 5 4) will allow",
+ "me to hit you. With an unprecedented amount of luck, I happen",
+ "to roll a 4 5 and hit you as just mentioned.",
+ 0
+};
+
+char *text4[] = {
+ "You're pretty lucky yourself, you know. I follow by rolling 2 3",
+ "and moving 25-22,24-22, forming a new point.",
+ 0
+};
+
+char *text5[] = {
+ "Not a spectacular move, but a safe one. I follow by rolling 6 1.",
+ "I decide to use this roll to move 22-16,16-17. It leaves me with",
+ "one man still open, but the blot is farther back on the board, and",
+ "would suffer less of a loss by being hit.",
+ 0
+};
+
+char *text6[] = {
+ "By moving your two men from 17 to 20, you lessen my chance of",
+ "getting my man off the board. In fact, the odds are 5 to 4",
+ "against me getting off. I roll with the odds and helplessly",
+ "receive a 3 5.",
+ 0
+};
+
+char *text7[] = {
+ "Note that the blot on 7 cannot be hit unless I get off the bar",
+ "and have a 1 or a 6 left over, and doing so will leave two of",
+ "my men open. Also, the blot on 16 cannot be hit at all! With",
+ "a sigh of frustration, I roll double 6's and remain immobile.",
+ 0
+};
+
+char *text8[] = {
+ "See, you did not get hit and, you got to 'cover up' your open men.",
+ "Quite an accomplishment. Finally, I get off the bar by rolling",
+ "6 2 and moving 25-23,23-17.",
+ 0
+};
+
+char *text9[] = {
+ "My venture off the bar did not last long. However, I got lucky",
+ "and rolled double 1's, allowing me to move 0-1,1-2,15-14,15-14.",
+ 0
+};
+
+char *text10[] = {
+ "You are improving your position greatly and safely, and are well",
+ "on the way to winning the game. I roll a 6 2 and squeak past",
+ "your back man. Now the game becomes a race to the finish.",
+ 0
+};
+
+char *text11[] = {
+ "Now that it is merely a race, you are trying to get as many men",
+ "as possible into the inner table, so you can start removing them.",
+ "I roll a 3 4 and move my two men farthest back to position 11",
+ "(15-11,14-11).",
+ 0
+};
+
+char *text12[] = {
+ "The race is still on, and you have seem to be doing all right.",
+ "I roll 6 1 and move 14-8,13-12.",
+ 0
+};
+
+char *text13[] = {
+ "Notice that you get to remove men the instant you have all of",
+ "them at your inner table, even if it is the middle of a turn.",
+ "I roll 1 2 and move 13-11,12-11.",
+ 0
+};
+
+char *text14[] = {
+ "Although you could have removed a man, this move illustrates two",
+ "points: 1) You never have to remove men, and 2) You should try",
+ "to spread out your men on your inner table. Since you have one",
+ "man on each position, you should be able to remove at least two",
+ "men next turn. I roll 2 5 and move 8-6,11-6.",
+ 0
+};
+
+char *text15[] = {
+ "This time you were able to remove men. I roll 3 4 and move",
+ "11-7,11-8. The race continues.",
+ 0
+};
+
+char *text16[] = {
+ "More holes are opening up in your inner table, but you are",
+ "still very much ahead. If we were doubling, you would have",
+ "doubled long ago. I roll 2 6 and move 8-6,11-5.",
+ 0
+};
+
+char *text17[] = {
+ "It pays to spread out your men. I roll 3 5 and move 7-4,8-3.",
+ 0
+};
+
+char *text18[] = {
+ "You can only remove some men, but you spread out more and",
+ "more, in order to be able to remove men more efficiently.",
+ "I roll double 3's, which help, but not that much. I move",
+ "8-5,3-0,3-0,3-0.",
+ 0
+};
+
+char *text19[] = {
+ "I roll 1 4 and move 5-4,4-0.",
+ 0
+};
+
+char *text20[] = {
+ "You are now nicely spread out to win a game. I roll 5 6 and",
+ "move 5-0,6-0.",
+ 0
+};
+
+char *text21[] = {
+ "Any minute now. Just a few short steps from victory. I roll",
+ "2 4 and move 6-4,4-0.",
+ 0
+};
+
+char *text22[] = {
+ "It looks pretty hopeless for me, but I play on, rolling 1 3 and",
+ "moving 4-3,3-0.",
+ 0
+};
+
+char *text23[] = {
+ "Congratulations! You just won a game of backgammon against the",
+ "computer! You will now be able to play a game, but remember,",
+ "when you start playing, that doubling will be enabled, which",
+ "will add another factor to the game... Good luck!!",
+ "",
+ 0
+};
+
+struct situatn test[] = {
+ {
+ {0,2,0,0,0,0,-5,0,-3,0,0,0,5,-5,0,0,0,3,0,5,0,0,0,0,-2,0},
+ 3, 1, {8,6,0,0}, {5,5,0,0}, 4, 2, text0
+ },
+ {
+ {0,2,0,0,0,-2,-4,0,-2,0,0,0,5,-5,0,0,0,2,0,4,0,2,0,0,-2,0},
+ 5, 5, {13,13,8,8}, {8,8,3,3}, 6, 6, text1
+ },
+ {
+ {0,0,0,-2,0,-2,-4,2,-2,0,0,0,3,-3,0,0,0,2,2,4,0,2,0,0,-2,0},
+ 6, 5, {13,8,0,0}, {8,2,0,0}, 1, 2, text2
+ },
+ {
+ {0,0,-1,-2,0,-2,-4,2,-2,0,0,0,2,-2,0,1,0,2,2,4,0,2,0,0,-2,0},
+ 4, 5, {24,20,0,0}, {20,15,0,0}, 2, 5, text3
+ },
+ {
+ {0,0,0,-2,0,-2,-4,3,-2,0,0,0,2,-2,0,-1,0,2,2,4,0,2,0,0,-1,-1},
+ 2, 3, {25,24,0,0}, {22,22,0,0}, 4, 1, text4
+ },
+ {
+ {0,0,0,-2,0,-2,-4,2,-2,0,0,0,3,-2,0,-1,0,2,2,4,0,2,-2,0,0,0},
+ 6, 1, {22,16,0,0}, {16,15,0,0}, 3, 3, text5
+ },
+ {
+ {0,0,0,-2,0,-2,-4,2,-2,0,0,0,3,-2,0,-2,0,0,2,2,2,2,2,0,0,-1},
+ 3, 5, {0,0,0,0}, {0,0,0,0}, 5, 4, text6
+ },
+ {
+ {0,0,0,-2,0,-2,-4,1,-2,0,0,0,3,-2,0,-2,1,0,2,2,2,2,2,0,0,-1},
+ 6, 6, {0,0,0,0}, {0,0,0,0}, 3, 6, text7
+ },
+ {
+ {0,0,0,-2,0,-2,-4,0,-2,0,0,0,3,-2,0,-2,2,0,2,2,2,2,2,0,0,-1},
+ 2, 6, {25,23,0,0}, {23,17,0,0}, 5, 1, text8
+ },
+ {
+ {0,0,0,-2,0,-2,-4,0,-2,0,0,0,2,-2,0,-2,2,0,3,2,2,2,2,0,0,-1},
+ 1, 1, {25,24,15,15}, {24,23,14,14}, 4, 6, text9
+ },
+ {
+ {0,0,0,-2,0,-2,-4,0,-2,0,0,0,0,-2,-2,0,3,0,4,2,2,2,2,-1,0,0},
+ 6, 2, {23,17,0,0}, {17,15,0,0}, 1, 3, text10
+ },
+ {
+ {0,0,0,-2,0,-2,-4,0,-2,0,0,0,0,-2,-2,-1,2,0,3,4,2,2,2,0,0,0},
+ 4, 3, {15,14,0,0}, {11,11,0,0}, 5, 3, text11
+ },
+ {
+ {0,0,0,-2,0,-2,-4,0,-2,0,0,-2,0,-2,-1,0,0,0,3,5,2,3,2,0,0,0},
+ 6, 1, {14,13,0,0}, {8,12,0,0}, 4, 4, text12
+ },
+ {
+ {0,0,0,-2,0,-2,-4,0,-3,0,0,-2,-1,-1,0,0,0,0,0,5,2,2,5,0,0,0},
+ 2, 1, {13,12,0,0}, {11,11,0,0}, 2, 1, text13
+ },
+ {
+ {0,0,0,-2,0,-2,-4,0,-3,0,0,-4,0,0,0,0,0,0,0,5,2,2,3,1,1,0},
+ 2, 5, {8,11,0,0}, {6,6,0,0}, 6, 3, text14
+ },
+ {
+ {0,0,0,-2,0,-2,-6,0,-2,0,0,-3,0,0,0,0,0,0,0,4,2,2,2,1,1,0},
+ 4, 3, {11,11,0,0}, {7,8,0,0}, 2, 5, text15
+ },
+ {
+ {0,0,0,-2,0,-2,-6,-1,-3,0,0,-1,0,0,0,0,0,0,0,4,1,2,2,0,1,0},
+ 2, 6, {8,11,0,0}, {6,5,0,0}, 6, 1, text16
+ },
+ {
+ {0,0,0,-2,0,-3,-7,-1,-2,0,0,0,0,0,0,0,0,0,0,3,1,2,2,0,0,0},
+ 5, 3, {8,7,0,0}, {3,4,0,0}, 5, 2, text17
+ },
+ {
+ {0,0,0,-3,-1,-3,-7,0,-1,0,0,0,0,0,0,0,0,0,0,3,0,1,2,1,0,0},
+ 3, 3, {8,3,3,3}, {5,0,0,0}, 1, 6, text18
+ },
+ {
+ {0,0,0,0,-1,-4,-7,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,1,0,0},
+ 1, 4, {4,5,0,0}, {0,4,0,0}, 2, 3, text19
+ },
+ {
+ {0,0,0,0,-1,-3,-7,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0},
+ 5, 6, {6,5,0,0}, {0,0,0,0}, 1, 4, text20
+ },
+ {
+ {0,0,0,0,-1,-2,-6,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0},
+ 2, 4, {4,6,0,0}, {0,4,0,0}, 6, 2, text21
+ },
+ {
+ {0,0,0,0,-1,-2,-5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0},
+ 3, 1, {4,3,0,0}, {3,0,0,0}, 4, 3, text22
+ },
+ {
+ {0,0,0,0,0,-2,-5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+ 0, 0, {0,0,0,0}, {0,0,0,0}, 0, 0, text23
+ }
+};
diff --git a/games/backgammon/teachgammon/teach.c b/games/backgammon/teachgammon/teach.c
new file mode 100644
index 00000000000..3eaf273970a
--- /dev/null
+++ b/games/backgammon/teachgammon/teach.c
@@ -0,0 +1,170 @@
+/* $NetBSD: teach.c,v 1.4 1995/04/29 00:44:18 mycroft Exp $ */
+
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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 University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)teach.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: teach.c,v 1.4 1995/04/29 00:44:18 mycroft Exp $";
+#endif
+#endif /* not lint */
+
+#include "back.h"
+
+char *hello[];
+char *list[];
+char *intro1[];
+char *intro2[];
+char *moves[];
+char *remove[];
+char *hits[];
+char *endgame[];
+char *doubl[];
+char *stragy[];
+char *prog[];
+char *lastch[];
+
+extern speed_t ospeed; /* tty output speed for termlib */
+
+char *helpm[] = {
+ "\nEnter a space or newline to roll, or",
+ " b to display the board",
+ " d to double",
+ " q to quit\n",
+ 0
+};
+
+char *contin[] = {
+ "",
+ 0
+};
+
+main (argc,argv)
+int argc;
+char **argv;
+
+{
+ register int i;
+
+ signal (2,getout);
+ if (tcgetattr (0, &old) == -1) /* get old tty mode */
+ errexit ("teachgammon(gtty)");
+ noech = old;
+ noech.c_lflag &= ~ECHO;
+ raw = noech;
+ raw.c_lflag &= ~ICANON; /* set up modes */
+ ospeed = cfgetospeed (&old); /* for termlib */
+ tflag = getcaps (getenv ("TERM"));
+#ifdef V7
+ while (*++argv != 0)
+#else
+ while (*++argv != -1)
+#endif
+ getarg (&argv);
+ if (tflag) {
+ noech.c_oflag &= ~(ONLCR|OXTABS);
+ raw.c_oflag &= ~(ONLCR|OXTABS);
+ clear();
+ }
+ text (hello);
+ text (list);
+ i = text (contin);
+ if (i == 0)
+ i = 2;
+ init();
+ while (i)
+ switch (i) {
+
+ case 1:
+ leave();
+
+ case 2:
+ if (i = text(intro1))
+ break;
+ wrboard();
+ if (i = text(intro2))
+ break;
+
+ case 3:
+ if (i = text(moves))
+ break;
+
+ case 4:
+ if (i = text(remove))
+ break;
+
+ case 5:
+ if (i = text(hits))
+ break;
+
+ case 6:
+ if (i = text(endgame))
+ break;
+
+ case 7:
+ if (i = text(doubl))
+ break;
+
+ case 8:
+ if (i = text(stragy))
+ break;
+
+ case 9:
+ if (i = text(prog))
+ break;
+
+ case 10:
+ if (i = text(lastch))
+ break;
+ }
+ tutor();
+}
+
+leave() {
+ if (tflag)
+ clear();
+ else
+ writec ('\n');
+ fixtty(&old);
+ execl (EXEC,"backgammon",args,"n",0);
+ writel ("Help! Backgammon program is missing\007!!\n");
+ exit (-1);
+}
diff --git a/games/backgammon/teachgammon/ttext1.c b/games/backgammon/teachgammon/ttext1.c
new file mode 100644
index 00000000000..100b5e45ec8
--- /dev/null
+++ b/games/backgammon/teachgammon/ttext1.c
@@ -0,0 +1,190 @@
+/* $NetBSD: ttext1.c,v 1.3 1995/03/21 15:06:17 cgd Exp $ */
+
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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 University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)ttext1.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: ttext1.c,v 1.3 1995/03/21 15:06:17 cgd Exp $";
+#endif
+#endif /* not lint */
+
+#include "back.h"
+
+char *opts = " QIMRHEDSPT";
+char *prompt = "-->";
+
+char *list[] = {
+ "\n\n\tI\tIntroduction to Backgammon",
+ "\tM\tMoves and Points",
+ "\tR\tRemoving Men from the Board",
+ "\tH\tHitting Blots",
+ "\tE\tEnding the Game and Scoring",
+ "\tD\tDoubling",
+ "\tS\tStrategy",
+ "\tP\tThe Program and How to Use It",
+ "\nalso, you can type:",
+ "\t?\tto get this list",
+ "\tQ\tto go start playing",
+ "\tT\tto go straight to the tutorial",
+ 0
+};
+
+char *hello[] = {
+ "\n\032 These rules consist of text describing how to play Backgammon",
+ "followed by a tutorial session where you play a practice game",
+ "against the computer. When using this program, think carefuly",
+ "before typing, since it reacts as soon as you type something. In",
+ "addition, the program presents text output, such as these rules,",
+ "in small blocks that will not roll off the top of the screen.",
+ "Frequently, you will see the characters '-->' indicating that the",
+ "program is waiting for you to finish reading, and will continue",
+ "printing when you type a space or newline. Also, the rules are",
+ "divided into sections, and although you should read them in or-",
+ "der, you can go directly to any of them by typing one of the fol-",
+ "lowing letters:",
+ "(Remember to hit a space or a newline to continue.)",
+ "",
+ 0
+};
+
+char *intro1[] = {
+ "\nIntroduction:",
+ "\n Backgammon is a game involving the skill of two players and",
+ "the luck of two dice. There are two players, red and white, and",
+ "each player gets fifteen men. The object of the game is to re-",
+ "move all your men from the board before the opponent does. The",
+ "board consists of twenty-four positions, a 'bar' and a 'home' for",
+ "each player. It looks like this:",
+ "",
+ 0};
+
+char *intro2[] = {
+ "",
+ "\n Although not indicated on the board, the players' homes are",
+ "located just to the right of the board. A player's men are placed",
+ "there when they are removed from the board. The board you just",
+ "saw was in it's initial position. All games start with the board",
+ "looking like this. Notice that red's pieces are represented by the",
+ "letter 'r' and white's pieces are represented by the letter 'w'.",
+ "Also, a position may have zero or more pieces on it, e.g. posi-",
+ "tion 12 has five red pieces on it, while position 11 does not",
+ "have any pieces of either color.",
+ "",
+ 0};
+
+char *moves[] = {
+ "\nMoves and Points:",
+ "\n Moves are made along the positions on the board according to",
+ "their numbers. Red moves in the positive direction (clockwise",
+ "from 1 to 24), and white moves in the negative direction (coun-",
+ "terclockwise from 24 to 1).",
+ "\n A turn consists of rolling the dice, and moving the number of",
+ "positions indicated on each die. The two numbers can be used to",
+ "move one man the sum of the two rolls, or two men the number on",
+ "each individual die. For example, if red rolled 6 3 at the start",
+ "of the game, he might move a man from 1 to 7 to 10, using both",
+ "dice for one man, or he might move two men from position 12, one",
+ "to 15 and one to 18. (Red did not have to choose two men start-",
+ "ing from the same position.) In addition, doubles are treated",
+ "specially in backgammon. When a player rolls doubles, he gets to",
+ "move as if he had four dice instead of two. For instance, if you",
+ "rolled double 2's, you could move one man eight positions, four",
+ "men two positions each, or any permutation in between.",
+ "",
+ "\n However, there are certain limitations, called 'points.' A",
+ "player has a point when he has two or more men on the same posi-",
+ "tion. This gives him custody of that position, and his opponent",
+ "cannot place his men there, even if passing through on the way to",
+ "another position. When a player has six points in a row, it is",
+ "called a 'wall,' since any of his opponent's men behind the wall",
+ "cannot pass it and are trapped, at least for the moment. Notice",
+ "that this could mean that a player could not use part or all of",
+ "his roll. However, he must use as much of his roll as possible.",
+ "",
+ 0};
+
+char *remove[] = {
+ "\nRemoving Men from the Board:",
+ "\n The most important part of the game is removing men, since",
+ "that is how you win the game. Once a man is removed, he stays",
+ "off the board for the duration of the game. However, a player",
+ "cannot remove men until all his men are on his 'inner table,' or",
+ "the last six positions of the board (19-24 for red, 6-1 for",
+ "white).",
+ "\n To get off the board, a player must roll the exact number to",
+ "get his man one position past the last position on the board, or",
+ "his 'home.' Hence, if red wanted to remove a man from position",
+ "23, he would have to roll a 2, anything else would be used for",
+ "another man, or for another purpose. However, there is one ex-",
+ "ception. If the player rolling has no men far enough to move the",
+ "roll made, he may move his farthest man off the board. For exam-",
+ "ple, if red's farthest man back was on position 21, he could re-",
+ "move men from that position if he rolled a 5 or a 6, as well as a",
+ "4. Since he does not have men on 20 (where he could use a 5) or",
+ "on 19 (where he could use a 6), he can use these rolls for posi-",
+ "tion 21. A player never has to remove men, but he must make as",
+ "many moves as possible.",
+ "",
+ 0};
+
+char *hits[] = {
+ "\nHitting Blots:",
+ "\n Although two men on a position form an impenetrable point, a",
+ "lone man is not so secure. Such a man is called a 'blot' and has",
+ "the potential of getting hit by an opposing man. When a player's",
+ "blot is hit, he is placed on the bar, and the first thing that",
+ "player must do is move the man off the bar. Such moves are",
+ "counted as if the bar is one position behind the first position",
+ "on the board. Thus if red has a man on the bar and rolls 2 3, he",
+ "must move the man on the bar to position 2 or 3 before moving any",
+ "other man. If white had points on positions 2 and 3, then red",
+ "would forfeit his turn. Being on the bar is a very bad position,",
+ "for often a player can lose many turns trying to move off the",
+ "bar, as well as being set back the full distance of the board.",
+ "",
+ 0};
+
+char *endgame[] = {
+ "\nEnding the Game and Scoring:",
+ "\n Winning a game usually wins one point, the normal value of a",
+ "game. However, if the losing player has not removed any men yet,",
+ "then the winning player wins double the game value, called a",
+ "'gammon.' If the losing player has a player on the bar or on the",
+ "winner's inner table, then the winner gets triple the game value,",
+ "which is called a 'backgammon.' (So that's where the name comes",
+ "from!)",
+ "",
+ 0};
diff --git a/games/backgammon/teachgammon/ttext2.c b/games/backgammon/teachgammon/ttext2.c
new file mode 100644
index 00000000000..afb431c171f
--- /dev/null
+++ b/games/backgammon/teachgammon/ttext2.c
@@ -0,0 +1,199 @@
+/* $NetBSD: ttext2.c,v 1.4 1995/04/29 00:44:20 mycroft Exp $ */
+
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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 University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)ttext2.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: ttext2.c,v 1.4 1995/04/29 00:44:20 mycroft Exp $";
+#endif
+#endif /* not lint */
+
+#include "back.h"
+
+char *prompt, *list, *opts;
+
+char *doubl[] = {
+ "\nDoubling:",
+ "\n If a player thinks he is in a good position, he may double the",
+ "value of the game. However, his opponent may not accept the pro-",
+ "posal and forfeit the game before the price gets too high. A",
+ "player must double before he rolls, and once his double has been",
+ "accepted, he cannot double again, until his opponent has doubled.",
+ "Thus, unless the game swings back and forth in advantage between",
+ "the two players a great deal, the value of the game should be",
+ "low. At any rate, the value of the game will never go above 64,",
+ "or six doubles. However, if a player wins a backgammon at 64",
+ "points, he wins 192 points!",
+ "",
+ 0};
+
+char *stragy[] = {
+ "\nStrategy:",
+ "\n Some general hints when playing: Try not to leave men open",
+ "unless absolutely necessary. Also, it is good to make as many",
+ "points as possible. Often, two men from different positions can",
+ "be brought together to form a new point. Although walls (six",
+ "points in a row) are difficult to form, many points nestled close-",
+ "ly together produce a formidable barrier. Also, while it is good",
+ "to move back men forward, doing so lessens the opportunity for you",
+ "to hit men. Finally, remember that once the two player's have",
+ "passed each other on the board, there is no chance of either team",
+ "being hit, so the game reduces to a race off the board. Addi-",
+ "tional hints on strategy are presented in the practice game.",
+ "",
+ 0};
+
+char *prog[] = {
+ "\nThe Program and How It Works:",
+ "\n A general rule of thumb is when you don't know what to do,",
+ "type a question mark, and you should get some help. When it is",
+ "your turn, only your color will be printed out, with nothing",
+ "after it. You may double by typing a 'd', but if you type a",
+ "space or newline, you will get your roll. (Remember, you must",
+ "double before you roll.) Also, typing a 'r' will reprint the",
+ "board, and a 'q' will quit the game. The program will type",
+ "'Move:' when it wants your move, and you may indicate each die's",
+ "move with <s>-<f>, where <s> is the starting position and <f> is",
+ "the finishing position, or <s>/<r> where <r> is the roll made.",
+ "<s>-<f1>-<f2> is short for <s>-<f1>,<f1>-<f2> and <s>/<r1><r2> is",
+ "short for <s>/<r1>,<s>/<r2>. Moves may be separated by a comma",
+ "or a space.",
+ "",
+ "\n While typing, any input which does not make sense will not be",
+ "echoed, and a bell will sound instead. Also, backspacing and",
+ "killing lines will echo differently than normal. You may examine",
+ "the board by typing a 'r' if you have made a partial move, or be-",
+ "fore you type a newline, to see what the board looks like. You",
+ "must end your move with a newline. If you cannot double, your",
+ "roll will always be printed, and you will not be given the oppor-",
+ "tunity to double. Home and bar are represented by the appropri-",
+ "ate number, 0 or 25 as the case may be, or by the letters 'h' or",
+ "'b' as appropriate. You may also type 'r' or 'q' when the program",
+ "types 'Move:', which has the same effect as above. Finally, you",
+ "will get to decide if you want to play red or white (or both if you",
+ "want to play a friend) at the beginning of the session, and you",
+ "will not get to change your mind later, since the computer keeps",
+ "score.",
+ "",
+ 0};
+
+char *lastch[] = {
+ "\nTutorial (Practice Game):",
+ "\n This tutorial, for simplicity's sake, will let you play one",
+ "predetermined game. All the rolls have been pre-arranged, and",
+ "only one response will let you advance to the next move.",
+ "Although a given roll will may have several legal moves, the tu-",
+ "torial will only accept one (not including the same moves in a",
+ "different order), claiming that that move is 'best.' Obviously,",
+ "a subjective statement. At any rate, be patient with it and have",
+ "fun learning about backgammon. Also, to speed things up a lit-",
+ "tle, doubling will not take place in the tutorial, so you will",
+ "never get that opportunity, and quitting only leaves the tutori-",
+ "al, not the game. You will still be able to play backgammon",
+ "after quitting.",
+ "\n This is your last chance to look over the rules before the tu-",
+ "torial starts.",
+ "",
+ 0};
+
+text (txt)
+char **txt;
+
+{
+ char **begin;
+ char *a;
+ char b;
+ char *c;
+ int i;
+
+ fixtty (&noech);
+ begin = txt;
+ while (*txt) {
+ a = *(txt++);
+ if (*a != '\0') {
+ c = a;
+ for (i = 0; *(c++) != '\0'; i--);
+ writel (a);
+ writec ('\n');
+ } else {
+ fixtty (&raw);
+ writel (prompt);
+ for (;;) {
+ if ((b = readc()) == '?') {
+ if (tflag) {
+ if (begscr) {
+ curmove (18,0);
+ clend();
+ } else
+ clear();
+ } else
+ writec ('\n');
+ text (list);
+ writel (prompt);
+ continue;
+ }
+ i = 0;
+ if (b == '\n')
+ break;
+ while (i < 11) {
+ if (b == opts[i])
+ break;
+ i++;
+ }
+ if (i == 11)
+ writec ('\007');
+ else
+ break;
+ }
+ if (tflag) {
+ if (begscr) {
+ curmove (18,0);
+ clend();
+ } else
+ clear();
+ } else
+ writec ('\n');
+ if (i)
+ return(i);
+ fixtty (&noech);
+ if (tflag)
+ curmove (curr,0);
+ begin = txt;
+ }
+ }
+ fixtty (&raw);
+ return (0);
+}
diff --git a/games/backgammon/teachgammon/tutor.c b/games/backgammon/teachgammon/tutor.c
new file mode 100644
index 00000000000..497191ee375
--- /dev/null
+++ b/games/backgammon/teachgammon/tutor.c
@@ -0,0 +1,161 @@
+/* $NetBSD: tutor.c,v 1.3 1995/03/21 15:06:27 cgd Exp $ */
+
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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 University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)tutor.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: tutor.c,v 1.3 1995/03/21 15:06:27 cgd Exp $";
+#endif
+#endif /* not lint */
+
+#include "back.h"
+#include "tutor.h"
+
+extern int maxmoves;
+extern char *finis[];
+
+extern struct situatn test[];
+
+static char better[] = "That is a legal move, but there is a better one.\n";
+
+tutor () {
+ register int i, j;
+
+ i = 0;
+ begscr = 18;
+ cturn = -1;
+ home = 0;
+ bar = 25;
+ inptr = &in[0];
+ inopp = &in[1];
+ offptr = &off[0];
+ offopp = &off[1];
+ Colorptr = &color[0];
+ colorptr = &color[2];
+ colen = 5;
+ wrboard();
+
+ while (1) {
+ if (! brdeq(test[i].brd,board)) {
+ if (tflag && curr == 23)
+ curmove (18,0);
+ writel (better);
+ nexturn();
+ movback (mvlim);
+ if (tflag) {
+ refresh();
+ clrest ();
+ }
+ if ((! tflag) || curr == 19) {
+ proll();
+ writec ('\t');
+ }
+ else
+ curmove (curr > 19? curr-2: curr+4,25);
+ getmove();
+ if (cturn == 0)
+ leave();
+ continue;
+ }
+ if (tflag)
+ curmove (18,0);
+ text (*test[i].com);
+ if (! tflag)
+ writec ('\n');
+ if (i == maxmoves)
+ break;
+ D0 = test[i].roll1;
+ D1 = test[i].roll2;
+ d0 = 0;
+ mvlim = 0;
+ for (j = 0; j < 4; j++) {
+ if (test[i].mp[j] == test[i].mg[j])
+ break;
+ p[j] = test[i].mp[j];
+ g[j] = test[i].mg[j];
+ mvlim++;
+ }
+ if (mvlim)
+ for (j = 0; j < mvlim; j++)
+ if (makmove(j))
+ writel ("AARGH!!!\n");
+ if (tflag)
+ refresh();
+ nexturn();
+ D0 = test[i].new1;
+ D1 = test[i].new2;
+ d0 = 0;
+ i++;
+ mvlim = movallow();
+ if (mvlim) {
+ if (tflag)
+ clrest();
+ proll();
+ writec('\t');
+ getmove();
+ if (tflag)
+ refresh();
+ if (cturn == 0)
+ leave();
+ }
+ }
+ leave();
+}
+
+clrest () {
+ register int r, c, j;
+
+ r = curr;
+ c = curc;
+ for (j = r+1; j < 24; j++) {
+ curmove (j,0);
+ cline();
+ }
+ curmove (r,c);
+}
+
+brdeq (b1,b2)
+register int *b1, *b2;
+
+{
+ register int *e;
+
+ e = b1+26;
+ while (b1 < e)
+ if (*b1++ != *b2++)
+ return(0);
+ return(1);
+}
diff --git a/games/backgammon/teachgammon/tutor.h b/games/backgammon/teachgammon/tutor.h
new file mode 100644
index 00000000000..bfafd43fa07
--- /dev/null
+++ b/games/backgammon/teachgammon/tutor.h
@@ -0,0 +1,47 @@
+/* $NetBSD: tutor.h,v 1.3 1995/03/21 15:06:30 cgd Exp $ */
+
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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 University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ *
+ * @(#)tutor.h 8.1 (Berkeley) 5/31/93
+ */
+
+struct situatn {
+ int brd[26];
+ int roll1;
+ int roll2;
+ int mp[4];
+ int mg[4];
+ int new1;
+ int new2;
+ char *(*com[8]);
+};