157275Sbostic /*-
2*60854Sbostic * Copyright (c) 1992, 1993
3*60854Sbostic * The Regents of the University of California. All rights reserved.
457275Sbostic *
557288Sbostic * This code is derived from software contributed to Berkeley by
657288Sbostic * Chris Torek and Darren F. Provine.
757288Sbostic *
857275Sbostic * %sccs.include.redist.c%
957275Sbostic *
10*60854Sbostic * @(#)shapes.c 8.1 (Berkeley) 05/31/93
1157275Sbostic */
1257275Sbostic
1357275Sbostic /*
1457275Sbostic * Tetris shapes and related routines.
1557275Sbostic *
1657275Sbostic * Note that the first 7 are `well known'.
1757275Sbostic */
1857275Sbostic
1957275Sbostic #include <sys/cdefs.h>
2057275Sbostic #include "tetris.h"
2157275Sbostic
2257275Sbostic #define TL -B_COLS-1 /* top left */
2357275Sbostic #define TC -B_COLS /* top center */
2457275Sbostic #define TR -B_COLS+1 /* top right */
2557275Sbostic #define ML -1 /* middle left */
2657275Sbostic #define MR 1 /* middle right */
2757275Sbostic #define BL B_COLS-1 /* bottom left */
2857275Sbostic #define BC B_COLS /* bottom center */
2957275Sbostic #define BR B_COLS+1 /* bottom right */
3057275Sbostic
3157275Sbostic struct shape shapes[] = {
3257275Sbostic /* 0*/ 7, TL, TC, MR,
3357275Sbostic /* 1*/ 8, TC, TR, ML,
3457275Sbostic /* 2*/ 9, ML, MR, BC,
3557275Sbostic /* 3*/ 3, TL, TC, ML,
3657275Sbostic /* 4*/ 12, ML, BL, MR,
3757275Sbostic /* 5*/ 15, ML, BR, MR,
3857275Sbostic /* 6*/ 18, ML, MR, /* sticks out */ 2,
3957275Sbostic /* 7*/ 0, TC, ML, BL,
4057275Sbostic /* 8*/ 1, TC, MR, BR,
4157275Sbostic /* 9*/ 10, TC, MR, BC,
4257275Sbostic /*10*/ 11, TC, ML, MR,
4357275Sbostic /*11*/ 2, TC, ML, BC,
4457275Sbostic /*12*/ 13, TC, BC, BR,
4557275Sbostic /*13*/ 14, TR, ML, MR,
4657275Sbostic /*14*/ 4, TL, TC, BC,
4757275Sbostic /*15*/ 16, TR, TC, BC,
4857275Sbostic /*16*/ 17, TL, MR, ML,
4957275Sbostic /*17*/ 5, TC, BC, BL,
5057275Sbostic /*18*/ 6, TC, BC, /* sticks out */ 2*B_COLS,
5157275Sbostic };
5257275Sbostic
5357275Sbostic /*
5457275Sbostic * Return true iff the given shape fits in the given position,
5557275Sbostic * taking the current board into account.
5657275Sbostic */
5757275Sbostic int
fits_in(shape,pos)5857275Sbostic fits_in(shape, pos)
5957275Sbostic struct shape *shape;
6057275Sbostic register int pos;
6157275Sbostic {
6257275Sbostic register int *o = shape->off;
6357275Sbostic
6457275Sbostic if (board[pos] || board[pos + *o++] || board[pos + *o++] ||
6557275Sbostic board[pos + *o])
6657275Sbostic return 0;
6757275Sbostic return 1;
6857275Sbostic }
6957275Sbostic
7057275Sbostic /*
7157275Sbostic * Write the given shape into the current board, turning it on
7257275Sbostic * if `onoff' is 1, and off if `onoff' is 0.
7357275Sbostic */
7457275Sbostic void
place(shape,pos,onoff)7557275Sbostic place(shape, pos, onoff)
7657275Sbostic struct shape *shape;
7757275Sbostic register int pos, onoff;
7857275Sbostic {
7957275Sbostic register int *o = shape->off;
8057275Sbostic
8157275Sbostic board[pos] = onoff;
8257275Sbostic board[pos + *o++] = onoff;
8357275Sbostic board[pos + *o++] = onoff;
8457275Sbostic board[pos + *o] = onoff;
8557275Sbostic }
86