1 /*-
2 # X-BASED PYRAMINX(tm)
3 #
4 #  PyraminxP.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 Pyraminx */
27 
28 #ifndef _PyraminxP_h
29 #define _PyraminxP_h
30 
31 #include "Pyraminx.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 IGNORE (-1)
75 #define TOP 0
76 #define TR 1
77 #define RIGHT 2
78 #define BOTTOM 3
79 #define BL 4
80 #define LEFT 5
81 #define COORD 6
82 #define CW 7
83 #define CCW 11
84 
85 /* The following are in xpyraminx.c also */
86 #define MINTETRAS 1
87 #define PERIOD2 2
88 #define PERIOD3 3
89 #define BOTH 4
90 #define MAXMODES 3
91 
92 #define DEFAULTMODE PERIOD3
93 #define DEFAULTTETRAS 3
94 #define MAXFACES 4
95 #define DOWN 1
96 #define UP 0
97 #define MAXVIEWS 2
98 #define MAXSIDES (MAXFACES/MAXVIEWS)
99 #define MAXORIENT (3*MAXSIDES)
100 
101 #define ABS(a) (((a)<0)?(-a):(a))
102 #define SIGN(a) (((a)<0)?(-1):1)
103 #define MIN(a,b) (((int)(a)<(int)(b))?(int)(a):(int)(b))
104 #define MAX(a,b) (((int)(a)>(int)(b))?(int)(a):(int)(b))
105 
106 typedef struct _PyraminxLoc {
107 	int         face, rotation;
108 } PyraminxLoc;
109 
110 typedef struct _PyraminxPart {
111 	Pixel       foreground;
112 	Pixel       borderColor;
113 	Pixel       faceColor[MAXFACES];
114 	PyraminxLoc *tetraLoc[MAXFACES];
115 	PyraminxLoc *faceLoc[MAXSIDES];
116 	PyraminxLoc *rowLoc[3][MAXSIDES];
117 	int         currentFace, currentPosition;
118 	Boolean     started, practice, orient, vertical, mono, reverse,
119 	            sticky;
120 	int         mode, depth;
121 	int         size, sizeSize;
122 	Position    delta;
123 	Position    tetraLength;
124 	Position    faceLength;
125 	Position    viewLength;
126 	Position    sideOffset, orientLineLength, orientDiagLength;
127 	XPoint      puzzleSize;
128 	XPoint      puzzleOffset;
129 	GC          puzzleGC;
130 	GC          borderGC;
131 	GC          faceGC[MAXFACES];
132 	GC          inverseGC;
133 	String      faceName[MAXFACES];
134 	char       *username;
135 	XtCallbackList select;
136 } PyraminxPart;
137 
138 typedef struct _PyraminxRec {
139 	CorePart    core;
140 	PyraminxPart pyraminx;
141 } PyraminxRec;
142 
143 /* This gets around C's inability to do inheritance */
144 typedef struct _PyraminxClassPart {
145 	int         ignore;
146 } PyraminxClassPart;
147 
148 typedef struct _PyraminxClassRec {
149 	CoreClassPart core_class;
150 	PyraminxClassPart pyraminx_class;
151 } PyraminxClassRec;
152 
153 extern PyraminxClassRec pyraminxClassRec;
154 extern PyraminxLoc *startLoc[MAXFACES];
155 
156 extern void MovePyraminx(PyraminxWidget w, int face, int position, int direction, int style, int control);
157 
158 #if 0
159 extern void SolvePolyhedrons();	/* For future auto-solver */
160 
161 #endif
162 extern void DrawAllPolyhedrons(PyraminxWidget w);
163 extern Boolean CheckSolved(PyraminxWidget w);
164 extern void InitMoves(void);
165 extern void PutMove(int face, int position, int direction, int style, int control);
166 extern void GetMove(int *face, int *position, int *direction, int *style, int *control);
167 extern int  MadeMoves(void);
168 extern void FlushMoves(PyraminxWidget w);
169 extern int  NumMoves(void);
170 extern void ScanMoves(FILE * fp, PyraminxWidget w, int moves);
171 extern void PrintMoves(FILE * fp);
172 extern void ScanStartPosition(FILE * fp, PyraminxWidget w);
173 extern void PrintStartPosition(FILE * fp, PyraminxWidget w);
174 extern void SetStartPosition(PyraminxWidget w);
175 
176 #endif /* _PyraminxP_h */
177