mirror of
https://github.com/SEPPDROID/Digital-Research-Source-Code.git
synced 2025-10-27 10:24:19 +00:00
Upload
Digital Research
This commit is contained in:
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* 3D Tic Tac Toe.
|
||||
*/
|
||||
#include "stdio.h"
|
||||
#define EMPTY 0
|
||||
#define PLAYER 1
|
||||
#define BEAST 5
|
||||
|
||||
/*
|
||||
* This is a table of all winning
|
||||
* combinations.
|
||||
* I stole it out of Kilobaud, April
|
||||
* 78.
|
||||
* You can look there to see how it
|
||||
* is ordered.
|
||||
*/
|
||||
char w[] = {
|
||||
0, 1, 2, 3,
|
||||
4, 5, 6, 7,
|
||||
8, 9, 10, 11,
|
||||
12, 13, 14, 15,
|
||||
0, 4, 8, 12,
|
||||
1, 5, 9, 13,
|
||||
2, 6, 10, 14,
|
||||
3, 7, 11, 15,
|
||||
0, 5, 10, 15,
|
||||
3, 6, 9, 12,
|
||||
16, 17, 18, 19,
|
||||
20, 21, 22, 23,
|
||||
24, 25, 26, 27,
|
||||
28, 29, 30, 31,
|
||||
16, 20, 24, 28,
|
||||
17, 21, 25, 29,
|
||||
18, 22, 26, 30,
|
||||
19, 23, 27, 31,
|
||||
16, 21, 26, 31,
|
||||
19, 22, 25, 28,
|
||||
32, 33, 34, 35,
|
||||
36, 37, 38, 39,
|
||||
40, 41, 42, 43,
|
||||
44, 45, 46, 47,
|
||||
32, 36, 40, 44,
|
||||
33, 37, 41, 45,
|
||||
34, 38, 42, 46,
|
||||
35, 39, 43, 47,
|
||||
32, 37, 42, 47,
|
||||
35, 38, 41, 44,
|
||||
48, 49, 50, 51,
|
||||
52, 53, 54, 55,
|
||||
56, 57, 58, 59,
|
||||
60, 61, 62, 63,
|
||||
48, 52, 56, 60,
|
||||
49, 53, 57, 61,
|
||||
50, 54, 58, 62,
|
||||
51, 55, 59, 63,
|
||||
48, 53, 58, 63,
|
||||
51, 54, 57, 60,
|
||||
0, 16, 32, 48,
|
||||
1, 17, 33, 49,
|
||||
2, 18, 34, 50,
|
||||
3, 19, 35, 51,
|
||||
4, 20, 36, 52,
|
||||
5, 21, 37, 53,
|
||||
6, 22, 38, 54,
|
||||
7, 23, 39, 55,
|
||||
8, 24, 40, 56,
|
||||
9, 25, 41, 57,
|
||||
10, 26, 42, 58,
|
||||
11, 27, 43, 59,
|
||||
13, 29, 45, 61,
|
||||
12, 28, 44, 60,
|
||||
14, 30, 46, 62,
|
||||
15, 31, 47, 63,
|
||||
0, 21, 42, 63,
|
||||
4, 21, 38, 55,
|
||||
8, 25, 42, 59,
|
||||
12, 25, 38, 51,
|
||||
1, 21, 41, 61,
|
||||
13, 25, 37, 49,
|
||||
2, 22, 42, 62,
|
||||
14, 26, 38, 50,
|
||||
3, 22, 41, 60,
|
||||
7, 22, 37, 52,
|
||||
11, 26, 41, 56,
|
||||
15, 26, 37, 48,
|
||||
0, 20, 40, 60,
|
||||
0, 17, 34, 51,
|
||||
3, 18, 33, 48,
|
||||
3, 23, 43, 63,
|
||||
12, 24, 36, 48,
|
||||
12, 29, 46, 63,
|
||||
15, 30, 45, 60,
|
||||
15, 27, 39, 51
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the board.
|
||||
* Starts off all empty.
|
||||
*/
|
||||
char b[64];
|
||||
|
||||
char *sep = "----------- ----------- ----------- -----------";
|
||||
|
||||
/*
|
||||
* The mainline is just
|
||||
* a driver.
|
||||
*/
|
||||
main(argc, argv)
|
||||
char *argv[];
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
printf("Do you want the rules? ");
|
||||
gets(buf);
|
||||
if(buf[0]=='Y' || buf[0]=='y')
|
||||
rules();
|
||||
printf("Do you want to go first? ");
|
||||
gets(buf);
|
||||
if(buf[0]=='Y' || buf[0]=='y')
|
||||
user();
|
||||
for(;;) {
|
||||
beast();
|
||||
user();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the rules of the
|
||||
* game.
|
||||
*/
|
||||
rules()
|
||||
{
|
||||
printf("Three dimensional tic-tac-toe is played on a 4x4x4\n");
|
||||
printf("board. To win you must get 4 in a row. Your moves\n");
|
||||
printf("are specified as a 3 digit number; the first digit\n");
|
||||
printf("is the level, the second the row and the third the\n");
|
||||
printf("column. Levels and columns go from left to right\n");
|
||||
printf("from 0 to 3. Rows go from top to bottom with 0 on\n");
|
||||
printf("the top.\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Accept a user move.
|
||||
* Exit if he wins.
|
||||
*/
|
||||
user()
|
||||
{
|
||||
register int i, j, t;
|
||||
char buf[20];
|
||||
|
||||
board();
|
||||
for(;;) {
|
||||
printf("Your move? ");
|
||||
if(gets(buf) == NULL) {
|
||||
printf("Chicken.\n");
|
||||
exit(0);
|
||||
}
|
||||
i = 16*(buf[0]-'0') + (buf[1]-'0') + 4*(buf[2]-'0');
|
||||
if(i>=0 && i<=63 && b[i]==EMPTY)
|
||||
break;
|
||||
printf("Eh?\n");
|
||||
}
|
||||
b[i] = PLAYER;
|
||||
for(i=0; i<4*76; i+=4) {
|
||||
t = 0;
|
||||
for(j=0; j<4; ++j)
|
||||
t += b[w[i+j]];
|
||||
if(t == 4*PLAYER) {
|
||||
printf("You win.\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Display the board.
|
||||
* Not as easy as it sounds.
|
||||
*/
|
||||
board()
|
||||
{
|
||||
register int i, j;
|
||||
|
||||
for(i=0; i<4; ++i) {
|
||||
if(i != 0)
|
||||
puts(sep);
|
||||
for(j=0; j<64; j+=4) {
|
||||
psq(i+j);
|
||||
if(j==12 || j==28 || j==44)
|
||||
putchar(' ');
|
||||
else if(j >= 60)
|
||||
putchar('\n');
|
||||
else
|
||||
putchar('!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Format and put out square
|
||||
* `s' of the board.
|
||||
*/
|
||||
psq(s)
|
||||
{
|
||||
register int v;
|
||||
|
||||
v = b[s];
|
||||
if(v == PLAYER)
|
||||
printf("UU");
|
||||
else if(v == BEAST)
|
||||
printf("CC");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
/*
|
||||
* Move for the machine.
|
||||
* Just exit on machine wins
|
||||
* and draws.
|
||||
*/
|
||||
beast()
|
||||
{
|
||||
register int i, j, t;
|
||||
int s, bs, bt, v[76];
|
||||
|
||||
for(i=0; i<4*76; i+=4) {
|
||||
t = 0;
|
||||
for(j=0; j<4; ++j)
|
||||
t += b[w[i+j]];
|
||||
v[i>>2] = t;
|
||||
if(t == 3*BEAST)
|
||||
break;
|
||||
}
|
||||
if(i < 4*76) {
|
||||
for(j=0; j<4; ++j)
|
||||
if(b[w[i+j]] == EMPTY) {
|
||||
b[w[i+j]] = BEAST;
|
||||
break;
|
||||
}
|
||||
board();
|
||||
printf("I win.\n");
|
||||
exit(0);
|
||||
}
|
||||
bt = 0;
|
||||
for(s=0; s<64; ++s) {
|
||||
if(b[s] != EMPTY)
|
||||
continue;
|
||||
t = 0;
|
||||
for(i=0; i<4*76; i+=4) {
|
||||
for(j=0; j<4; ++j)
|
||||
if(w[i+j] == s)
|
||||
break;
|
||||
if(j != 4) {
|
||||
if(v[i>>2] == 3*PLAYER) {
|
||||
b[s] = BEAST;
|
||||
return;
|
||||
}
|
||||
t += weight(v[i>>2]);
|
||||
}
|
||||
}
|
||||
if(t > bt) {
|
||||
bt = t;
|
||||
bs = s;
|
||||
}
|
||||
}
|
||||
if(bt != 0)
|
||||
b[bs] = BEAST;
|
||||
else {
|
||||
for(s=0; s<64; ++s)
|
||||
if(b[s] == EMPTY)
|
||||
break;
|
||||
if(s == 64) {
|
||||
printf("Draw.\n");
|
||||
exit(0);
|
||||
}
|
||||
b[s] = BEAST;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a total along a winning
|
||||
* combination, return the weight
|
||||
* value.
|
||||
*/
|
||||
weight(at)
|
||||
{
|
||||
register int t;
|
||||
|
||||
t = at;
|
||||
if(t == PLAYER)
|
||||
return(1);
|
||||
if(t == 2*PLAYER)
|
||||
return(4);
|
||||
if(t == BEAST)
|
||||
return(1);
|
||||
if(t == 2*BEAST)
|
||||
return(2);
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
#include "stdio.h"
|
||||
#include "cpm.h"
|
||||
/*
|
||||
* wumpus
|
||||
* stolen from PCC Vol 2 No 1
|
||||
*/
|
||||
|
||||
#define NBAT 3
|
||||
#define NROOM 20
|
||||
#define NTUNN 3
|
||||
#define NPIT 3
|
||||
/* #define BIGINT 2147483648.0 */
|
||||
|
||||
struct room
|
||||
{
|
||||
int tunn[NTUNN];
|
||||
int flag;
|
||||
} room[NROOM] = 0;
|
||||
|
||||
char *intro[] =
|
||||
{
|
||||
"\n",
|
||||
"Welcome to 'Hunt the Wumpus.'\n",
|
||||
"\n",
|
||||
"The Wumpus lives in a cave of %d rooms.\n",
|
||||
"Each room has %d tunnels leading to other rooms.\n",
|
||||
"\n",
|
||||
"Hazards:\n",
|
||||
"\n",
|
||||
"Bottomless Pits - Some rooms have Bottomless Pits in them.\n",
|
||||
" If you go there, you fall into the pit and lose!\n",
|
||||
"Super Bats - Some other rooms have super bats.\n",
|
||||
" If you go there, a bat will grab you and take you to\n",
|
||||
" somewhere else in the cave where you could\n",
|
||||
" fall into a pit or run into the . . .\n",
|
||||
"\n",
|
||||
"Wumpus:\n",
|
||||
"\n",
|
||||
"The Wumpus is not bothered by the hazards since\n",
|
||||
"he has sucker feet and is too big for a bat to lift.\n",
|
||||
"\n",
|
||||
"Usually he is asleep.\n",
|
||||
"Two things wake him up:\n",
|
||||
" your entering his room\n",
|
||||
" your shooting an arrow anywhere in the cave.\n",
|
||||
"If the wumpus wakes, he either decides to move one room or\n",
|
||||
"stay where he was. But if he ends up where you are,\n",
|
||||
"he eats you up and you lose!\n",
|
||||
"\n",
|
||||
"You:\n",
|
||||
"\n",
|
||||
"Each turn you may either move or shoot a crooked arrow.\n",
|
||||
"\n",
|
||||
"Moving - You can move to one of the adjoining rooms;\n",
|
||||
" that is, to one that has a tunnel connecting it with\n",
|
||||
" the room you are in.\n",
|
||||
"\n",
|
||||
"Shooting - You have 5 arrows. You lose when you run out.\n",
|
||||
" Each arrow can go from 1 to 5 rooms.\n",
|
||||
" You aim by telling the computer\n",
|
||||
" The arrow's path is a list of room numbers\n",
|
||||
" telling the arrow which room to go to next.\n",
|
||||
" The list is terminated with a 0.\n",
|
||||
" The first room in the path must be connected to the\n",
|
||||
" room you are in. Each succeeding room must be\n",
|
||||
" connected to the previous room.\n",
|
||||
" If there is no tunnel between two of the rooms\n",
|
||||
" in the arrow's path, the arrow chooses one of the\n",
|
||||
" three tunnels from the room it's in and goes its\n",
|
||||
" own way.\n",
|
||||
"\n",
|
||||
" If the arrow hits the wumpus, you win!\n",
|
||||
" If the arrow hits you, you lose!\n",
|
||||
"\n",
|
||||
"Warnings:\n",
|
||||
"\n",
|
||||
"When you are one or two rooms away from the wumpus,\n",
|
||||
"the computer says:\n",
|
||||
" 'I smell a Wumpus'\n",
|
||||
"When you are one room away from some other hazard, it says:\n",
|
||||
" Bat - 'Bats nearby'\n",
|
||||
" Pit - 'I feel a draft'\n",
|
||||
"\n",
|
||||
0,
|
||||
};
|
||||
|
||||
#define BAT 01
|
||||
#define PIT 02
|
||||
#define WUMP 04
|
||||
|
||||
int arrow = 0;
|
||||
int loc = 0;
|
||||
int wloc = 0;
|
||||
int tchar = 0;
|
||||
|
||||
main()
|
||||
{
|
||||
register i, j;
|
||||
register struct room *p;
|
||||
int k, icomp();
|
||||
|
||||
printf("Instructions? (y-n) ");
|
||||
if(rline() == 'y')
|
||||
for(i=0; intro[i]; i++)
|
||||
printf(intro[i], i&1? NROOM: NTUNN);
|
||||
|
||||
|
||||
/*
|
||||
* initialize the room connections
|
||||
*/
|
||||
|
||||
init:
|
||||
p = &room[0];
|
||||
for(i=0; i<NROOM; i++) {
|
||||
for(j=0; j<NTUNN; j++)
|
||||
p->tunn[j] = -1;
|
||||
p++;
|
||||
}
|
||||
k = 0;
|
||||
for(i=1; i<NROOM; ) {
|
||||
j = rnum(NROOM);
|
||||
p = &room[j];
|
||||
if(j == k || p->tunn[0] >= 0 || p->tunn[1] >= 0)
|
||||
continue;
|
||||
p->tunn[1] = k;
|
||||
room[k].tunn[0] = j;
|
||||
k = j;
|
||||
i++;
|
||||
}
|
||||
p = &room[0];
|
||||
for(i=0; i<NROOM; i++) {
|
||||
for(j=0; j<NTUNN; j++) {
|
||||
if(p->tunn[j] < 0)
|
||||
p->tunn[j] = tunnel(i);
|
||||
if(p->tunn[j] == i)
|
||||
goto init;
|
||||
for(k=0; k<j; k++)
|
||||
if(p->tunn[j] == p->tunn[k])
|
||||
goto init;
|
||||
}
|
||||
qsort(&p->tunn[0], NTUNN, sizeof(p->tunn[0]), icomp);
|
||||
p++;
|
||||
}
|
||||
|
||||
/*
|
||||
* put in player, wumpus,
|
||||
* pits and bats
|
||||
*/
|
||||
|
||||
setup:
|
||||
arrow = 5;
|
||||
p = &room[0];
|
||||
for(i=0; i<NROOM; i++) {
|
||||
p->flag = 0;
|
||||
p++;
|
||||
}
|
||||
for(i=0; i<NPIT; ) {
|
||||
p = &room[rnum(NROOM)];
|
||||
if((p->flag&PIT) == 0) {
|
||||
p->flag |= PIT;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
for(i=0; i<NBAT; ) {
|
||||
p = &room[rnum(NROOM)];
|
||||
if((p->flag&(PIT|BAT)) == 0) {
|
||||
p->flag |= BAT;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
i = rnum(NROOM);
|
||||
wloc = i;
|
||||
room[i].flag |= WUMP;
|
||||
for(;;) {
|
||||
i = rnum(NROOM);
|
||||
if((room[i].flag&(PIT|BAT|WUMP)) == 0) {
|
||||
loc = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* main loop of the game
|
||||
*/
|
||||
|
||||
loop:
|
||||
printf("You are in room %d\n", loc+1);
|
||||
p = &room[loc];
|
||||
if(p->flag&PIT) {
|
||||
printf("You fell into a pit\n");
|
||||
goto done;
|
||||
}
|
||||
if(p->flag&WUMP) {
|
||||
printf("You were eaten by the wumpus\n");
|
||||
goto done;
|
||||
}
|
||||
if(p->flag&BAT) {
|
||||
printf("Theres a bat in your room\n");
|
||||
loc = rnum(NROOM);
|
||||
goto loop;
|
||||
}
|
||||
for(i=0; i<NTUNN; i++)
|
||||
if(near(&room[p->tunn[i]], WUMP))
|
||||
goto nearwump;
|
||||
if (near(p, WUMP)) {
|
||||
nearwump:
|
||||
printf("I smell a wumpus\n");
|
||||
}
|
||||
if (near(p, BAT))
|
||||
printf("Bats nearby\n");
|
||||
if (near(p, PIT))
|
||||
printf("I feel a draft\n");
|
||||
printf("There are tunnels to");
|
||||
for(i=0; i<NTUNN; i++)
|
||||
printf(" %d", p->tunn[i]+1);
|
||||
printf("\n");
|
||||
|
||||
again:
|
||||
printf("Move or shoot (m-s) ");
|
||||
switch(rline()) {
|
||||
case 'm':
|
||||
if(tchar == '\n')
|
||||
printf("which room? ");
|
||||
i = rin()-1;
|
||||
for(j=0; j<NTUNN; j++)
|
||||
if(i == p->tunn[j])
|
||||
goto groom;
|
||||
printf("You hit the wall\n");
|
||||
goto again;
|
||||
groom:
|
||||
loc = i;
|
||||
if(i == wloc)
|
||||
goto mwump;
|
||||
goto loop;
|
||||
|
||||
case 's':
|
||||
if(tchar == '\n')
|
||||
printf("Give list of rooms terminated by 0\n");
|
||||
for(i=0; i<5; i++) {
|
||||
j = rin()-1;
|
||||
if(j == -1)
|
||||
break;
|
||||
ranarw:
|
||||
for(k=0; k<NTUNN; k++)
|
||||
if(j == p->tunn[k])
|
||||
goto garow;
|
||||
j = rnum(NROOM);
|
||||
goto ranarw;
|
||||
garow:
|
||||
p = &room[j];
|
||||
if(j == loc) {
|
||||
printf("You shot yourself\n");
|
||||
goto done;
|
||||
}
|
||||
if(p->flag&WUMP) {
|
||||
printf("You slew the wumpus\n");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if(--arrow == 0) {
|
||||
printf("That was your last shot\n");
|
||||
goto done;
|
||||
}
|
||||
goto mwump;
|
||||
}
|
||||
|
||||
goto again;
|
||||
|
||||
mwump:
|
||||
p = &room[wloc];
|
||||
p->flag &= ~WUMP;
|
||||
i = rnum(NTUNN+1);
|
||||
if(i != NTUNN)
|
||||
wloc = p->tunn[i];
|
||||
room[wloc].flag |= WUMP;
|
||||
goto loop;
|
||||
|
||||
done:
|
||||
drain();
|
||||
printf("Another game? (y-n) ");
|
||||
if(rline() != 'n') {
|
||||
drain();
|
||||
printf("Same room setup? (y-n) ");
|
||||
if(rline() != 'n')
|
||||
goto setup;
|
||||
goto init;
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
tunnel(i)
|
||||
{
|
||||
register struct room *p;
|
||||
register n, j;
|
||||
int c;
|
||||
|
||||
c = 20;
|
||||
|
||||
loop:
|
||||
n = rnum(NROOM);
|
||||
if(n == i)
|
||||
if(--c > 0)
|
||||
goto loop;
|
||||
p = &room[n];
|
||||
for(j=0; j<NTUNN; j++)
|
||||
if(p->tunn[j] == -1) {
|
||||
p->tunn[j] = i;
|
||||
return(n);
|
||||
}
|
||||
goto loop;
|
||||
}
|
||||
|
||||
rline()
|
||||
{
|
||||
register char c, r;
|
||||
|
||||
while((c=getchar()) == ' ');
|
||||
r = c;
|
||||
while(c != '\n' && c != ' ') {
|
||||
if(c == EOF)
|
||||
exit(0);
|
||||
c = getchar();
|
||||
}
|
||||
tchar = c;
|
||||
return(r);
|
||||
}
|
||||
|
||||
rnum(n)
|
||||
{
|
||||
static short first[2];
|
||||
long temp;
|
||||
|
||||
if(first[1] == 0) {
|
||||
/* time(first); */
|
||||
if(first[1]==0) first[1] = 1;
|
||||
srand((first[1]*first[0])^first[1]);
|
||||
}
|
||||
temp = ((unsigned) rand()) * n;
|
||||
temp = temp/16384; temp = temp/2;
|
||||
return(temp);
|
||||
}
|
||||
|
||||
rin()
|
||||
{
|
||||
register n, c;
|
||||
|
||||
n = 0;
|
||||
c = getchar();
|
||||
while(c != '\n' && c != ' ') {
|
||||
if(c<'0' || c>'9') {
|
||||
while(c != '\n') {
|
||||
if(c == EOF)
|
||||
exit(0);
|
||||
c = getchar();
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
n = n*10 + c-'0';
|
||||
c = getchar();
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
near(ap, ahaz)
|
||||
struct room *ap;
|
||||
{
|
||||
register struct room *p;
|
||||
register haz, i;
|
||||
|
||||
p = apIq
|
||||
This directory contains the source, object and linked versions of utilities
|
||||
useful in the Olivetti implementation of CP/M-8000:
|
||||
cpmcopy Copies the 10 boot tracks from one disk
|
||||
to another.
|
||||
ddcopy "fast" disk-to-disk copy.
|
||||
Reference in New Issue
Block a user