File: build.c

package info (click to toggle)
mgt 2.31-7
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 460 kB
  • ctags: 582
  • sloc: ansic: 4,852; sh: 411; pascal: 329; makefile: 88; csh: 3
file content (197 lines) | stat: -rw-r--r-- 3,525 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* "mgt" Copyright (c) 1991 Shodan  */

#include "mgt.h"

int lastMoveX, lastMoveY, moveNum, lastTurn;
coordList *lastletters = 0, *lastmarks;
coordList *marks = 0;
coordList *letters = 0;


FUNCTION void clearLast()
{
   lastMoveX = lastMoveY = -1;
   lastTurn = -1;
   moveNum = 0;  
   curPlayer = t_Black;
}

FUNCTION void highlightLast()
{
   (*io->highlightLast) (lastMoveX, lastMoveY, moveNum, lastTurn);
}


static void setLastMovePos(p)
property *p;
{
   Token player;

   if (p->t==t_Pass) player=p->data.player;
   else player=p->t;

   if (player==t_White){ lastTurn=1; curPlayer=t_Black;}
   else if (player==t_Black) {lastTurn=0;curPlayer=t_White;}
   else lastTurn= -1;

   if (p->t==t_Pass)
     lastMoveX = lastMoveY = PASSVAL;
   else if (p->data.stones) {
      lastMoveX = p->data.stones->x;
      lastMoveY = p->data.stones->y;
   } else
      lastMoveX = lastMoveY = -1;
}


FUNCTION void doPlace(p, b, t)
property *p;
pBoard b;
piece t;
{
   coordList *list;

   list = p->data.stones;
   while (list) {
      placeStone(b, list->x, list->y, t);
      list = list->next;
   }
   if (p->t == t_Black || p->t == t_White){
      moveNum++;
      setLastMovePos(p);
   }

}




FUNCTION void doProps(p, b)
property *p;
pBoard b;
{
   letters = NULL;
   marks = NULL;
   lastTurn= -1;
   while (p) {
      switch (p->t) {
	 case t_White:
	    BUG("t_White ");
	    doPlace(p, b, P_WHITE);
	    break;
	 case t_Black:
	    BUG("t_Black ");
	    doPlace(p, b, P_BLACK);
	    break;
	 case t_AddWhite:
	    BUG("t_AddWhite ");
	    doPlace(p, b, P_WHITE);
	    break;
	 case t_AddBlack:
	    BUG("t_AddBlack ");
	    doPlace(p, b, P_BLACK);
	    break;
	 case t_AddEmpty:
	    BUG("t_AddEmpty ");
	    doPlace(p, b, P_NOTHING);
	    break;
	 case t_Comment:
	    break;
	 case t_Pass:
	    moveNum++;
	    setLastMovePos(p);
	    break;
	 case t_Mark:
	    marks = p->data.stones;
	    break;
	 case t_Letter:
	    letters = p->data.stones;
	    BUG("t_Letter ");
	    break;
	 default:
	    BUG("default ");
      }
      p = p->next;
   }
}



FUNCTION void doPropComment(n)
nodep n;
{
   property *p;

   if (p = getprop(n, t_Comment))
      (*io->displayComment) (p->data.comment);
}


FUNCTION void buildTree0(n, b)
nodep n;
pBoard b;
{
   BUG("parent >");
   if (n) {
      buildTree0(n->parent, b);
      BUG("\nprops:");
      doProps(n->p, b);
   }
}



FUNCTION void buildTree(n, b)
nodep n;
pBoard b;
{
   prisoners[0] = 0;
   prisoners[1] = 0;
   boardClear(b);
   (*io->clearComment) ();
   BUG("buildTree:\n");
   clearLast();
   buildTree0(n, b);
   doPropComment(n);
}


FUNCTION void setPiece(b, i, j, p)
pBoard b;
int i, j;
piece p;
{
   boardSet(b, i, j, p);
   (*io->plotPiece) (b, i, j);
}

FUNCTION void updateBoard(dst, new)
pBoard dst, new;		/* update dst to look like new */
{
   int i, j;
   coordList *cl;

   for (cl = lastmarks; cl; cl = cl->next)
      (*io->plotPiece) (new, cl->x, cl->y);

   for (cl = lastletters; cl; cl = cl->next)
      (*io->plotPiece) (new, cl->x, cl->y);
   lastmarks = marks;
   lastletters = letters;
   for (i = boardsize; i--;)
      for (j = boardsize; j--;) {
	 if (boardGet(new, i, j) != boardGet(dst, i, j)) {
	    setPiece(dst, i, j, boardGet(new, i, j));
	 }
      }
   if (marks) {
      for (cl = marks; cl; cl = cl->next)
	 (*io->plotMark) (new, cl->x, cl->y);
      marks = NULL;
   }
   if (letters) {
      for (i = 0, cl = letters; cl; cl = cl->next, i++)
	 (*io->plotLetter) (cl->x, cl->y, (i % 26) + 'a');
      letters = NULL;
   }
}