1 /*-
2 # X-BASED TRIANGLES
3 #
4 #  TriangleP.h
5 #
6 ###
7 #
8 #  Copyright (c) 1994 - 99	David Albert Bagley, bagleyd@tux.org
9 #
10 #                   All Rights Reserved
11 #
12 #  Permission to use, copy, modify, and distribute this software and
13 #  its documentation for any purpose and without fee is hereby granted,
14 #  provided that the above copyright notice appear in all copies and
15 #  that both that copyright notice and this permission notice appear in
16 #  supporting documentation, and that the name of the author not be
17 #  used in advertising or publicity pertaining to distribution of the
18 #  software without specific, written prior permission.
19 #
20 #  This program is distributed in the hope that it will be "playable",
21 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
22 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 #
24 */
25 
26 /* Private header file for Triangles */
27 
28 #ifndef _TrianglesP_h
29 #define _TrianglesP_h
30 
31 #include "Triangles.h"
32 
33 /*** random number generator ***/
34 #if HAVE_RAND48
35 #define SRAND srand48
36 #define LRAND lrand48
37 #define MAXRAND (2147483648.0)
38 #else /* HAVE_RAND48 */
39 #if HAVE_RANDOM
40 #define SRAND srand48
41 #define LRAND lrand48
42 #define MAXRAND (2147483648.0)
43 #else /* HAVE_RANDOM */
44 #if HAVE_RAND
45 #define SRAND srand48
46 #define LRAND lrand48
47 #ifdef AIXV3
48 #define MAXRAND (2147483648.0)
49 #else
50 #define MAXRAND (32768.0)
51 #endif
52 #endif /* HAVE_RAND */
53 #endif /* HAVE_RANDOM */
54 #endif /* HAVE_RAND48 */
55 
56 #ifndef SRAND
57 extern void SetRNG(long int s);
58 
59 #define SRAND(X) SetRNG((long) X)
60 #endif
61 #ifndef LRAND
62 extern long LongRNG(void);
63 
64 #define LRAND() LongRNG()
65 #endif
66 #ifndef MAXRAND
67 #define MAXRAND (2147483648.0)
68 #endif
69 
70 #define NRAND(X) ((int)(LRAND()%(X)))
71 
72 #define SYMBOL ':'
73 
74 #define TR 0
75 #define RIGHT 1
76 #define BR 2
77 #define BL 3
78 #define LEFT 4
79 #define TL 5
80 #define COORD 6
81 #define TRBL 0
82 #define TLBR 1
83 #define ROW 2
84 #define ROWTYPES 3
85 #define DOWN 0
86 #define UP 1
87 #define MAXORIENT 2
88 
89 /* The following is in xtriangles.c also */
90 #define MINTRIANGLES 1
91 
92 #define DEFAULTTRIANGLES 4
93 
94 #define ABS(a) (((a)<0)?(-a):(a))
95 #define SIGN(a) (((a)<0)?(-1):1)
96 #define MIN(a,b) (((int)(a)<(int)(b))?(int)(a):(int)(b))
97 #define MAX(a,b) (((int)(a)>(int)(b))?(int)(a):(int)(b))
98 
99 typedef struct _TrianglesPart {
100 	Pixel       foreground;
101 	Pixel       tileColor, borderColor;
102 	int        *tileOfPosition, spacePosition[MAXORIENT];
103 	int         spaceRow[MAXORIENT][ROWTYPES];
104 	int         currentPosition, currentRow[ROWTYPES], currentPositionOrient;
105 	Boolean     started, vertical, mono, reverse;
106 	int         depth;
107 	int         base;
108 	int         size, sizeSize;
109 	XPoint      offset, tileSize, puzzleSize;
110 	XPoint      delta, puzzleOffset, digitOffset;
111 	GC          puzzleGC;
112 	GC          tileGC;
113 	GC          borderGC;
114 	GC          inverseGC;
115 	char       *username;
116 	XtCallbackList select;
117 } TrianglesPart;
118 
119 typedef struct _TrianglesRec {
120 	CorePart    core;
121 	TrianglesPart triangles;
122 } TrianglesRec;
123 
124 /* This gets around C's inability to do inheritance */
125 typedef struct _TrianglesClassPart {
126 	int         ignore;
127 } TrianglesClassPart;
128 
129 typedef struct _TrianglesClassRec {
130 	CoreClassPart core_class;
131 	TrianglesClassPart triangles_class;
132 } TrianglesClassRec;
133 
134 extern TrianglesClassRec trianglesClassRec;
135 extern int *startPosition;
136 
137 extern int  MoveTrianglesDir(TrianglesWidget w, int direction);
138 
139 #if 0
140 extern void SolveTiles();	/* For future auto-solver */
141 
142 #endif
143 extern void DrawAllTiles(TrianglesWidget w);
144 extern Boolean CheckSolved(TrianglesWidget w);
145 extern void InitMoves(void);
146 extern void PutMove(int direction);
147 extern void GetMove(int *direction);
148 extern int  MadeMoves(void);
149 extern void FlushMoves(TrianglesWidget w);
150 extern int  NumMoves(void);
151 extern void ScanMoves(FILE * fp, TrianglesWidget w, int moves);
152 extern void PrintMoves(FILE * fp);
153 extern void ScanStartPosition(FILE * fp, TrianglesWidget w);
154 extern void PrintStartPosition(FILE * fp, TrianglesWidget w);
155 extern void SetStartPosition(TrianglesWidget w);
156 extern int  Row(int pos);
157 extern int  TrBl(int pos, int posRow);
158 extern int  TlBr(int pos, int posRow);
159 
160 #endif /* _TrianglesP_h */
161