Initial revision

git-svn-id: file:///srv/svn/joey/bsdgames-trunk@5086 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
joey
1999-09-08 23:56:51 +00:00
commit 03272d67da
623 changed files with 243457 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
# $NetBSD: Makefile,v 1.8 1997/10/10 08:59:50 lukem Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= teachgammon
SRCS= data.c teach.c ttext1.c ttext2.c tutor.c
NOMAN= noman
.include <bsd.prog.mk>

View File

@@ -0,0 +1,12 @@
# Makefrag - makefile fragment for backgammon/teachgammon
backgammon_teachgammon_DEFS := -DV7
backgammon_teachgammon_DIRS := $(GAMESDIR) $(MAN6DIR)
backgammon_teachgammon_INCS := -Ibackgammon/common_source
backgammon_teachgammon_all: backgammon/teachgammon/teachgammon
backgammon_teachgammon_install: backgammon_teachgammon_all
$(INSTALL_BINARY) backgammon/teachgammon/teachgammon $(INSTALL_PREFIX)$(GAMESDIR)/teachgammon
$(HIDE_GAME) teachgammon
$(INSTALL_MANUAL) backgammon.6 teachgammon.6

View File

@@ -0,0 +1,346 @@
/* $NetBSD: data.c,v 1.4 1997/10/10 08:59:51 lukem 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)data.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: data.c,v 1.4 1997/10/10 08:59:51 lukem Exp $");
#endif
#endif /* not lint */
#include "tutor.h"
int maxmoves = 23;
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const 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
};
const char *const text15[] = {
"This time you were able to remove men. I roll 3 4 and move",
"11-7,11-8. The race continues.",
0
};
const char *const 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
};
const char *const text17[] = {
"It pays to spread out your men. I roll 3 5 and move 7-4,8-3.",
0
};
const char *const 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
};
const char *const text19[] = {
"I roll 1 4 and move 5-4,4-0.",
0
};
const char *const text20[] = {
"You are now nicely spread out to win a game. I roll 5 6 and",
"move 5-0,6-0.",
0
};
const char *const text21[] = {
"Any minute now. Just a few short steps from victory. I roll",
"2 4 and move 6-4,4-0.",
0
};
const char *const text22[] = {
"It looks pretty hopeless for me, but I play on, rolling 1 3 and",
"moving 4-3,3-0.",
0
};
const char *const 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
};
const 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}
}
};

View File

@@ -0,0 +1,166 @@
/* $NetBSD: teach.c,v 1.6 1998/08/29 22:53:04 hubertf 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__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
__RCSID("$NetBSD: teach.c,v 1.6 1998/08/29 22:53:04 hubertf Exp $");
#endif
#endif /* not lint */
#include "back.h"
#include "tutor.h"
#ifndef NCURSES_VERSION
extern speed_t ospeed; /* tty output speed for termlib */
#endif
const char *const helpm[] = {
"\nEnter a space or newline to roll, or",
" b to display the board",
" d to double",
" q to quit\n",
0
};
const char *const contin[] = {
"",
0
};
int
main(argc, argv)
int argc __attribute__((unused));
char *argv[];
{
int i;
/* revoke setgid privileges */
setregid(getgid(), getgid());
signal(SIGINT, getout);
if (tcgetattr(0, &old) == -1) /* get old tty mode */
errexit("teachgammon(gtty)");
noech = old;
noech.c_lflag &= ~ECHO;
bg_raw = noech;
bg_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);
bg_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)) != 0)
break;
wrboard();
if ((i = text(intro2)) != 0)
break;
case 3:
if ((i = text(moves)) != 0)
break;
case 4:
if ((i = text(removepiece)) != 0)
break;
case 5:
if ((i = text(hits)) != 0)
break;
case 6:
if ((i = text(endgame)) != 0)
break;
case 7:
if ((i = text(doubl)) != 0)
break;
case 8:
if ((i = text(stragy)) != 0)
break;
case 9:
if ((i = text(prog)) != 0)
break;
case 10:
if ((i = text(lastch)) != 0)
break;
}
tutor();
/* NOTREACHED */
return (0);
}
void
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);
}

View File

@@ -0,0 +1,192 @@
/* $NetBSD: ttext1.c,v 1.4 1997/10/10 08:59:53 lukem 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)ttext1.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: ttext1.c,v 1.4 1997/10/10 08:59:53 lukem Exp $");
#endif
#endif /* not lint */
#include "back.h"
#include "tutor.h"
const char *opts = " QIMRHEDSPT";
const char *prompt = "-->";
const char *const 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
};
const char *const hello[] = {
"\n 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
};
const char *const 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};
const char *const 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};
const char *const 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};
const char *const removepiece[] = {
"\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};
const char *const 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};
const char *const 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};

View File

@@ -0,0 +1,200 @@
/* $NetBSD: ttext2.c,v 1.5 1997/10/10 08:59:53 lukem 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)ttext2.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: ttext2.c,v 1.5 1997/10/10 08:59:53 lukem Exp $");
#endif
#endif /* not lint */
#include "back.h"
#include "tutor.h"
const char *const 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};
const char *const 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};
const char *const 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};
const char *const 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};
int
text(txt)
const char *const *txt;
{
const char *const *begin;
const char *a;
char b;
const 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(&bg_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(&bg_raw);
return (0);
}

View File

@@ -0,0 +1,160 @@
/* $NetBSD: tutor.c,v 1.4 1997/10/10 08:59:54 lukem 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)tutor.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: tutor.c,v 1.4 1997/10/10 08:59:54 lukem Exp $");
#endif
#endif /* not lint */
#include "back.h"
#include "tutor.h"
static const char better[] = "That is a legal move, but there is a better one.\n";
void
tutor()
{
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();
}
void
clrest()
{
int r, c, j;
r = curr;
c = curc;
for (j = r + 1; j < 24; j++) {
curmove(j, 0);
cline();
}
curmove(r, c);
}
int
brdeq(b1, b2)
const int *b1, *b2;
{
const int *e;
e = b1 + 26;
while (b1 < e)
if (*b1++ != *b2++)
return (0);
return (1);
}

View File

@@ -0,0 +1,72 @@
/* $NetBSD: tutor.h,v 1.5 1998/09/13 15:27:26 hubertf 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;
const char *const (*com[8]);
};
extern const char *const doubl[];
extern const char *const endgame[];
extern const char *const finis[];
extern const char *const hello[];
extern const char *const hits[];
extern const char *const intro1[];
extern const char *const intro2[];
extern const char *const lastch[];
extern const char *const list[];
extern int maxmoves;
extern const char *const moves[];
extern const char *opts;
extern const char *const prog[];
extern const char *prompt;
extern const char *const removepiece[];
extern const char *const stragy[];
extern const struct situatn test[];
int brdeq __P((const int *, const int *));
void clrest __P((void));
void leave __P((void)) __attribute__((__noreturn__));
void tutor __P((void)) __attribute__((__noreturn__));