Completely get rid of unused m4/ directory
[shogivar/ydirson.git] / backend.c
blob01b7b0d4db358ac3e41c5a459f46c448f17c02be
1 /**************************************************************/
2 /* ShogiVar business logic hand-converted to C by H.G. Muller */
3 /**************************************************************/
5 #include "config.h"
7 #include <stdio.h>
8 #include <string.h>
9 #include <stdlib.h>
11 #include "common.h"
12 #include "backend.h"
13 #include "frontend.h"
15 #define NOCOLOR 0
17 #ifdef MSVC
18 # define MOVE(N, OBJ, X, Y) OBJ.Move(X, Y)
19 # define DRAG(OBJ, X) OBJ.Drag(X)
20 # define CR "\r"
21 # define LF
22 # define DATADIR "./Data"
23 # define CONFIGFILE "%s/Shogi.cfg", Direct
24 #else
25 # define MOVE(N, OBJ, X, Y) MoveObject(N, &OBJ, X, Y)
26 # define DRAG(OBJ, X) OBJ.dragged = X
27 # define CR
28 # define LF "\n"
29 # define CONFIGFILE "./.shogivarrc"
30 #endif
32 // integer globals;
34 INT FirstInitFile, FirstInitRank, LionAttack, FirstSeeMove, Reload, PawnMate, AA, Suggest, EndMove, Eval, CheckLooked, NoLionCapture, Checked, OriginalPiece, RightClick, OriginalFile, OriginalRank, FirstFile, FirstRank, Influence, CheckTest;
35 INT CompLionTest, OldNewFile, OldNewRank, ChuLionTest, ProtectLion, XXX, YYY, BlackKingX, BlackKingY, WhiteKingX, WhiteKingY, Changed, FirstTime, MakeMove, CompFile, CompRank, CompMove, LegalMoves, Evaluate, DropTest, OldSeeMove, BestMove;
36 INT Replaying, OldInitRank, OldInitFile, EmperorTest, WhiteEmperor, BlackEmperor, Boardsize, Notate, Graphnum, Pixels, XCorner, SeeFile, SeeRank, PromGraf, Reverse, CapturedPiece;
37 INT Forwards, Tabbing, PieceSizes, ClickPiece, OldLast, OldRank, OldFile, YCorner, Totpiece, PieceNum, J, I, Demon, XStart, LookMate, GameOver;
38 INT Tilde, Blink, Blocked, MicroCap, BoardSizeX, BoardSizeY, Setup, Reduce, WhiteKing, BlackKing, WhitePrince, BlackPrince, LionPro;
39 INT ForceProm, AutoPromote, Notice, Backwards, TurnCount, Handicap, Display, NewButton, PromDotY, NewIndex, Rank, File, TotGraph, InitRank, InitFile, Prom;
40 INT Testing123, Timing, NewGraf, HandGame, Loading, NoPro, GameNo, MoveCount, NewRank, NewFile, Weaker, TeachVer, Teach, CaptPiece;
41 INT Other, LionTest, NewGame, GeneralInfo, LastWhite, LastBlack, Hook, Range, N, R, F, Area, M, Drop, Dropped, C, D, Capture, RealLion, LionPiece;
42 INT EndTurn, MovePiece, Selection, WhiteLion, BlackLion, Mate, Taken, P, MoveTest, MoveData, FileInc, RankInc, Last, SeeMove, LionHawkVer;
43 INT AllBack, Ligui, XA, LastPieceX, LastPieceY, CCC, ShowLast, BlackInfluence, WhiteInfluence, WhiteEmpX, WhiteEmpY, BlackEmpX, BlackEmpY, Level, RealLevel, Depth, TestDepth, FirstLegal;
44 INT YStart;
46 // string globals;
48 STRING OldComputer, Threat = "Off", FirstScore, SecondScore;
49 STRING OldThreat, ScoreFormat, PromPieceSTR, OldChoice, GameName, LionNameSTR, CMoveSTR, NxtSTR, Turn = "Black", Turn2, Choice;
50 STRING Computer = "White", SaveTitleSTR, NewTurn, ExtraPiece, ElapsedSTR, SpecPowerSTR, LoadedSTR, SavedSTR, Datafile, Direct = DATADIR, Cap, Boardbmp, Grade = "Weak";
52 // float globals;
54 SINGLE Count;
55 SINGLE NewX, NewY;
56 #define COUNT ((int)Count)
58 // long globals;
60 LONG BestTally[26];
61 LONG BestScore, WhiteTally, BlackTally;
62 LONG FinalTally[26];
64 static FILE *f2; // global, because LoadGame opens it, and SetPieces then reads from it.
65 static STRING StringTmp;
67 FORM Board;
68 FORM Start; // FIXME: what is this?
69 FORM RulesHelp;
70 ADDPIECES AddPieces; // created by Load ?
71 // FORM TaiPieces;
73 char *Mid(char *s, int start, int len)
75 static char buf[80];
76 *buf = 0;
77 if(start < 1 || start > strlen(s) || len > 79) return buf;
78 strncpy(buf, s + start - 1, 79); buf[len] = 0;
79 return buf;
81 char *TrimSTR (char *s)
83 char *p; static STRING buf;
84 strncpy(buf, s, 79); while(*s == ' ') s++;
85 p = s + strlen(s) - 1; while(*p == ' ') p--; p[1] = '\0';
86 return buf;
88 char *NumSTR (int n) { static char buf[20]; snprintf(buf, 20, "% d", n); return buf; }
89 char *CharSTR (int n) { static char buf[2]; buf[0] = n; return buf; }
90 INT Int(double x) { return (INT) x; }
91 INT Sgn(INT n) { if(n < 0) return -1; else return n > 0; }
92 char Asc(STRING s) { return *s; }
93 INT Rnd() { return rand(); }
94 void Randomize() { srand(StartTime()); }
96 struct {
97 int Height, Width;
98 int TwipsPerPixelY;
99 } screen;
101 INT Err; // FIXME: this is apparently a variable set by the system, like errno in C
102 INT Dropping; STRING Game; // FIXME: added to prevent compile error, read-only variables!
104 // structures;
106 typedef struct {
107 INT StartFile;
108 INT StartRank;
109 INT EndFile;
110 INT EndRank;
111 INT StartPiece;
112 INT EndPiece;
113 } LegalList;
114 typedef struct {
115 STRING Caption;
116 INT IDStart;
117 INT IDEnd;
118 INT PosStart;
119 INT PosEnd;
120 } MoveRecord;
121 typedef struct {
122 INT number;
123 INT Positions[13];
124 INT PieceNum[13];
125 } CaptiveRecord;
126 typedef struct {
127 INT File;
128 INT Rank;
129 INT Piece;
130 } Layout;
131 typedef struct {
132 INT File;
133 INT Rank;
134 } Empty;
135 typedef struct {
136 INT WhiteNum;
137 INT BlackNum;
138 INT WhiteValue;
139 INT BlackValue;
140 Layout Info[513];
141 } Map;
143 // Tables;
145 #define SZX 26
146 #define SZY 26
147 #define PIXELS 61
148 #define CAPTURE 30
150 LegalList MoveList[27];
151 Empty Clearing[201];
152 STRING ShortScore[4001];
153 STRING BlackDrop[3];
154 STRING WhiteDrop[3];
155 LegalList CompLegal[2001];
156 Layout ExtraCapture[2001];
157 Layout ECapture[22];
158 Layout LionVictim;
159 Piece Pieces[1000]; // TODO how many really?
160 INT LowBlack[SZX][SZY];
161 INT LowWhite[SZX][SZY];
162 INT PieceMask[7][PIXELS];
163 INT Squares[SZX][SZY];
164 INT Comp[SZX][SZY];
165 INT CompHeld[2*CAPTURE];
166 INT Legal[SZX][SZY];
167 INT OldLegal[SZX][SZY];
168 INT Grafix[SZX][SZY];
169 INT InHand[2*CAPTURE];
170 INT TempHand[2*CAPTURE];
171 INT CapRef[2*CAPTURE];
172 INT AreaOK[SZX][SZY];
173 INT Camps[SZX][SZY];
174 INT Attacker[SZX][SZY];
175 INT OldAttack[SZX][SZY];
176 Map BanMap[SZX][SZY];
177 Map BackMap[SZX][SZY];
178 MoveRecord Score[4001];
179 CaptiveRecord Captures[4001];
180 LONG KingTally[2001];
181 LONG OldKingTally[27];
183 INT OldHand[2*CAPTURE];
184 INT TestBoard[SZX][SZY];
186 // Prototypes
188 void AreaMove2();
189 void CheckBurn();
190 void CheckAdd();
191 void CompPromote();
192 void CompPromote2();
193 void ConfigLoad2();
194 void ConsiderMate();
195 void ConsiderMove();
196 void EmperorInfluence();
197 void FindEmperorMove();
198 void FindInfluence();
199 void FireDemon();
200 void FormDrop();
201 void GetSquare();
202 void GetSquare2();
203 void HeldDrop();
204 void HeldValid();
205 void KingSafety();
206 void Lion2();
207 void LionBurn();
208 void LionBurn2();
209 void LookAhead();
210 void LookCheck2();
211 void LookComp2();
212 void LookMove();
213 void Main();
214 void MakeDrop();
215 void MakeMap();
216 void MicroAdd();
217 void MicroDrop();
218 void MoveFormDrop();
219 void NextTurn();
220 void NextTurn2();
221 void PawnMates();
222 void PicDrop();
223 void Promessage();
224 void Promote();
225 void RemovePiece();
226 void ReorderMoves();
227 void ResetHand();
228 void ResetLegal();
229 void RestoreGrafix();
230 void RestoreMap();
231 void SetClock();
232 void SetDifficulty();
233 void SetGrade();
234 void SetGrafix();
235 void SetKings();
236 void SetPieces();
237 void SetThreat();
238 void ShowMove();
239 void SingleStep();
240 void SquareReplace();
241 void StartUp();
242 void SuggestMove();
243 void TakeBack();
244 void Territory();
245 void TestAhead();
246 void TestDrop();
247 void TestOther();
248 void TestStrength();
249 void Tetrarchs();
250 void TooSmall();
251 void UnPromote();
252 void Validate();
253 void WaDrop();
254 void TwoKings();
257 void ActingPieces ()
259 int AB, CD;
260 if(InitFile > 0) {
261 BlackInfluence = 0; WhiteInfluence = 0;
262 OriginalPiece = Squares[InitFile][InitRank];
263 OriginalFile = InitFile; OriginalRank = InitRank;
264 Influence = 1;
265 for(AB = 1; AB <= BoardSizeY; AB++) {
266 for(CD = 1; CD <= BoardSizeX; CD++) {
267 if(Squares[CD][AB] != 0) {
268 if(OriginalPiece != 0 && Sgn(Squares[CD][AB]) != Sgn(OriginalPiece)) {
269 Squares[OriginalFile][OriginalRank] = OriginalPiece;
270 } else {
271 if(CheckTest != 1) Squares[OriginalFile][OriginalRank] = 0;
273 InitFile = CD; InitRank = AB;
274 if(CheckTest != 1 || (Sgn(OriginalPiece) != Sgn(Squares[CD][AB])) ) Validate();
276 } // Next CD;
277 } // Next AB;
278 if(CheckTest != 1 && (!strcmp(Choice, "Maka") || !strcmp(Choice, "Tai")) ) {
279 if(OriginalPiece == 0) {
280 if(WhiteEmperor == 1 ) { InitFile = WhiteEmpX; InitRank = WhiteEmpY; EmperorInfluence(); }
281 if(BlackEmperor == 1 ) { InitFile = BlackEmpX; InitRank = BlackEmpY; EmperorInfluence(); }
282 } else {
283 if(OriginalPiece < 0 && WhiteEmperor == 1 && strcmp(Pieces[abs(OriginalPiece)].Name, "Emperor") ) {
284 InitFile = WhiteEmpX; InitRank = WhiteEmpY; EmperorInfluence();
286 if(OriginalPiece > 0 && WhiteEmperor == 1 && BlackEmperor == 0 && BlackInfluence == 0) {
287 InitFile = WhiteEmpX; InitRank = WhiteEmpY; EmperorInfluence();
289 if(OriginalPiece > 0 && BlackEmperor == 1 && strcmp(Pieces[abs(OriginalPiece)].Name, "Emperor") ) {
290 InitFile = BlackEmpX; InitRank = BlackEmpY; EmperorInfluence();
292 if(OriginalPiece < 0 && BlackEmperor == 1 && WhiteEmperor == 0 && WhiteInfluence == 0) {
293 InitFile = BlackEmpX; InitRank = BlackEmpY; EmperorInfluence();
297 Influence = 0;
298 Squares[OriginalFile][OriginalRank] = OriginalPiece;
302 void AddEmperorAttack ()
304 LegalMoves = LegalMoves + 1;
305 if(!strcmp(Turn, "White") ) {
306 CompLegal[LegalMoves].StartFile = WhiteEmpX;
307 CompLegal[LegalMoves].StartRank = WhiteEmpY;
308 CompLegal[LegalMoves].EndFile = BlackEmpX;
309 CompLegal[LegalMoves].EndRank = BlackEmpY;
310 CompLegal[LegalMoves].StartPiece = Squares[WhiteEmpX][WhiteEmpY];
311 CompLegal[LegalMoves].EndPiece = Squares[WhiteEmpX][WhiteEmpY];
312 } else {
313 CompLegal[LegalMoves].StartFile = BlackEmpX;
314 CompLegal[LegalMoves].StartRank = BlackEmpY;
315 CompLegal[LegalMoves].EndFile = WhiteEmpX;
316 CompLegal[LegalMoves].EndRank = WhiteEmpY;
317 CompLegal[LegalMoves].StartPiece = Squares[BlackEmpX][BlackEmpY];
318 CompLegal[LegalMoves].EndPiece = Squares[BlackEmpX][BlackEmpY];
322 void AddEmperorMove ()
324 LegalMoves = LegalMoves + 1;
325 CompLegal[LegalMoves].StartFile = InitFile;
326 CompLegal[LegalMoves].StartRank = InitRank;
327 CompLegal[LegalMoves].EndFile = SeeFile;
328 CompLegal[LegalMoves].EndRank = SeeRank;
329 CompLegal[LegalMoves].StartPiece = Squares[InitFile][InitRank];
330 CompLegal[LegalMoves].EndPiece = Squares[InitFile][InitRank];
333 void AddHand ()
335 int X;
336 for(X = 1; X <= Capture; X++) {
337 if(CapRef[X] == CaptPiece) {
338 InHand[X] = InHand[X] + 1;
339 Board.HandPic[X].Visible = True;
340 if(InHand[X] > 1) sprintf(Board.Held[X].Caption, "%d", InHand[X]);
341 if(!strcmp(Choice, "Micro")) {
342 MicroCap = X;
343 MicroAdd();
345 } else {
346 if(CapRef[X] == 0 - CaptPiece) {
347 InHand[Capture + X] = InHand[Capture + X] + 1;
348 Board.HandPic[Capture + X].Visible = True;
349 if(InHand[Capture + X] > 1) sprintf(Board.Held[Capture + X].Caption, "%d", InHand[Capture + X]);
350 if(!strcmp(Choice, "Micro") ) {
351 MicroCap = Capture + X;
352 MicroAdd();
356 } // } // Next X;
359 void AddHand2 ()
361 int X;
362 if(MovePiece != 1 ) {
363 for(X = 1; X <= Capture; X++) {
364 if(CapRef[X] == Selection ) {
365 InHand[X] = InHand[X] + 1;
366 sprintf(Board.Held[X].Caption, "%d", InHand[X]);
367 if(!strcmp(Choice, "Micro") ) {
368 MicroCap = X;
369 MicroAdd();
371 } else {
372 if(CapRef[X] == 0 - Selection ) {
373 InHand[Capture + X] = InHand[Capture + X] + 1;
374 sprintf(Board.Held[Capture + X].Caption, "%d", InHand[Capture + X]);
375 if(!strcmp(Choice, "Micro") ) {
376 MicroCap = Capture + X;
377 MicroAdd();
381 } // Next X;
382 CheckAdd();
386 void AddHand3 ()
388 int X;
389 for(X = 1; X <= Capture; X++) {
390 if(CapRef[X] == CaptPiece ) {
391 InHand[X] = InHand[X] + 1;
392 if(!strcmp(Choice, "Micro") ) {
393 MicroCap = X;
394 if((MicroCap > 4 && MicroCap < 9) || MicroCap > 12)
395 InHand[MicroCap - 4] = InHand[MicroCap - 4] + 1;
396 else InHand[MicroCap + 4] = InHand[MicroCap + 4] + 1;
398 } else {
399 if(CapRef[X] == 0 - CaptPiece ) {
400 InHand[Capture + X] = InHand[Capture + X] + 1;
401 if(!strcmp(Choice, "Micro") ) {
402 MicroCap = Capture + X;
403 if((MicroCap > 4 && MicroCap < 9) || MicroCap > 12)
404 InHand[MicroCap - 4] = InHand[MicroCap - 4] + 1;
405 else InHand[MicroCap + 4] = InHand[MicroCap + 4] + 1;
409 } // Next X;
412 void AddLegalMove ()
414 LegalMoves = LegalMoves + 1;
415 CompLegal[LegalMoves].StartFile = InitFile;
416 CompLegal[LegalMoves].StartRank = InitRank;
417 CompLegal[LegalMoves].EndFile = SeeFile;
418 CompLegal[LegalMoves].EndRank = SeeRank;
419 if(InitFile == 0 ) {
420 CompLegal[LegalMoves].StartPiece = CapRef[I];
421 CompLegal[LegalMoves].EndPiece = CapRef[I];
422 } else {
423 CompLegal[LegalMoves].StartPiece = Squares[InitFile][InitRank];
424 CompLegal[LegalMoves].EndPiece = Squares[InitFile][InitRank];
425 CompPromote();
429 void AddLionMove ()
431 LegalMoves = LegalMoves + 1;
432 CompLegal[LegalMoves].StartFile = InitFile;
433 CompLegal[LegalMoves].StartRank = InitRank;
434 CompLegal[LegalMoves].EndFile = XXX;
435 CompLegal[LegalMoves].EndRank = YYY;
436 CompLegal[LegalMoves].StartPiece = Squares[NewFile][NewRank];
437 CompLegal[LegalMoves].EndPiece = Squares[NewFile][NewRank];
440 void AddSomePieces ()
442 int X;
443 #if 0
444 int K, i, j;
445 char spaces[50];
446 STRING ASTR, HelpSTR;
447 for(K = PieceNum / 2; K >= 1; K--) {
448 sprintf(ASTR, "%s %s %d", Pieces[K].Name, Pieces[K].sname, Pieces[K].number);
449 for(i=strlen(ASTR), j=0; i<38; i++) spaces[j++] = ' '; spaces[j] = 0;
450 sprintf(HelpSTR, "%s %s %s %s %d", ExtraPiece, Pieces[K].Name, Pieces[K].sname, spaces, Pieces[K].number);
451 if(!strcmp(AddPieces.NewPiece.List[AddPieces.NewPiece.ListIndex], HelpSTR) ) { // FIXME: only dummy now
452 Selection = Pieces[K].number;
453 if(!strcmp(ExtraPiece, "White")) Selection = 0 - Selection;
455 } // Next K;
456 #else
457 // [HGM] Selection set by caller by requesting selected item from listbox
458 Selection = Pieces[Selection].number;
459 if(!strcmp(ExtraPiece, "White")) Selection = 0 - Selection;
460 #endif
461 AddPieces.Visible = False;
462 sprintf(Board.Caption, "Adding %s %ss - [Press Right Button When Finished]", ExtraPiece, Pieces[abs(Selection)].Name);
463 strcpy(Board.BlackClock.Caption, "00:00:00");
464 strcpy(Board.WhiteClock.Caption, "00:00:00");
465 Board.Timer1.Enabled = False;
466 strcpy(Board.LastMove.Caption, "");
467 if(Drop == 1 ) {
468 for(X = 1; X <= Capture; X++) {
469 if(!strcmp(ExtraPiece, "Black") ) {
470 if(CapRef[X] == Selection ) {
471 Board.HandPic[X].Visible = True;
472 sprintf(Board.Held[X].Caption, "%d", InHand[X]);
474 } else {
475 if(CapRef[X] == 0 - Selection ) {
476 Board.HandPic[Capture + X].Visible = True;
477 sprintf(Board.Held[Capture + X].Caption, "%d", InHand[Capture + X]);
480 } // Next X;
482 UnloadAddPieces();
485 void AddTally ()
487 INT DD, EE, FF, QQ, BlackLoss, WhiteLoss, HighBlackLoss, HighWhiteLoss;
488 BestTally[1] = -999999; CompMove = 0; Influence = 3; Evaluate = 1;
489 WhiteTally = 0; BlackTally = 0;
490 MakeMap();
491 for(DD = 1;DD <= BoardSizeY; DD++) {
492 for(EE = 1; EE <= BoardSizeX; EE++) {
493 if(Squares[EE][DD] < 0) WhiteTally = WhiteTally + (Pieces[abs(Squares[EE][DD])].Value * 10);
494 if(Squares[EE][DD] > 0) BlackTally = BlackTally + (Pieces[abs(Squares[EE][DD])].Value * 10);
495 if(BanMap[EE][DD].BlackNum == 0 && BanMap[EE][DD].WhiteNum > 0 ) {
496 WhiteTally = 1 + abs((BoardSizeY / 2) - DD) + WhiteTally;
497 if(Squares[EE][DD] > 0 && !strcmp(Turn, "Black") ) BlackTally = BlackTally - (Pieces[abs(Squares[EE][DD])].Value * 10);
499 if(BanMap[EE][DD].WhiteNum == 0 && BanMap[EE][DD].BlackNum > 0 ) {
500 BlackTally = abs((BoardSizeY / 2) - DD) + BlackTally;
501 if(Squares[EE][DD] < 0 && !strcmp(Turn, "White") ) WhiteTally = WhiteTally - (Pieces[abs(Squares[EE][DD])].Value * 10);
503 if(BanMap[EE][DD].WhiteNum > 0 && BanMap[EE][DD].BlackNum > 0 ) {
504 if(Squares[EE][DD] > 0 && !strcmp(Turn, "Black") ) {
505 for(QQ = 1; QQ <= Attacker[EE][DD]; QQ++) {
506 if(BanMap[EE][DD].Info[QQ].Piece < 0 && (Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value < LowWhite[EE][DD] || LowWhite[EE][DD] == 0) )
507 LowWhite[EE][DD] = Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value;
508 } // Next QQ;
509 BlackLoss = ((Pieces[abs(Squares[EE][DD])].Value - LowWhite[EE][DD]) * 10);
510 if(BlackLoss > HighBlackLoss ) HighBlackLoss = BlackLoss;
512 if(Squares[EE][DD] < 0 && !strcmp(Turn, "White") ) {
513 for(QQ = 1; QQ <= Attacker[EE][DD]; QQ++) {
514 if(BanMap[EE][DD].Info[QQ].Piece > 0 && (Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value < LowBlack[EE][DD] || LowBlack[EE][DD] == 0) )
515 LowBlack[EE][DD] = Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value;
516 } // Next QQ;
517 WhiteLoss = ((Pieces[abs(Squares[EE][DD])].Value - LowBlack[EE][DD]) * 10);
518 if(WhiteLoss > HighWhiteLoss ) HighWhiteLoss = WhiteLoss;
521 LowWhite[EE][DD] = 0; LowBlack[EE][DD] = 0;
522 } // Next EE;
523 } // Next DD;
524 if(Drop == 1 ) {
525 for(FF = 1; FF <= Capture; FF++) {
526 BlackTally = BlackTally + (Pieces[abs(CapRef[FF])].Value * 11) * (InHand[FF]);
527 WhiteTally = WhiteTally + (Pieces[abs(CapRef[FF + Capture])].Value * 11) * (InHand[FF + Capture]);
528 } // Next FF;
530 BlackTally = BlackTally - HighBlackLoss; HighBlackLoss = 0;
531 WhiteTally = WhiteTally - HighWhiteLoss; HighWhiteLoss = 0;
532 if(!strcmp(Turn, "White") ) BestTally[1] = WhiteTally - BlackTally; else BestTally[1] = BlackTally - WhiteTally;
535 void AreaMove ()
537 int X;
538 AreaMove2();
539 for(X = 1; X <= Area - 1; X++) {
540 for(N = InitRank - X; N <= InitRank + X; N++) {
541 if(N > 0 && N <= BoardSizeY ) {
542 for(P = InitFile - X; P <= InitFile + X; P++) {
543 if(P > 0 && P <= BoardSizeX ) {
544 if(AreaOK[P][N] == 1 && (abs(P - InitFile) <= X && abs(N - InitRank) <= X) ) AreaMove2();
546 } // Next P;
548 } // Next N;
549 } // Next X;
552 void AreaMove2 ()
554 int Q, S;
555 Evaluate = 0;
556 for(Q = N - 1; Q <= N + 1; Q++) {
557 if(Q > 0 && Q <= BoardSizeY ) {
558 for(S = P - 1; S <= P + 1; S++) {
559 if(S > 0 && S <= BoardSizeX ) {
560 if(Squares[S][Q] == 0 ) {
561 Board.FillColor = 0xFFFFFF;
562 if(SeeMove == 1 ) { SeeFile = S; SeeRank = Q; LookMove(); }
563 Legal[S][Q] = 1;
564 AreaOK[S][Q] = 1;
565 NewFile = S; NewRank = Q; CheckBurn();
566 if(Demon == 1 ) FireDemon();
567 } else {
568 if(Sgn(Squares[S][Q]) != Sgn(Squares[InitFile][InitRank]) || ((Influence > 0) && (S != InitFile || Q != InitRank)) ) {
569 Board.FillColor = 0xFF; // 0xFF&
570 if(SeeMove == 1 ) { SeeFile = S; SeeRank = Q; LookMove(); }
571 Legal[S][Q] = 1;
572 NewFile = S; NewRank = Q; CheckBurn();
573 if(Demon == 1 ) FireDemon();
577 } // Next S;
579 } // Next Q;
582 void AskMate ()
584 INT BB, CC, SS, TT, CheckDrop, OldCompMove, OldInfluence, OldEvaluate, TestFile, TestRank;
585 if((!strcmp(Pieces[abs(CapRef[I])].Name, "Pawn") || !strcmp(Pieces[abs(CapRef[I])].Name, "Sparrow Pawn") || !strcmp(Pieces[abs(CapRef[I])].Name, "Swallow") || !strcmp(Pieces[abs(CapRef[I])].Name, "Dolphin")) && (strcmp(Choice, "Micro") && strcmp(Choice, "Yari")) ) {
586 CheckDrop = 0;
587 if(!strcmp(Turn, "Black") && WhiteKingY < BoardSizeY ) {
588 if(Legal[WhiteKingX][WhiteKingY + 1] == 1 ) { Squares[WhiteKingX][WhiteKingY + 1] = CapRef[I]; File = WhiteKingX; Rank = WhiteKingY + 1; CheckDrop = 1; }
590 if(!strcmp(Turn, "White") && BlackKingY > 1 ) {
591 if(Legal[BlackKingX][BlackKingY - 1] == 1 ) { Squares[BlackKingX][BlackKingY - 1] = CapRef[I]; File = BlackKingX; Rank = BlackKingY - 1; CheckDrop = 1; }
593 if(CheckDrop == 1 ) {
594 for(CC = 1; CC <= BoardSizeY; CC++) {
595 for(BB = 1; BB <= BoardSizeX; BB++) {
596 Comp[BB][CC] = Squares[BB][CC];
597 OldLegal[BB][CC] = Legal[BB][CC];
598 } // Next BB;
599 } // Next CC;
600 OldInfluence = Influence; OldEvaluate = Evaluate; OldCompMove = CompMove;
601 OldSeeMove = SeeMove; Influence = 3; Evaluate = 1; CompMove = 0; SeeMove = 1;
602 TestFile = File; TestRank = Rank;
603 MakeMap();
604 File = TestFile; Rank = TestRank;
605 for(CC = 1; CC <= BoardSizeY; CC++) {
606 for(BB = 1; BB <= BoardSizeX; BB++) {
607 Squares[BB][CC] = Comp[BB][CC];
608 } // Next BB;
609 } // Next CC;
610 Influence = OldInfluence; Evaluate = OldEvaluate; CompMove = OldCompMove;
611 if(!strcmp(Turn, "Black") ) {
612 if(BanMap[File][Rank].WhiteNum < 2 && BanMap[File][Rank].BlackNum > 0 ) {
613 PawnMate = 1;
614 for(SS = Rank - 2; SS <= Rank; SS++) {
615 for(TT = File - 1; TT <= File + 1; TT++) {
616 if(TT > 0 && TT <= BoardSizeX && SS > 0 && SS <= BoardSizeY && (SS != Rank || TT != File) && (SS != WhiteKingX || TT != WhiteKingY) ) {
617 if(BanMap[TT][SS].BlackNum == 0 && Squares[TT][SS] >= 0 ) PawnMate = 0;
619 } // Next TT;
620 } // Next SS;
621 if(PawnMate == 1 ) OldLegal[File][Rank] = 0;
623 } else {
624 if(BanMap[File][Rank].BlackNum < 2 && BanMap[File][Rank].WhiteNum > 0 ) {
625 PawnMate = 1;
626 for(SS = Rank; SS <= Rank + 2; SS++) {
627 for(TT = File - 1; TT <= File + 1; TT++) {
628 if(TT > 0 && TT <= BoardSizeX && SS > 0 && SS <= BoardSizeY && (SS != Rank || TT != File) && (SS != BlackKingY || TT != BlackKingX) ) {
629 if(BanMap[TT][SS].WhiteNum == 0 && Squares[TT][SS] <= 0 ) PawnMate = 0;
631 } // Next TT;
632 } // Next SS;
633 if(PawnMate == 1 ) OldLegal[File][Rank] = 0;
636 SeeMove = OldSeeMove;
637 for(AA = 1; AA <= BoardSizeY; AA++) {
638 for(BB = 1; BB <= BoardSizeX; BB++) {
639 Squares[BB][AA] = Comp[BB][AA];
640 Legal[BB][AA] = OldLegal[BB][AA];
641 } // Next BB;
642 } // Next AA;
643 Squares[File][Rank] = 0;
646 PawnMate = 0;
649 void AutoMessage ()
651 Board.PieceID.ForeColor = 0x8000; // 0x8000&
652 sprintf(Board.PieceID.Caption, "%s promotes", PromPieceSTR);
653 if(strcmp(Game, "Micro") && strcmp(Game, "Tori") && strcmp(Game, "Whale") && strcmp(Game, "Maka") && strcmp(Game, "DaiDai") && strcmp(Game, "Tai") && strcmp(Computer, Turn) && strcmp(Computer, "Both") ) {
654 Notice = 1;
655 sprintf(Board.Caption, "Double Click on new %s if not promoting.", Pieces[abs(Squares[File][Rank])].Name);
659 void BugFix ()
661 INT A, B, BugNo;
662 Count = 0; Backwards = 0; BugNo = 64;
663 if(!strcmp(Choice, "HShogi")) BugNo = 40;
664 else if(!strcmp(Choice, "Wa")) BugNo = 69;
665 else if(!strcmp(Choice, "Chu")) BugNo = 93;
666 else if(!strcmp(Choice, "Dai")) BugNo = 132;
667 else if(!strcmp(Choice, "Tenjiku")) BugNo = 158;
668 else if(!strcmp(Choice, "DaiDai")) BugNo = 192;
669 else if(!strcmp(Choice, "Maka")) BugNo = 192;
670 else if(!strcmp(Choice, "Tai")) BugNo = 356;
671 else if(!strcmp(Choice, "Heian")) BugNo = 92;
672 for(A = 0; A <= BugNo; A++) {
673 if(Board.showpic[A].Visible == False ) Count = Count + 1;
674 } // Next A;
675 for(A = 0; A <= BugNo; A++) {
676 Board.showpic[A].Visible = False;
677 for(B = 1; B <= BoardSizeY; B++) {
678 for(C = 1; C <= BoardSizeX; C++) {
679 if(Grafix[C][B] == A ) Board.showpic[A].Visible = True;
680 } // Next C;
681 } // Next B;
682 } // Next A;
683 Setup = 0;
686 void ChangeGame ()
687 { // Menu Function.
688 // TODO
689 // UnloadStart();
690 UnloadBoard();
691 UnloadPieceHelp();
692 // Unload RulesHelp;
693 // Main(); // [HGM] we do this with delay, scheduled by caller
696 void ChangeSides ()
698 if(!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Porpoise") ) {
699 strcpy(Board.Caption, "Captured Porpoise becomes a Killer Whale");
700 Notice = 1;
702 if(Pieces[abs(Squares[File][Rank])].Promotes == 0 && Pieces[abs(Squares[File][Rank])].PrGraphic > 0 ) {
703 CaptPiece = Pieces[abs(Squares[File][Rank])].PrGraphic;
704 if(Squares[File][Rank] > 0 ) {
705 CaptPiece = 0 - CaptPiece;
707 } else {
708 CaptPiece = 0 - Squares[File][Rank];
710 AddHand();
713 void ChangeTurn ()
714 { // Menu function to set side to move. NewTurn = "White" or "Black". (Calls EndSetup() before)
715 if(!strcmp(NewTurn, "Black") ) {
716 strcpy(Board.LastMove.Caption, "");
717 MoveCount = 0; TurnCount = 0;
718 strcpy(Board.NextMove.Caption, "Black to Move");
719 strcpy(Turn, "Black");
720 strcpy(Board.BlackClock.Caption, "00:00:00");
721 strcpy(Board.WhiteClock.Caption, "00:00:00");
723 if(!strcmp(NewTurn, "White") ) {
724 strcpy(Board.LastMove.Caption, "");
725 MoveCount = 1; TurnCount = 0;
726 strcpy(Turn, "White");
727 strcpy(Board.NextMove.Caption, "White to Move");
728 strcpy(Board.BlackClock.Caption, "00:00:00");
729 strcpy(Board.WhiteClock.Caption, "00:00:00");
733 void CheckAdd ()
734 { // AddWhite/Black menu function. ExtraPiece = "White"/"Black" (after EndSetup())
735 INT K, L;
736 strcpy(Board.LastMove.Caption, "");
737 Count = 0; Setup = 1;
738 for(K = 1; K <= BoardSizeY; K++) {
739 for(L = 1; L <= BoardSizeX; L++) {
740 if(Squares[L][K] != 0 ) Count = Count + 1;
741 } // Next L;
742 } // Next K;
743 if(Drop == 1 ) {
744 for(K = 1; K <= Capture * 2; K++) {
745 Count = Count + InHand[K];
746 if(!strcmp(Choice, "Micro") ) Count = Count - (InHand[K] / 2);
747 } // Next K;
749 if(Count >= Totpiece ) {
750 strcpy(Board.Caption, "You can not add any more pieces!");
751 Notice = 1;
752 Selection = 0; MovePiece = 0;
753 Board.Timer1.Enabled = True;
754 TurnCount = 0; MoveCount = 0;
755 if(Drop == 1 ) ResetHand();
756 if(!strcmp(Turn, "White") ) MoveCount = 1;
757 BugFix();
758 } else {
759 if(Selection == 0 ) LoadAddPieces();
763 void CheckBurn ()
765 INT K, L;
766 Evaluate = 0;
767 for(K = NewRank - 1; K <= NewRank + 1; K++) {
768 for(L = NewFile - 1; L <= NewFile + 1; L++) {
769 if(L > 0 && L <= BoardSizeX && K > 0 && K <= BoardSizeY ) {
770 if((K != NewRank || L != NewFile) && Squares[L][K] != 0 ) {
771 if(Pieces[abs(Squares[L][K])].special == 'F' && Sgn(Squares[InitFile][InitRank]) != Sgn(Squares[L][K]) ) {
772 Board.FillColor = 0; // 0x0&
773 if(SeeMove == 1 ) { SeeFile = NewFile; SeeRank = NewRank; LookMove(); }
774 Legal[NewFile][NewRank] = 3;
778 } // Next L;
779 } // Next K;
782 void CheckEmperor ()
784 INT FFF, GGG, OldInfluence, OldSeeFile, OldSeeRank;
785 OldInfluence = Influence; ProtectLion = 0; OldSeeMove = SeeMove; SeeMove = 1;
786 Influence = 1; ChuLionTest = 1; OldInitFile = InitFile; OldInitRank = InitRank;
787 OldNewFile = NewFile; OldNewRank = NewRank; OldSeeFile = SeeFile; OldSeeRank = SeeRank; OldFile = File; OldRank = Rank;
788 for(FFF = 1; FFF <= BoardSizeY; FFF++) {
789 for(GGG = 1; GGG <= BoardSizeX; GGG++) {
790 OldLegal[GGG][FFF] = Legal[GGG][FFF];
791 } // Next GGG;
792 } // Next FFF;
793 for(FFF = 1; FFF <= BoardSizeY; FFF++) {
794 for(GGG = 1; GGG <= BoardSizeX; GGG++) {
795 if(Sgn(Squares[GGG][FFF]) == Sgn(Squares[OldNewFile][OldNewRank]) ) {
796 InitFile = GGG; InitRank = FFF; Validate();
797 if(ProtectLion == 1 ) { OldLegal[OldNewFile][OldNewRank] = 0; break; }
799 } // Next GGG;
800 if(ProtectLion == 1 ) break;
801 } // Next FFF;
802 for(FFF = 1; FFF <= BoardSizeY; FFF++) {
803 for(GGG = 1; GGG <= BoardSizeX; GGG++) {
804 Legal[GGG][FFF] = OldLegal[GGG][FFF];
805 } // Next GGG;
806 } // Next FFF;
807 Influence = OldInfluence;
808 ChuLionTest = 0; InitFile = OldInitFile; InitRank = OldInitRank;
809 NewFile = OldNewFile; NewRank = OldNewRank; SeeFile = OldSeeFile; SeeRank = OldSeeRank; File = OldFile; Rank = OldRank;
810 SeeMove = OldSeeMove;
813 void CheckMate ()
815 if(!strcmp(Turn, "White") ) {
816 if(abs(Squares[File][Rank]) == 1 || !strcmp(Pieces[abs(Squares[File][Rank])].Name, "Emperor") ) BlackKing = 1;
817 if(!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[File][Rank])].Name, "Prince") ) BlackPrince = BlackPrince - 1;
818 if(!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Emperor") ) BlackEmperor = 0;
819 } else {
820 if(!strcmp(Turn, "Black") ) {
821 if(abs(Squares[File][Rank]) == 1 || !strcmp(Pieces[abs(Squares[File][Rank])].Name, "Emperor") ) WhiteKing = 1;
822 if(!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Emperor") ) WhiteEmperor = 0;
823 if(!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[File][Rank])].Name, "Prince") ) WhitePrince = WhitePrince - 1;
826 if(!strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai") ) {
827 if(BlackKing == 1 && BlackPrince == 0 ) { Mate = 1; GameOver = 1; }
828 if(WhiteKing == 1 && WhitePrince == 0 ) { Mate = 1; GameOver = 1; }
832 void ChuLion ()
834 INT FFF, GGG, OldInfluence, OldSeeFile, OldSeeRank;
835 OldInfluence = Influence; ProtectLion = 0; OldSeeMove = SeeMove; SeeMove = 1;
836 Influence = 1; ChuLionTest = 1; OldInitFile = InitFile; OldInitRank = InitRank;
837 OldNewFile = NewFile; OldNewRank = NewRank; OldSeeFile = SeeFile; OldSeeRank = SeeRank; OldFile = File; OldRank = Rank;
838 for(FFF = 1; FFF <= BoardSizeY; FFF++) {
839 for(GGG = 1; GGG <= BoardSizeX; GGG++) {
840 OldLegal[GGG][FFF] = Legal[GGG][FFF];
841 } // Next GGG;
842 } // Next FFF;
843 for(FFF = 1; FFF <= BoardSizeY; FFF++) {
844 for(GGG = 1; GGG <= BoardSizeX; GGG++) {
845 if(Sgn(Squares[GGG][FFF]) == Sgn(Squares[OldNewFile][OldNewRank]) ) {
846 InitFile = GGG; InitRank = FFF; Validate();
847 if(ProtectLion == 1 ) { OldLegal[OldNewFile][OldNewRank] = 0; break; }
849 } // Next GGG;
850 if(ProtectLion == 1 ) break;
851 } // Next FFF;
852 for(FFF = 1; FFF <= BoardSizeY; FFF++) {
853 for(GGG = 1; GGG <= BoardSizeX; GGG++) {
854 Legal[GGG][FFF] = OldLegal[GGG][FFF];
855 } // Next GGG;
856 } // Next FFF;
857 Influence = OldInfluence;
858 ChuLionTest = 0; InitFile = OldInitFile; InitRank = OldInitRank; SeeMove = OldSeeMove;
859 NewFile = OldNewFile; NewRank = OldNewRank; SeeFile = OldSeeFile; SeeRank = OldSeeRank; File = OldFile; Rank = OldRank;
862 void ClearBoard ()
863 { // Menu function. (calls EndSetup() before.)
864 INT A, B;
865 int Response;
866 Response = MsgBox("Are You Sure ?", 36, "Clear the Board");
867 if(Response == 6 ) {
868 for(A = 1; A <= BoardSizeY; A++) {
869 for(B = 1; B <= BoardSizeX; B++) {
870 if(Squares[B][A] != 0 ) {
871 Board.showpic[Grafix[B][A]].Visible = False;
872 MOVE(0, Board.showpic[Grafix[B][A]], 0, 0);
873 Squares[B][A] = 0;
875 Grafix[B][A] = -1;
876 } // Next B;
877 } // Next A;
878 if(Drop == 1 ) {
879 for(A = 1; A <= Capture * 2; A++) {
880 InHand[A] = 0;
881 Board.HandPic[A].Visible = False;
882 strcpy(Board.Held[A].Caption, "");
883 } // Next A;
885 WhitePrince = 0; BlackPrince = 0;
886 strcpy(Board.LastMove.Caption, "");
887 MoveCount = 0; TurnCount = 0;
888 strcpy(Board.BlackClock.Caption, "00:00:00");
889 strcpy(Board.WhiteClock.Caption, "00:00:00");
890 Board.Timer1.Enabled = False;
894 void ClearInfo ()
896 INT JJ, KK, MM, NN;
897 if(CapturedPiece != 1 ) {
898 Changed = Changed + 1;
899 Clearing[Changed].File = File;
900 Clearing[Changed].Rank = Rank;
902 CapturedPiece = 0;
903 for(JJ = 1; JJ <= BoardSizeY; JJ++) {
904 for(KK = 1; KK <= BoardSizeX; KK++) {
905 for(MM = 1; MM <= Attacker[KK][JJ]; MM++) {
906 if(BanMap[KK][JJ].Info[MM].File == File && BanMap[KK][JJ].Info[MM].Rank == Rank ) {
907 if(Attacker[KK][JJ] == 1 ) {
908 BanMap[KK][JJ].Info[MM].File = 0;
909 BanMap[KK][JJ].Info[MM].Rank = 0;
910 BanMap[KK][JJ].Info[MM].Piece = 0;
911 } else {
912 for(NN = MM; NN <= Attacker[KK][JJ] - 1; NN++) {
913 BanMap[KK][JJ].Info[NN].File = BanMap[KK][JJ].Info[NN + 1].File;
914 BanMap[KK][JJ].Info[NN].Rank = BanMap[KK][JJ].Info[NN + 1].Rank;
915 BanMap[KK][JJ].Info[NN].Piece = BanMap[KK][JJ].Info[NN + 1].Piece;
916 } // Next NN;
918 Attacker[KK][JJ] = Attacker[KK][JJ] - 1;
919 if(Squares[File][Rank] < 0 ) {
920 BanMap[KK][JJ].WhiteNum = BanMap[KK][JJ].WhiteNum - 1;
921 } else {
922 if(Squares[File][Rank] > 0 ) {
923 BanMap[KK][JJ].BlackNum = BanMap[KK][JJ].BlackNum - 1;
927 } // Next MM;
928 } // Next KK;
929 } // Next JJ;
933 void ClearLegal ()
934 { // default DragDrop handler in almost all visible objects.
935 // MouseUp in Form if LegalMoves = 0, also triggered by key 192
936 INT A, B;
937 if(Notice == 0 && Checked != 1 ) strcpy(Board.PieceID.Caption, "");
938 if(GameOver == 1 ) {
939 strcpy(Board.NextMove.Caption, "Game Over");
940 } else {
941 if(!strcmp(Turn, "White") ) strcpy(Board.NextMove.Caption, "White to Move"); else strcpy(Board.NextMove.Caption, "Black to Move");
943 if(SeeMove == 1 ) Board.Refresh();
944 for(A = 1; A <= BoardSizeY; A++) {
945 for(B = 1; B <= BoardSizeX; B++) {
946 Legal[B][A] = 0;
947 AreaOK[B][A] = 0;
948 } // Next B;
949 } // Next A;
952 void Clock ()
953 { // Handler for Timer1 interrupts.
954 if(Timing == 0 && GameOver != 1 ) {
955 if((!strcmp(Turn, "White") && Level > 0) || (!strcmp(Turn, "Black") && Level == 0) ) {
956 strcpy(ElapsedSTR, Board.WhiteClock.Caption);
957 SetClock();
958 strcpy(Board.WhiteClock.Caption, ElapsedSTR);
959 } else {
960 strcpy(ElapsedSTR, Board.BlackClock.Caption);
961 SetClock();
962 strcpy(Board.BlackClock.Caption, ElapsedSTR);
967 void ClocksOff ()
968 { // Menu function.
969 Board.Timer1.Enabled = False;
970 strcpy(Board.WhiteClock.Caption, "00:00:00");
971 strcpy(Board.BlackClock.Caption, "00:00:00");
972 Timing = 1;
973 Board.WhiteClock.Visible = False;
974 Board.BlackClock.Visible = False;
975 Board.MnuClockOff.Enabled = False;
976 Board.MnuClockOn.Enabled = True;
977 Board.MnuClockOff.Checked = True;
978 Board.MnuClockOn.Checked = False;
981 void ClocksOn ()
982 { // Menu function.
983 Board.Timer1.Enabled = True;
984 strcpy(Board.WhiteClock.Caption, "00:00:00");
985 strcpy(Board.BlackClock.Caption, "00:00:00");
986 Timing = 0;
987 Board.WhiteClock.Visible = True;
988 Board.BlackClock.Visible = True;
989 Board.MnuClockOff.Enabled = True;
990 Board.MnuClockOn.Enabled = False;
991 Board.MnuClockOn.Checked = True;
992 Board.MnuClockOff.Checked = False;
995 void CompLion ()
997 INT DeadPiece;
998 CompLionTest = 1;
999 AddLegalMove();
1000 DeadPiece = Squares[NewFile][NewRank];
1001 Squares[NewFile][NewRank] = Squares[InitFile][InitRank];
1002 Squares[InitFile][InitRank] = 0;
1003 for(YYY = NewRank - 1; YYY <= NewRank + 1; YYY++) {
1004 for(XXX = NewFile - 1; XXX <= NewFile + 1; XXX++) {
1005 if(XXX > 0 && XXX <= BoardSizeX && YYY > 0 && YYY <= BoardSizeY ) {
1006 if(Squares[XXX][YYY] == 0 || Sgn(Squares[XXX][YYY]) != Sgn(Squares[NewFile][NewRank]) ) {
1007 AddLionMove();
1008 ExtraCapture[LegalMoves].Piece = DeadPiece;
1009 ExtraCapture[LegalMoves].File = NewFile;
1010 ExtraCapture[LegalMoves].Rank = NewRank;
1013 } // Next XXX;
1014 } // Next YYY;
1015 Squares[InitFile][InitRank] = Squares[NewFile][NewRank];
1016 Squares[NewFile][NewRank] = DeadPiece;
1019 void CompLionPower ()
1021 INT WWW, DeadPiece;
1022 CompLionTest = 1;
1023 AddLegalMove();
1024 DeadPiece = Squares[NewFile][NewRank];
1025 Squares[NewFile][NewRank] = Squares[InitFile][InitRank];
1026 Squares[InitFile][InitRank] = 0;
1027 for(WWW = -1; WWW <= 1; WWW += 2) {
1028 XXX = NewFile + (FileInc * WWW);
1029 YYY = NewRank + (RankInc * WWW);
1030 if(XXX > 0 && XXX <= BoardSizeX && YYY > 0 && YYY <= BoardSizeY ) {
1031 if(Squares[XXX][YYY] == 0 || Sgn(Squares[XXX][YYY]) != Sgn(Squares[NewFile][NewRank]) ) {
1032 AddLionMove();
1033 ExtraCapture[LegalMoves].Piece = DeadPiece;
1034 ExtraCapture[LegalMoves].File = NewFile;
1035 ExtraCapture[LegalMoves].Rank = NewRank;
1038 } // Next WWW;
1039 Squares[InitFile][InitRank] = Squares[NewFile][NewRank];
1040 Squares[NewFile][NewRank] = DeadPiece;
1043 void CompMain ()
1045 INT A, B, BB, YZ, VX, TU, AB, CD, OldInfluence;
1046 if(Level != 0 && (!strcmp(Computer, "White") || !strcmp(Computer, "Black")) ) // Board.MnuSwitch.Enabled = True; else Board.MnuSwitch.Enabled = False;
1047 EnableNamedMenuItem("Setup.SwitchSides", True); else EnableNamedMenuItem("Setup.SwitchSides", False); // [HGM] added
1049 // Find Legal Moves;
1051 if(GameOver == 1 ) return;
1052 for(AA = 1; AA <= BoardSizeY; AA++) {
1053 for(BB = 1; BB <= BoardSizeX; BB++) {
1054 Comp[BB][AA] = Squares[BB][AA];
1055 } // Next BB;
1056 } // Next AA;
1057 CompMove = 1; LegalMoves = 0;
1058 for(YZ = 1; YZ <= BoardSizeY; YZ++) {
1059 for(VX = 1; VX <= BoardSizeX; VX++) {
1060 if(!strcmp(Turn, "White") ) {
1061 if(Squares[VX][YZ] < 0 ) {
1062 InitFile = VX; InitRank = YZ;
1063 I = Grafix[VX][YZ];
1064 Validate();
1065 Taken = 0;
1067 } else {
1068 if(Squares[VX][YZ] > 0 ) {
1069 InitFile = VX; InitRank = YZ;
1070 I = Grafix[VX][YZ];
1071 Validate();
1072 Taken = 0;
1075 } // Next VX;
1076 DoEvents();
1077 } // Next YZ;
1079 // Find Legal Drops;
1081 if(Drop == 1 ) {
1082 if((!strcmp(Turn, "Black") && Reverse == 0) || (!strcmp(Turn, "White") && Reverse == 1) ) {
1083 for(TU = 1; TU <= Capture; TU++) {
1084 ResetLegal();
1085 if(InHand[TU] > 0 ) {
1086 I = TU; InitFile = 0; InitRank = 0;
1087 HeldValid();
1088 DoEvents();
1090 } // Next TU;
1091 } else {
1092 for(TU = Capture + 1; TU <= Capture * 2; TU++) {
1093 if(InHand[TU] > 0 ) {
1094 ResetLegal();
1095 I = TU; InitFile = 0; InitRank = 0;
1096 HeldValid();
1097 DoEvents();
1099 } // Next TU;
1103 // Find Legal Emperor Moves;
1105 if(!strcmp(Choice, "Tai") || !strcmp(Choice, "Maka") ) {
1106 OldInfluence = Influence; CompMove = 0;
1107 if(WhiteEmperor == 1 && BlackEmperor == 1 ) AddEmperorAttack();
1108 if((!strcmp(Turn, "White") && WhiteEmperor == 1) || (!strcmp(Turn, "Black") && BlackEmperor == 1) ) {
1109 Influence = 2;
1110 for(AB = 1; AB <= BoardSizeY; AB++) {
1111 for(CD = 1; CD <= BoardSizeX; CD++) {
1112 InitFile = CD; InitRank = AB; Validate();
1113 } // Next CD;
1114 } // Next AB;
1115 FindEmperorMove();
1117 Influence = OldInfluence; CompMove = 1;
1120 FirstLegal = LegalMoves;
1121 if(FirstLegal < Level ) TestDepth = FirstLegal; else TestDepth = Level;
1122 if(LookMate == 1 ) ConsiderMate(); else ConsiderMove();
1123 Evaluate = 0; CompMove = 0; Influence = 0; EndMove = 0;
1124 if(Suggest == 1 ) { SuggestMove(); return; }
1125 if(GameOver == 1 ) return;
1126 if(Level > 1 ) LookAhead();
1128 // Make Best Move;
1130 for(AA = 1; AA <= BoardSizeY; AA++) {
1131 for(BB = 1; BB <= BoardSizeX; BB++) {
1132 Squares[BB][AA] = Comp[BB][AA];
1133 } // Next BB;
1134 } // Next AA;
1135 for(A = 1; A <= BoardSizeY; A++) {
1136 for(B = 1; B <= BoardSizeX; B++) {
1137 Legal[B][A] = 0;
1138 AreaOK[B][A] = 0;
1139 } // Next B;
1140 } // Next A;
1141 OldSeeMove = SeeMove; SeeMove = 0;
1142 if(LookMate == 1 ) return;
1143 if(CompLegal[BestMove].StartFile == 0 ) {
1144 InitFile = 0;
1145 DropTest = 1;
1146 TestDrop();
1147 } else {
1148 InitRank = CompLegal[BestMove].StartRank;
1149 InitFile = CompLegal[BestMove].StartFile;
1150 I = Grafix[InitFile][InitRank];
1151 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) Legal[CompLegal[BestMove].EndFile][CompLegal[BestMove].EndRank] = 1;
1152 Validate();
1154 SeeMove = OldSeeMove; CompMove = 1; Evaluate = 0; MakeMove = 1;
1155 File = CompLegal[BestMove].EndFile;
1156 Rank = CompLegal[BestMove].EndRank;
1157 if(InitFile == 0 ) {
1158 MakeDrop();
1159 DropTest = 0;
1160 } else {
1161 if(Pieces[abs(Squares[InitFile][InitRank])].special == 'L' || !strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Horned Falcon") || !strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Soaring Eagle") ) Legal[InitFile][InitRank] = 1;
1162 I = Grafix[InitFile][InitRank];
1163 if(Squares[File][Rank] == 0 ) {
1164 FormDrop();
1165 } else {
1166 NewIndex = Grafix[File][Rank];
1167 PicDrop();
1170 if(Taken == 1 && (!strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai")) ) {
1171 I = Grafix[File][Rank];
1172 Promote();
1173 } else {
1174 if(CompLegal[BestMove].StartPiece != CompLegal[BestMove].EndPiece && Squares[File][Rank] != 0 ) {
1175 I = Grafix[File][Rank];
1176 Promote();
1179 CompMove = 0; Evaluate = 0; LegalMoves = 0;
1180 if(Mate != 1 ) NextTurn2();
1183 void CompMate ()
1185 INT SS, TT, MateCheck;
1186 if(Squares[File][Rank] == 1 && !strcmp(Turn, "White") ) {
1187 if((abs(File - CompLegal[AA].EndFile) < 2 && abs(Rank - CompLegal[AA].EndRank) < 2) && BanMap[CompLegal[AA].EndFile][CompLegal[AA].EndRank].BlackNum < 2 && BanMap[CompLegal[AA].EndFile][CompLegal[AA].EndRank].WhiteNum > 0 && BanMap[File][Rank].WhiteNum > 0 && CompLegal[AA].EndPiece != -1 ) {
1188 MateCheck = 1;
1189 for(SS = Rank - 1; SS <= Rank + 1; SS++) {
1190 for(TT = File - 1; TT <= File + 1; TT++) {
1191 if(TT > 0 && TT <= BoardSizeX && SS > 0 && SS <= BoardSizeY && (SS != Rank || TT != File) ) {
1192 if(BanMap[TT][SS].WhiteNum == 0 && Squares[TT][SS] <= 0 ) MateCheck = 0;
1194 } // Next TT;
1195 } // Next SS;
1196 if(MateCheck == 1 ) WhiteTally = WhiteTally + 8888; else WhiteTally = WhiteTally + 20;
1197 } else {
1198 if(BanMap[File][Rank].WhiteNum > 0 && BanMap[CompLegal[AA].EndFile][CompLegal[AA].EndRank].BlackNum == 0 && CompLegal[AA].EndPiece != -1 ) WhiteTally = WhiteTally + 20;
1201 if(Squares[File][Rank] == -1 && !strcmp(Turn, "Black") ) {
1202 if(abs(File - CompLegal[AA].EndFile) < 2 && abs(Rank - CompLegal[AA].EndRank) < 2 && BanMap[CompLegal[AA].EndFile][CompLegal[AA].EndRank].WhiteNum < 2 && BanMap[CompLegal[AA].EndFile][CompLegal[AA].EndRank].BlackNum > 0 && BanMap[File][Rank].BlackNum > 0 && CompLegal[AA].EndPiece != 1 ) {
1203 MateCheck = 1;
1204 for(SS = Rank - 1; SS <= Rank + 1; SS++) {
1205 for(TT = File - 1; TT <= File + 1; TT++) {
1206 if(TT > 0 && TT <= BoardSizeX && SS > 0 && SS <= BoardSizeY && (SS != Rank || TT != File) ) {
1207 if(BanMap[TT][SS].BlackNum == 0 && Squares[TT][SS] >= 0 ) MateCheck = 0;
1209 } // Next TT;
1210 } // Next SS;
1211 if(MateCheck == 1 ) BlackTally = BlackTally + 8888; else BlackTally = BlackTally + 20;
1212 } else {
1213 if(BanMap[File][Rank].BlackNum > 0 && BanMap[CompLegal[AA].EndFile][CompLegal[AA].EndRank].WhiteNum == 0 && CompLegal[AA].EndPiece != 1 ) BlackTally = BlackTally + 20;
1218 void CompPromote ()
1220 ForceProm = 0; Taken = 0;
1221 if(!strcmp(Choice, "Micro") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai") ) {
1222 if(Squares[SeeFile][SeeRank] != 0 ) {
1223 if(Sgn(Squares[InitFile][InitRank]) != Sgn(Squares[SeeFile][SeeRank]) ) {
1224 Taken = 1; ForceProm = 1;
1225 CompPromote2();
1228 } else {
1229 if(Pieces[abs(Squares[InitFile][InitRank])].special == '1' ) {
1230 if(Squares[InitFile][InitRank] > 0 && SeeRank == 1 ) { ForceProm = 1; CompPromote2(); }
1231 if(Squares[InitFile][InitRank] < 0 && SeeRank == BoardSizeY ) { ForceProm = 1; CompPromote2(); }
1233 if(Pieces[abs(Squares[InitFile][InitRank])].special == '2' ) {
1234 if(Squares[InitFile][InitRank] > 0 && SeeRank < 3 ) { ForceProm = 1; CompPromote2(); }
1235 if(Squares[InitFile][InitRank] < 0 && SeeRank > BoardSizeY - 2 ) { ForceProm = 1; CompPromote2(); }
1237 if(Squares[InitFile][InitRank] > 0 && (SeeRank <= PromDotY || InitRank <= PromDotY) ) CompPromote2();
1238 if(Squares[InitFile][InitRank] < 0 && (SeeRank > BoardSizeY - PromDotY || InitRank > BoardSizeY - PromDotY) ) CompPromote2();
1242 void CompPromote2 ()
1244 if((strcmp(Choice, "Micro") && strcmp(Choice, "Tai") && strcmp(Choice, "Maka") && strcmp(Choice, "DaiDai")) || (Taken == 1) ) {
1245 if((ForceProm == 1 && Pieces[abs(Squares[InitFile][InitRank])].Promotes != 0) || Prom == 1 ) {
1246 CompLegal[LegalMoves].EndPiece = Pieces[abs(Squares[InitFile][InitRank])].Promotes;
1247 if(CompLegal[LegalMoves].StartPiece < 0 ) CompLegal[LegalMoves].EndPiece = 0 - CompLegal[LegalMoves].EndPiece;
1248 } else {
1249 if((Pieces[abs(Squares[InitFile][InitRank])].Promotes != 0) ) {
1250 LegalMoves = LegalMoves + 1;
1251 CompLegal[LegalMoves].StartFile = InitFile;
1252 CompLegal[LegalMoves].StartRank = InitRank;
1253 CompLegal[LegalMoves].EndFile = SeeFile;
1254 CompLegal[LegalMoves].EndRank = SeeRank;
1255 CompLegal[LegalMoves].StartPiece = Squares[InitFile][InitRank];
1256 CompLegal[LegalMoves].EndPiece = Pieces[abs(Squares[InitFile][InitRank])].Promotes;
1257 if(Squares[InitFile][InitRank] < 0 ) CompLegal[LegalMoves].EndPiece = 0 - CompLegal[LegalMoves].EndPiece;
1263 void CompTeach ()
1265 Board.MnuVer2.Enabled = False;
1266 Board.MnuVer1.Enabled = False;
1267 Board.MnuVer1.Checked = True;
1268 Board.MnuVer2.Checked = False;
1269 TeachVer = 1;
1270 if(!strcmp(Choice, "Tai") ) {
1271 Pieces[29].PrValue = 28; Pieces[100].Value = 28;
1272 } else {
1273 Pieces[29].PrValue = 28; Pieces[76].Value = 28;
1277 void CompTurn ()
1279 if(LegalMoves == 0 ) {
1280 strcpy(Board.Caption, Cap);
1281 if(!strcmp(Computer, Turn) ) {
1282 FirstSeeMove = SeeMove;
1283 SeeMove = 1;
1284 CompMain();
1289 void CompVComp ()
1291 do {
1292 CompMain();
1293 } while( !( GameOver == 1 || Mate == 1) );
1294 if(GameOver == 1 ) NextTurn2();
1295 GameOver = 0;
1298 void ConfigLoad ()
1299 { // WARNING: this does not allow values to be missing, as in the Basic code
1300 if(Loading != 1 ) {
1301 FILE *f4;
1302 if(f4 = fopen((sprintf(StringTmp, CONFIGFILE), StringTmp), "r")) { // [HGM] allow for failing
1303 fscanf(f4, "%d,%d,\"%[^\"]\",\"%[^\"]\",%d,%d,%d,%d,%d,\"%[^\"],%d", &SeeMove, &Timing, Computer, Threat, &AutoPromote, &Notate, &LionHawkVer, &TeachVer, &Eval, Grade, &ShowLast);
1304 fclose(f4);
1307 if(SeeMove == 1 ) {
1308 Board.MnuShowOn.Enabled = False;
1309 Board.MnuShowOn.Checked = True;
1310 Board.MnuShowOff.Enabled = True;
1311 Board.MnuShowOff.Checked = False;
1312 } else {
1313 Board.MnuShowOn.Enabled = True;
1314 Board.MnuShowOn.Checked = False;
1315 Board.MnuShowOff.Enabled = False;
1316 Board.MnuShowOff.Checked = True;
1318 MarkMenuItem("Moves.ShowLegal", SeeMove == 1); // [HGM] added
1319 ConfigLoad2();
1320 if(ShowLast == 1 ) {
1321 Board.MnuShowLastOn.Enabled = False;
1322 Board.MnuShowLastOn.Checked = True;
1323 Board.MnuShowLastOff.Enabled = True;
1324 Board.MnuShowLastOff.Checked = False;
1325 } else {
1326 Board.MnuShowLastOn.Enabled = True;
1327 Board.MnuShowLastOn.Checked = False;
1328 Board.MnuShowLastOff.Enabled = False;
1329 Board.MnuShowLastOff.Checked = True;
1331 MarkMenuItem("Moves.Flash", ShowLast == 1); // [HGM] added
1332 if(!strcmp(Threat, "On") ) {
1333 Board.MnuThreatOn.Enabled = False;
1334 Board.MnuThreatOn.Checked = True;
1335 Board.MnuThreatOff.Enabled = True;
1336 Board.MnuThreatOff.Checked = False;
1337 } else {
1338 Board.MnuThreatOn.Enabled = True;
1339 Board.MnuThreatOn.Checked = False;
1340 Board.MnuThreatOff.Enabled = False;
1341 Board.MnuThreatOff.Checked = True;
1343 MarkMenuItem("Moves.ShowThreat", !strcmp(Threat, "On")); // [HGM] added
1345 if(strcmp(Choice, "Whale") && strcmp(Choice, "Maka") && strcmp(Choice, "Tai") && strcmp(Choice, "DaiDai") && strcmp(Choice, "Tori") && strcmp(Choice, "Micro") ) {
1346 if(AutoPromote == 1 ) {
1347 Board.MnuAutoOn.Enabled = False;
1348 Board.MnuAutoOn.Checked = True;
1349 Board.MnuAutoOff.Enabled = True;
1350 Board.MnuAutoOff.Checked = False;
1351 } else {
1352 Board.MnuAutoOn.Enabled = True;
1353 Board.MnuAutoOn.Checked = False;
1354 Board.MnuAutoOff.Enabled = False;
1355 Board.MnuAutoOff.Checked = True;
1357 MarkMenuItem("Setup.AutoProm", AutoPromote == 1); // [HGM] added
1360 if(Eval == 1 ) {
1361 Board.MnuEvalOn.Enabled = False;
1362 Board.MnuEvalOn.Checked = True;
1363 Board.MnuEvalOff.Enabled = True;
1364 Board.MnuEvalOff.Checked = False;
1365 } else {
1366 Board.MnuEvalOn.Enabled = True;
1367 Board.MnuEvalOn.Checked = False;
1368 Board.MnuEvalOff.Enabled = False;
1369 Board.MnuEvalOff.Checked = True;
1371 MarkMenuItem("Moves.Evaluate", Eval == 1); // [HGM] added
1373 if(!strcmp(Choice, "Tenjiku") ) Board.MnuEvalOn.Enabled = False;
1374 if(!strcmp(Choice, "Tenjiku") ) {
1375 if(LionHawkVer == 1 ) {
1376 Board.MnuLVer1.Enabled = False;
1377 Board.MnuLVer1.Checked = True;
1378 Board.MnuLVer2.Enabled = True;
1379 Board.MnuLVer2.Checked = False;
1380 } else {
1381 Board.MnuLVer1.Enabled = True;
1382 Board.MnuLVer1.Checked = False;
1383 Board.MnuLVer2.Enabled = False;
1384 Board.MnuLVer2.Checked = True;
1386 MarkMenuItem("Setup.LionHawk", LionHawkVer == 2); // [HGM] added
1388 if(!strcmp(Choice, "Maka") || !strcmp(Choice, "Tai") ) {
1389 if(TeachVer == 1 ) {
1390 Board.MnuVer1.Enabled = False;
1391 Board.MnuVer1.Checked = True;
1392 Board.MnuVer2.Enabled = True;
1393 Board.MnuVer2.Checked = False;
1394 } else {
1395 Board.MnuVer1.Enabled = True;
1396 Board.MnuVer1.Checked = False;
1397 Board.MnuVer2.Enabled = False;
1398 Board.MnuVer2.Checked = True;
1400 MarkMenuItem("Setup.TeachingKing", TeachVer == 2); // [HGM] added
1402 if(Notate == 1 ) {
1403 Board.NotTop.Visible = True;
1404 Board.NotSide.Visible = True;
1405 Board.MnuNotOff.Enabled = True;
1406 Board.MnuNotOff.Checked = False;
1407 Board.MnuNotOn.Enabled = False;
1408 Board.MnuNotOn.Checked = True;
1409 } else {
1410 Board.NotTop.Visible = False;
1411 Board.NotSide.Visible = False;
1412 Board.MnuNotOff.Enabled = False;
1413 Board.MnuNotOff.Checked = True;
1414 Board.MnuNotOn.Enabled = True;
1415 Board.MnuNotOn.Checked = False;
1417 MarkMenuItem("Setup.Notation", Notate == 1); // [HGM] added
1418 SetDifficulty();
1421 void ConfigLoad2 ()
1423 if(!strcmp(Choice, "Tenjiku") ) strcpy(Computer, "None");
1424 if(!strcmp(Computer, "White") || !strcmp(Computer, "Both") ) {
1425 Board.MnuWhitePlayer.Enabled = True;
1426 Board.MnuWhitePlayer.Checked = False;
1427 Board.MnuWhiteComp.Enabled = False;
1428 Board.MnuWhiteComp.Checked = True;
1429 Board.MnuBlackPlayer.Enabled = False;
1430 Board.MnuBlackPlayer.Checked = True;
1431 Board.MnuBlackComp.Enabled = True;
1432 Board.MnuBlackComp.Checked = False;
1434 if(!strcmp(Computer, "Black") ) {
1435 Board.MnuWhitePlayer.Enabled = False;
1436 Board.MnuWhitePlayer.Checked = True;
1437 Board.MnuWhiteComp.Enabled = True;
1438 Board.MnuWhiteComp.Checked = False;
1439 Board.MnuBlackPlayer.Enabled = True;
1440 Board.MnuBlackPlayer.Checked = False;
1441 Board.MnuBlackComp.Enabled = False;
1442 Board.MnuBlackComp.Checked = True;
1444 if(!strcmp(Computer, "") || !strcmp(Computer, "None") ) {
1445 Board.MnuWhitePlayer.Enabled = False;
1446 Board.MnuWhitePlayer.Checked = True;
1447 Board.MnuWhiteComp.Enabled = True;
1448 Board.MnuWhiteComp.Checked = False;
1449 Board.MnuBlackPlayer.Enabled = False;
1450 Board.MnuBlackPlayer.Checked = True;
1451 Board.MnuBlackComp.Enabled = True;
1452 Board.MnuBlackComp.Checked = False;
1454 MarkMenuItem("Setup.CompWhite", !strcmp(Computer, "White") || !strcmp(Computer, "Both")); // [HGM] added
1455 MarkMenuItem("Setup.CompBlack", !strcmp(Computer, "Black") || !strcmp(Computer, "Both")); // [HGM] added
1456 if(!strcmp(Choice, "Tenjiku") ) {
1457 Eval = 0;
1458 Board.MnuWhiteComp.Enabled = False;
1459 Board.MnuBlackComp.Enabled = False;
1461 EnableNamedMenuItem("Setup.CompWhite", !!strcmp(Choice, "Tenjiku")); // [HGM] added
1462 EnableNamedMenuItem("Setup.CompBlack", !!strcmp(Choice, "Tenjiku")); // [HGM] added
1465 void ConfigSave ()
1466 { // Callen on Quit from menu.
1467 int Response;
1468 Response = MsgBox("Do you wish to save " LF "your Game Preferences?", 36, "");
1469 if(Response == 6 ) {
1470 FILE *f4;
1471 if(f4 = fopen((sprintf(StringTmp, CONFIGFILE), StringTmp), "w")) {
1472 fprintf(f4, "%d,%d,\"%s\",\"%s\",%d,%d,%d,%d,%d,\"%s\",%d\n", SeeMove, Timing, Computer, Threat, AutoPromote, Notate, LionHawkVer, TeachVer, Eval, Grade, ShowLast);
1473 fclose(f4);
1478 void ConsiderMate ()
1480 INT DD, EE, JJ, KK, PP, StartAA, EndAA, Steps;
1481 BestTally[0] = -999999; CompMove = 0; Influence = 3; Evaluate = 1;
1482 MakeMap();
1483 if(!strcmp(Turn, "Black") ) {
1484 Steps = -1;
1485 StartAA = LegalMoves;
1486 EndAA = 1;
1487 } else {
1488 Steps = 1;
1489 StartAA = 1;
1490 EndAA = LegalMoves;
1492 for(AA = StartAA; Steps > 0 ? AA <= EndAA : AA >= EndAA; AA += Steps) {
1493 WhiteTally = 0; BlackTally = 0;
1494 DoEvents();
1495 Evaluate = 1;
1496 for(JJ = 1; JJ <= BoardSizeY; JJ++) {
1497 for(KK = 1; KK <= BoardSizeX; KK++) {
1498 Squares[KK][JJ] = Comp[KK][JJ];
1499 } // Next KK;
1500 } // Next JJ;
1501 InitFile = CompLegal[AA].StartFile;
1502 InitRank = CompLegal[AA].StartRank;
1503 CompFile = CompLegal[AA].EndFile;
1504 CompRank = CompLegal[AA].EndRank;
1505 Evaluate = 0;
1506 FindInfluence();
1507 if(InitFile != 0 ) Squares[InitFile][InitRank] = 0;
1508 Squares[CompFile][CompRank] = CompLegal[AA].EndPiece;
1509 Evaluate = 1;
1510 for(PP = 1; PP <= Changed; PP++) {
1511 InitFile = Clearing[PP].File;
1512 InitRank = Clearing[PP].Rank;
1513 if(Squares[InitFile][InitRank] != 0 ) Validate();
1514 } // Next PP;
1515 Evaluate = 0;
1516 for(DD = 1; DD <= BoardSizeY; DD++) {
1517 for(EE = 1; EE <= BoardSizeX; EE++) {
1518 if(Squares[EE][DD] != 0 ) {
1519 if(BanMap[EE][DD].WhiteNum > 0 && (Squares[EE][DD] == 1 || (Squares[EE][DD] > 0 && BlackKing == 1 && (!strcmp(Pieces[abs(Squares[EE][DD])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Prince")))) ) BlackTally = -99999;
1520 if(BanMap[EE][DD].BlackNum > 0 && (Squares[EE][DD] == -1 || (Squares[EE][DD] < 0 && WhiteKing == 1 && (!strcmp(Pieces[abs(Squares[EE][DD])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Prince")))) ) WhiteTally = -99999;
1522 } // Next EE;
1523 } // Next DD;
1524 if(!strcmp(Turn, "White") && WhiteTally == 0 ) { BestTally[0] = 0; return; }
1525 if(!strcmp(Turn, "Black") && BlackTally == 0 ) { BestTally[0] = 0; return; }
1526 RestoreMap();
1527 } // Next AA;
1528 LegalMoves = 0;
1531 void ConsiderMove ()
1533 INT BB, DD, EE, FF, JJ, KK, PP, QQ, JJJ, KKK, BlackLoss, WhiteLoss, HighBlackLoss, HighWhiteLoss;
1534 // Evaluate Legal Moves;
1536 BestTally[0] = -999999; CompMove = 0; Influence = 3; Evaluate = 1;
1537 if(Level > 0 ) {
1538 for(BB = 1; BB <= Level + 1; BB++) {
1539 BestTally[BB] = -999999;
1540 OldKingTally[BB] = 0;
1541 ECapture[BB].Piece = 0;
1542 } // Next BB;
1544 MakeMap();
1545 for(AA = 1; AA <= LegalMoves; AA++) {
1546 KingTally[AA] = 0; WhiteTally = 0; BlackTally = 0;
1547 DoEvents();
1548 Evaluate = 1;
1549 for(JJ = 1; JJ <= BoardSizeY; JJ++) {
1550 for(KK = 1; KK <= BoardSizeX; KK++) {
1551 Squares[KK][JJ] = Comp[KK][JJ];
1552 } // Next KK;
1553 } // Next JJ;
1554 InitFile = CompLegal[AA].StartFile;
1555 InitRank = CompLegal[AA].StartRank;
1556 CompFile = CompLegal[AA].EndFile;
1557 CompRank = CompLegal[AA].EndRank;
1558 if(!strcmp(Choice, "Maka") || !strcmp(Choice, "Tai") ) {
1559 if(!strcmp(Turn, "Black") && !strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) BlackTally = BlackTally - 20;
1560 if(!strcmp(Turn, "White") && !strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) WhiteTally = WhiteTally - 20;
1562 if(!strcmp(Choice, "Shogi") && TurnCount <= 1 ) {
1563 if(InitFile == 6 && InitRank == 1 ) KingTally[AA] = KingTally[AA] - 5;
1564 if(InitFile == 5 && InitRank == 1 ) KingTally[AA] = KingTally[AA] - 2;
1565 if((InitRank == 3 || InitRank == 7) ) KingTally[AA] = KingTally[AA] + 1;
1566 if(InitFile == 4 && InitRank == 9 ) KingTally[AA] = KingTally[AA] - 5;
1567 if(InitFile == 5 && InitRank == 9 ) KingTally[AA] = KingTally[AA] - 2;
1568 if((InitFile == 2 && InitRank == 3) || (InitFile == 8 && InitRank == 7) ) KingTally[AA] = KingTally[AA] + 4;
1570 if(Drop == 1 && Level == 0 ) {
1571 if(!strcmp(Turn, "Black") && Squares[CompFile][CompRank] < 0 ) {
1572 if(Pieces[abs(Squares[CompFile][CompRank])].Promotes == 0 && Pieces[abs(Squares[CompFile][CompRank])].PrGraphic > 0 )
1573 BlackTally = BlackTally + (Pieces[Pieces[abs(Squares[CompFile][CompRank])].PrGraphic].Value * 10);
1574 else BlackTally = BlackTally + (Pieces[abs(Squares[CompFile][CompRank])].Value * 10);
1576 if(!strcmp(Turn, "White") && Squares[CompFile][CompRank] > 0 ) {
1577 if(Pieces[abs(Squares[CompFile][CompRank])].Promotes == 0 && Pieces[abs(Squares[CompFile][CompRank])].PrGraphic > 0 )
1578 WhiteTally = WhiteTally + (Pieces[Pieces[abs(Squares[CompFile][CompRank])].PrGraphic].Value * 10);
1579 else WhiteTally = WhiteTally + (Pieces[abs(Squares[CompFile][CompRank])].Value * 10);
1582 if(Drop == 1 && Level > 1 ) {
1583 if(!strcmp(Turn, "Black") && Squares[CompFile][CompRank] < 0 ) {
1584 if(Pieces[abs(Squares[CompFile][CompRank])].Promotes == 0 && Pieces[abs(Squares[CompFile][CompRank])].PrGraphic > 0 )
1585 KingTally[AA] = KingTally[AA] + (Pieces[Pieces[abs(Squares[CompFile][CompRank])].PrGraphic].Value * 10);
1586 else KingTally[AA] = KingTally[AA] + (Pieces[abs(Squares[CompFile][CompRank])].Value * 10);
1588 if(!strcmp(Turn, "White") && Squares[CompFile][CompRank] > 0 ) {
1589 if(Pieces[abs(Squares[CompFile][CompRank])].Promotes == 0 && Pieces[abs(Squares[CompFile][CompRank])].PrGraphic > 0 )
1590 KingTally[AA] = KingTally[AA] + (Pieces[Pieces[abs(Squares[CompFile][CompRank])].PrGraphic].Value * 10);
1591 else KingTally[AA] = KingTally[AA] + (Pieces[abs(Squares[CompFile][CompRank])].Value * 10);
1594 if((TurnCount < 4 && BoardSizeY > 7) || TurnCount < 2 ) KingTally[AA] = KingTally[AA] + 4 - (Rnd() * 8);
1595 KingSafety();
1596 Evaluate = 0;
1597 FindInfluence();
1598 if(InitFile != 0 ) Squares[InitFile][InitRank] = 0;
1599 if(ExtraCapture[AA].Piece != 0 ) Squares[ExtraCapture[AA].File][ExtraCapture[AA].Rank] = 0;
1600 Squares[CompFile][CompRank] = CompLegal[AA].EndPiece;
1601 Evaluate = 1;
1602 for(PP = 1; PP <= Changed; PP++) {
1603 InitFile = Clearing[PP].File;
1604 InitRank = Clearing[PP].Rank;
1605 if(Squares[InitFile][InitRank] != 0 ) Validate();
1606 } // Next PP;
1607 Evaluate = 0;
1608 PawnMates();
1609 if(!strcmp(Turn, "Black") && BanMap[CompFile][CompRank].WhiteNum > 0 && BanMap[CompFile][CompRank].BlackNum == 0 && Comp[CompFile][CompRank] >= 0 ) BlackTally = BlackTally - 999;
1610 if(!strcmp(Turn, "White") && BanMap[CompFile][CompRank].BlackNum > 0 && BanMap[CompFile][CompRank].WhiteNum == 0 && Comp[CompFile][CompRank] <= 0 ) WhiteTally = WhiteTally - 999;
1612 for(DD = 1; DD <= BoardSizeY; DD++) {
1613 for(EE = 1; EE <= BoardSizeX; EE++) {
1614 if(Squares[EE][DD] != 0 ) {
1615 if(Squares[EE][DD] == 1 || (Squares[EE][DD] > 1 && !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Emperor")) || (Squares[EE][DD] > 0 && BlackKing == 1 && (!strcmp(Pieces[abs(Squares[EE][DD])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Prince"))) ) BlackTally = BlackTally + 9999;
1616 if(Squares[EE][DD] == -1 || (Squares[EE][DD] < -1 && !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Emperor")) || (Squares[EE][DD] < 0 && WhiteKing == 1 && (!strcmp(Pieces[abs(Squares[EE][DD])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Prince"))) ) WhiteTally = WhiteTally + 9999;
1618 if(ExtraCapture[AA].Piece == 0 || ExtraCapture[AA].File != EE || ExtraCapture[AA].Rank != DD ) {
1619 if(Squares[EE][DD] < 0 ) WhiteTally = WhiteTally + (Pieces[abs(Squares[EE][DD])].Value * 10);
1620 if(Squares[EE][DD] > 0 ) BlackTally = BlackTally + (Pieces[abs(Squares[EE][DD])].Value * 10);
1622 if(!strcmp(Choice, "Tai") || !strcmp(Choice, "Maka") ) {
1623 if(!strcmp(Turn, "Black") ) {
1624 if(Squares[EE][DD] > 0 ) {
1625 if(BlackEmperor == 0 && WhiteEmperor == 1 && BanMap[EE][DD].BlackNum == 0 ) BlackTally = BlackTally - (Pieces[abs(Squares[EE][DD])].Value * 10);
1626 if(!strcmp(Pieces[abs(Squares[EE][DD])].Name, "Emperor") && BanMap[EE][DD].WhiteNum > 0 ) BlackTally = BlackTally - (Pieces[abs(Squares[EE][DD])].Value * 20);
1627 if(!strcmp(Pieces[abs(Squares[EE][DD])].Name, "Emperor") && WhiteEmperor == 1 && (EE != WhiteEmpX || DD != WhiteEmpY) && BanMap[EE][DD].BlackNum == 0 ) BlackTally = BlackTally - (Pieces[abs(Squares[EE][DD])].Value * 20);
1629 } else {
1630 if(Squares[EE][DD] < 0 ) {
1631 if(WhiteEmperor == 0 && BlackEmperor == 1 && BanMap[EE][DD].WhiteNum == 0 ) WhiteTally = WhiteTally - (Pieces[abs(Squares[EE][DD])].Value * 10);
1632 if(!strcmp(Pieces[abs(Squares[EE][DD])].Name, "Emperor") && BanMap[EE][DD].BlackNum > 0 ) WhiteTally = WhiteTally - (Pieces[abs(Squares[EE][DD])].Value * 20);
1633 if(!strcmp(Pieces[abs(Squares[EE][DD])].Name, "Emperor") && BlackEmperor == 1 && (EE != BlackEmpX || DD != BlackEmpY) && BanMap[EE][DD].WhiteNum == 0 ) WhiteTally = WhiteTally - (Pieces[abs(Squares[EE][DD])].Value * 20);
1637 if(BanMap[EE][DD].BlackNum == 0 && BanMap[EE][DD].WhiteNum > 0 ) {
1638 WhiteTally = 1 + abs((BoardSizeY / 2) + .5 - DD) / 2 + WhiteTally;
1639 if(Squares[EE][DD] < 0 ) WhiteTally = WhiteTally + 1;
1640 if(Squares[EE][DD] > 0 && !strcmp(Turn, "Black") ) BlackTally = BlackTally - (Pieces[abs(Squares[EE][DD])].Value * 10);
1641 if(Squares[EE][DD] == 1 && !strcmp(Turn, "Black") && Level > 1 ) KingTally[AA] = -99999;
1642 if(Squares[EE][DD] > 0 && !strcmp(Turn, "Black") && Level == 0 ) BlackTally = BlackTally + (Pieces[abs(Squares[EE][DD])].Value);
1644 if(BanMap[EE][DD].WhiteNum == 0 && BanMap[EE][DD].BlackNum > 0 ) {
1645 BlackTally = 1 + abs((BoardSizeY / 2) + .5 - DD) / 2 + BlackTally;
1646 if(Squares[EE][DD] > 0 ) BlackTally = BlackTally + 1;
1647 if(Squares[EE][DD] == -1 && !strcmp(Turn, "White") && Level > 1 ) KingTally[AA] = -99999;
1648 if(Squares[EE][DD] < 0 && !strcmp(Turn, "White") ) WhiteTally = WhiteTally - (Pieces[abs(Squares[EE][DD])].Value * 10);
1649 if(Squares[EE][DD] < 0 && !strcmp(Turn, "White") && Level == 0 ) WhiteTally = WhiteTally + (Pieces[abs(Squares[EE][DD])].Value);
1651 if(BanMap[EE][DD].WhiteNum > 0 && BanMap[EE][DD].BlackNum > 0 ) {
1652 if(Squares[EE][DD] > 0 && !strcmp(Turn, "Black") ) {
1653 LionAttack = 0;
1654 if((!strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Tai")) ) {
1655 for(JJJ = DD - 1; JJJ <= DD + 1; JJJ++) {
1656 for(KKK = EE - 1; KKK <= EE + 1; KKK++) {
1657 if(JJJ > 0 && JJJ < BoardSizeY && KKK > 0 && KKK < BoardSizeX ) {
1658 if(Squares[KKK][JJJ] < 0 ) {
1659 if(Pieces[abs(Squares[KKK][JJJ])].special == 'L' ) LionAttack = 1;
1662 } // Next KKK;
1663 } // Next JJJ;
1665 if(LionAttack == 1 ) {
1666 BlackTally = BlackTally - (Pieces[abs(Squares[EE][DD])].Value * 10);
1667 LionAttack = 0;
1668 } else {
1669 for(QQ = 1; QQ <= Attacker[EE][DD]; QQ++) {
1670 if(BanMap[EE][DD].Info[QQ].Piece != 0 ) {
1671 if(BanMap[EE][DD].Info[QQ].Piece < 0 && (Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value < LowWhite[EE][DD] || LowWhite[EE][DD] == 0) ) {
1672 LowWhite[EE][DD] = Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value;
1673 if(Level < 2 ) LowWhite[EE][DD] = LowWhite[EE][DD] - 1;
1675 if(BanMap[EE][DD].WhiteNum > 1 && BanMap[EE][DD].Info[QQ].Piece > 0 && Level > 0 ) {
1676 if(Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value < LowBlack[EE][DD] || LowBlack[EE][DD] == 0 ) LowBlack[EE][DD] = Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value;
1679 } // Next QQ;
1680 BlackLoss = ((Pieces[abs(Squares[EE][DD])].Value + LowBlack[EE][DD] - LowWhite[EE][DD]) * 10);
1681 // [HGM] The line below looks fishy
1682 if(Squares[EE][DD] == 1 || !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Emperor") || (BlackKing == 1 && !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Prince")) ) { BlackLoss = 29999; if(Level > 0 ) KingTally[AA] = -99999; }
1683 if(BlackLoss > HighBlackLoss ) HighBlackLoss = BlackLoss;
1686 if(Squares[EE][DD] < -1 && !strcmp(Turn, "Black") ) BlackTally = BlackTally + (Pieces[abs(Squares[EE][DD])].Value / 4);
1687 if(Squares[EE][DD] < 0 && !strcmp(Turn, "White") ) {
1688 LionAttack = 0;
1689 if((!strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Tai")) ) {
1690 for(JJJ = DD - 1; JJJ <= DD + 1; JJJ++) {
1691 for(KKK = EE - 1; KKK <= EE + 1; KKK++) {
1692 if(JJJ > 0 && JJJ < BoardSizeY && KKK > 0 && KKK < BoardSizeX ) {
1693 if(Squares[KKK][JJJ] > 0 ) {
1694 if(Pieces[abs(Squares[KKK][JJJ])].special == 'L' ) LionAttack = 1;
1697 } // Next KKK;
1698 } // Next JJJ;
1700 if(LionAttack == 1 ) {
1701 WhiteTally = WhiteTally - (Pieces[abs(Squares[EE][DD])].Value * 10);
1702 LionAttack = 0;
1703 } else {
1704 for(QQ = 1; QQ <= Attacker[EE][DD]; QQ++) {
1705 if(BanMap[EE][DD].Info[QQ].Piece != 0 ) {
1706 if(BanMap[EE][DD].Info[QQ].Piece > 0 && (Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value < LowBlack[EE][DD] || LowBlack[EE][DD] == 0) ) {
1707 LowBlack[EE][DD] = Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value;
1708 if(Level < 2 ) LowWhite[EE][DD] = LowWhite[EE][DD] - 1;
1710 if(BanMap[EE][DD].BlackNum > 1 && BanMap[EE][DD].Info[QQ].Piece < 0 && Level > 0 ) {
1711 if(Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value < LowWhite[EE][DD] || LowWhite[EE][DD] == 0 ) LowWhite[EE][DD] = Pieces[abs(BanMap[EE][DD].Info[QQ].Piece)].Value;
1714 } // Next QQ;
1715 WhiteLoss = ((Pieces[abs(Squares[EE][DD])].Value + LowWhite[EE][DD] - LowBlack[EE][DD]) * 10);
1716 // [HGM] Looks again fishy, as Prince and Crown Prince are not equivalent
1717 if(Squares[EE][DD] == -1 || !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Emperor") || (WhiteKing == 1 && !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[EE][DD])].Name, "Prince")) ) { WhiteLoss = 29999; if(Level > 0 ) KingTally[AA] = -99999; }
1718 if(WhiteLoss > HighWhiteLoss ) HighWhiteLoss = WhiteLoss;
1721 if(Squares[EE][DD] > 1 && !strcmp(Turn, "White") ) WhiteTally = WhiteTally + (Pieces[abs(Squares[EE][DD])].Value / 4);
1723 File = EE; Rank = DD; CompMate();
1724 LowWhite[EE][DD] = 0; LowBlack[EE][DD] = 0;
1725 } // Next EE;
1726 } // Next DD;
1727 if(Drop == 1 ) {
1728 for(FF = 1; FF <= Capture; FF++) {
1729 BlackTally = BlackTally + (Pieces[abs(CapRef[FF])].Value * 10.5) * (InHand[FF]);
1730 WhiteTally = WhiteTally + (Pieces[abs(CapRef[FF + Capture])].Value * 10.5) * (InHand[FF + Capture]);
1731 } // Next FF;
1732 if(CompLegal[AA].StartFile == 0 ) {
1733 if(!strcmp(Turn, "White") ) {
1734 WhiteTally = WhiteTally - Pieces[abs(CompLegal[AA].StartPiece)].Value * 10.5;
1735 } else {
1736 BlackTally = BlackTally - Pieces[abs(CompLegal[AA].StartPiece)].Value * 10.5;
1740 BlackTally = BlackTally - HighBlackLoss; HighBlackLoss = 0;
1741 WhiteTally = WhiteTally - HighWhiteLoss; HighWhiteLoss = 0;
1742 if(Level > 0 && Rnd() < .5 ) {
1743 if(!strcmp(Turn, "White") ) WhiteTally = WhiteTally + Int(Rnd() * 2) + 1; else BlackTally = BlackTally + Int(Rnd() * 2) + 1;
1745 if(Level > 1 ) {
1746 if(!strcmp(Turn, "White") && (WhiteTally - BlackTally) + KingTally[AA] > BestTally[TestDepth] ) {
1747 BestTally[Level + 1] = (WhiteTally - BlackTally) + KingTally[AA]; BestMove = AA; ReorderMoves();
1749 if(!strcmp(Turn, "Black") && (BlackTally - WhiteTally) + KingTally[AA] > BestTally[TestDepth] ) {
1750 BestTally[Level + 1] = (BlackTally - WhiteTally) + KingTally[AA]; BestMove = AA; ReorderMoves();
1752 } else {
1753 if(Level == 1 ) {
1754 if(!strcmp(Turn, "White") && WhiteTally - BlackTally + KingTally[AA] > BestTally[1] ) {
1755 BestTally[1] = WhiteTally - BlackTally + KingTally[AA]; BestMove = AA;
1756 if((!strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Tai")) && ExtraCapture[AA].Piece != 0 ) {
1757 LionVictim.Piece = ExtraCapture[AA].Piece;
1758 LionVictim.File = ExtraCapture[AA].File;
1759 LionVictim.Rank = ExtraCapture[AA].Rank;
1760 } else {
1761 LionVictim.Piece = 0;
1764 if(!strcmp(Turn, "Black") && BlackTally - WhiteTally + KingTally[AA] > BestTally[1] ) {
1765 BestTally[1] = BlackTally - WhiteTally + KingTally[AA]; BestMove = AA;
1766 if((!strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Tai")) && ExtraCapture[AA].Piece != 0 ) {
1767 LionVictim.Piece = ExtraCapture[AA].Piece;
1768 LionVictim.File = ExtraCapture[AA].File;
1769 LionVictim.Rank = ExtraCapture[AA].Rank;
1770 } else {
1771 LionVictim.Piece = 0;
1774 } else {
1775 if(!strcmp(Turn, "White") && WhiteTally - BlackTally + KingTally[AA] > BestTally[0] ) {
1776 BestTally[0] = WhiteTally - BlackTally + KingTally[AA];
1778 if(!strcmp(Turn, "Black") && BlackTally - WhiteTally + KingTally[AA] > BestTally[0] ) {
1779 BestTally[0] = BlackTally - WhiteTally + KingTally[AA];
1783 RestoreMap();
1784 ExtraCapture[AA].Piece = 0;
1785 } // Next AA;
1789 void Convert ()
1791 INT K, AB, CD, Strip, NoStrip;
1792 STRING LeftBit, RightBit; // were not declared, and thus integer in basic source???
1793 ClearLegal();
1794 DropTest = 0; Strip = 0; NoStrip = 0;
1795 I = TurnCount + 1;
1796 strcpy(ShortScore[I], CMoveSTR);
1797 K = strlen(ShortScore[I]);
1798 if(strstr(ShortScore[I], "*") == NULL || ShortScore[I][K-1] == '*' ) {
1799 for(AB = 1; AB <= BoardSizeY; AB++) {
1800 for(CD = 1; CD <= BoardSizeX; CD++) {
1801 if(Squares[CD][AB] == Score[TurnCount].IDStart && Score[TurnCount].IDStart != 0 && (File != CD || Rank != AB) ) {
1802 if(!strcmp(Pieces[abs(Squares[CD][AB])].sname, Pieces[abs(Score[TurnCount].IDStart)].sname) ) {
1803 FirstFile = CD; FirstRank = AB;
1804 TestOther();
1807 } // Next CD;
1808 } // Next AB;
1809 if(Testing123 != 1 ) {
1810 for(J = 1; J <= K; J++) {
1811 if(ShortScore[I][J-1] > 47 && ShortScore[I][J-1] < 58 && NoStrip == 0 && Strip == 0 ) {
1812 Strip = 1;
1813 strcpy(LeftBit, ShortScore[I]); LeftBit[J-1] = 0;
1815 if(Strip == 1 && ShortScore[I][J-1] > 96 && ShortScore[I][J-1] < 123 ) {
1816 NoStrip = 1; Strip = 0;
1817 strcpy(RightBit, ShortScore[I]+J);
1819 } // Next J;
1820 sprintf(ShortScore[I], "%s%s", LeftBit, RightBit);
1822 Testing123 = 0;
1826 void ConvertScore ()
1828 INT K, Strip, NoStrip, OldScore;
1829 STRING LeftBit, RightBit; // not declared in basic, thus integer???
1830 STRING TmpSTR;
1831 for(I = 1; I <= TurnCount; I++) {
1832 Strip = 0; NoStrip = 0;
1833 strcpy(ShortScore[I], Score[I].Caption);
1834 for(J = 1; J <= strlen(ShortScore[I]); J++) {
1835 if(ShortScore[I][J-1] == ' ' ) { strcpy(TmpSTR, ShortScore[I]+J); strcpy(ShortScore[I], TmpSTR); OldScore = 1; }
1836 } // Next J;
1837 if(OldScore == 1 ) {
1838 K = strlen(ShortScore[I]);
1839 if(strstr(ShortScore[I], "*") == NULL || ShortScore[I][K-1] == '*' ) {
1840 for(J = 1; J <= K; J++) {
1841 if(ShortScore[I][J-1] > 47 && ShortScore[I][J-1] < 58 && NoStrip == 0 && Strip == 0 ) {
1842 Strip = 1;
1843 strcpy(LeftBit, ShortScore[I]); LeftBit[J-1] = 0;
1845 if(Strip == 1 && ShortScore[I][J-1] > 96 && ShortScore[I][J-1] < 123 ) {
1846 NoStrip = 1; Strip = 0;
1847 strcpy(RightBit, ShortScore[I]+J);
1849 } // Next J;
1850 sprintf(ShortScore[I], "%s%s", LeftBit, RightBit);
1853 OldScore = 0;
1854 strcpy(Score[I].Caption, ShortScore[I]);
1855 } // Next I;
1858 void DiagramDrop ()
1860 INT K, L, Z;
1861 STRING TmpSTR;
1862 strcpy(BlackDrop[1], "|"); strcpy(BlackDrop[2], "|"); Z = 1;
1863 if(Reverse == 0 ) {
1864 J = 1; K = Capture;
1865 L = K + 1; M = K * 2;
1866 } else {
1867 L = 1; M = Capture;
1868 J = M + 1; K = M * 2;
1870 for(I = J; I <= K; I++) {
1871 if(InHand[I] > 0 ) {
1872 // FIXME is this correct? why trim?
1873 // BlackDrop[Z] = BlackDrop[Z] + " " + Left(Pieces[abs(CapRef[I])].sname, Len(Trim$(Pieces[abs(CapRef[I])].sname)));
1874 sprintf(TmpSTR, " %s", Pieces[abs(CapRef[I])].sname);
1875 strcat(BlackDrop[Z], TmpSTR);
1876 if(InHand[I] > 1 ) { strcpy(TmpSTR, BlackDrop[Z]); sprintf(BlackDrop[Z], "%sx%d", TmpSTR, InHand[I]); }
1877 if(strlen(BlackDrop[Z]) > 12 ) Z = 2;
1879 } // Next I;
1880 strcpy(WhiteDrop[2], "|"); strcpy(WhiteDrop[1], "|"); Z = 1;
1881 for(I = L; I <= M; I++) {
1882 if(InHand[I] > 0 ) {
1883 // WhiteDrop(Z) = WhiteDrop(Z) + " " + Left(Pieces[abs(CapRef[I])].sname, Len(Trim$(Pieces[abs(CapRef[I])].sname)))
1884 sprintf(TmpSTR, " %s", Pieces[abs(CapRef[I])].sname);
1885 strcat(WhiteDrop[Z], TmpSTR);
1886 if(InHand[I] > 1 ) { strcpy(TmpSTR, WhiteDrop[Z]); sprintf(WhiteDrop[Z], "%sx%d", TmpSTR, InHand[I]); }
1887 if(strlen(WhiteDrop[Z]) > 13 ) Z = 2;
1889 } // Next I;
1890 if(!strcmp(WhiteDrop[1], "|") ) strcat(WhiteDrop[1], " Nothing");
1891 if(!strcmp(BlackDrop[1], "|") ) strcat(BlackDrop[1], " Nothing");
1892 for(I = 1; I <= 2; I++) {
1893 strcpy(TmpSTR, WhiteDrop[I]); sprintf(WhiteDrop[I], "%-17s|", TmpSTR);
1894 strcpy(TmpSTR, BlackDrop[I]); sprintf(BlackDrop[I], "%-17s|", TmpSTR);
1895 } // Next I;
1898 void DiagramFile ()
1899 { // Menu function for large diagrams.
1900 FILE *f3;
1901 STRING TmpSTR;
1902 INT Short, DropStart, DropEnd;
1903 // TODO On Error Resume Next;
1904 strcpy(Board.CMDiagram.DialogTitle, "Create Text Diagram");
1905 Board.CMDiagram.Flags = 0x400L | 0x800L | 0x4L;
1906 Board.CMDiagram.Action = 2;
1907 if(Err == 32755 ) return;
1908 strcpy(SavedSTR, Board.CMDiagram.Filename);
1910 if( !(f3 = fopen(SavedSTR, "w")) ) return;
1912 if(!strcpy(GameName, "Whale") || !strcpy(GameName, "Early") || !strcpy(GameName, "Bird") || !strcpy(GameName, "Micro") || !strcpy(GameName, "Mini") || !strcpy(GameName, "") ) Short = 1; else Short = 0;
1913 if(Drop == 1 ) DiagramDrop();
1914 DropStart = 0; DropEnd = 0;
1915 if(Drop == 1 ) {
1916 DropStart = 1;
1917 DropEnd = BoardSizeY - 1;
1919 if(strcpy(GameName, "") ) {
1920 fprintf(f3, "%s Shogi\n", GameName);
1921 for(I = 1; I <= strlen(GameName) + 6; I++) {
1922 fprintf(f3, "=");
1923 } // Next I;
1925 // Print #3,
1926 fprintf(f3, "\n");
1927 fprintf(f3, " ");
1928 for(I = BoardSizeX; I >= 1; I--) {
1929 if(I < 10 ) fprintf(f3, " ");
1930 if(Short == 0 ) fprintf(f3, " ");
1931 fprintf(f3, "% d ", I);
1932 } // Next I;
1933 fprintf(f3, "\n");
1934 for(J = 1; J <= BoardSizeY; J++) {
1935 fprintf(f3, "+");
1936 for(I = 1; I <= BoardSizeX - 1; I++) {
1937 if(Short == 0 ) fprintf(f3, "------"); else fprintf(f3, "-----");
1938 } // Next I;
1939 if(Short == 0 ) fprintf(f3, "-----+"); else fprintf(f3, "----+");
1940 if(Drop == 1 ) {
1941 if(J == DropStart ) fprintf(f3, " White in hand:");
1942 if(J == DropStart + 1 ) fprintf(f3, " %s", WhiteDrop[1]);
1943 if(J == DropEnd + 1 ) fprintf(f3, " %s", BlackDrop[1]);
1944 if(J == DropEnd ) fprintf(f3, " Black in hand:");
1945 if(J == DropStart + 2 ) fprintf(f3, " +----------------+");
1947 fprintf(f3, "\n");
1948 for(I = 1; I <= BoardSizeX; I++) {
1949 fprintf(f3, "|");
1950 if(Squares[I][J] != 0 ) {
1951 if(Squares[I][J] > 0 ) fprintf(f3, " b"); else fprintf(f3, " w");
1952 // FIXME? Print #3, Left$(Pieces[abs(Squares[I][J])].sname, 3 - Short);
1953 strcpy(TmpSTR, Pieces[abs(Squares[I][J])].sname); TmpSTR[3 - Short] = 0;
1954 if(Short) fprintf(f3, "%-2s", TmpSTR); else fprintf(f3, "%-3s", TmpSTR);
1955 } else {
1956 if(Short == 0 ) fprintf(f3, " "); else fprintf(f3, " ");
1958 } // Next I;
1959 fprintf(f3, "| %c", (96 + J));
1960 if(J == DropStart || J == DropEnd ) fprintf(f3, " +----------------+");
1961 if(J == DropStart + 1 ) fprintf(f3, " %s", WhiteDrop[2]);
1962 if(J == DropEnd + 1 ) fprintf(f3, " %s", BlackDrop[2]);
1963 fprintf(f3, "\n");
1964 } // Next J;
1965 fprintf(f3, "+");
1966 for(I = 1; I <= BoardSizeX - 1; I++) {
1967 if(Short == 0 ) fprintf(f3, "------"); else fprintf(f3, "-----");
1968 } // Next I;
1969 if(Short == 0 ) fprintf(f3, "-----+"); else fprintf(f3, "----+");
1970 if(DropEnd > 0 ) fprintf(f3, " +----------------+");
1971 fprintf(f3, "\n");
1972 fprintf(f3, "\n");
1973 fprintf(f3, "%s to move.\n", Turn);
1974 sprintf(Board.Caption, "Diagram text file %s created.", Board.CMDiagram.Filename); Notice = 1;
1975 fclose(f3);
1978 void DiagramSmall ()
1979 { // Menu function for small diagrams.
1980 FILE *f3;
1981 STRING TmpSTR;
1982 INT Short, DropStart, DropEnd;
1983 // TODO On Error Resume Next;
1984 strcpy(Board.CMDiagram.DialogTitle, "Create Small Text Diagram");
1985 Board.CMDiagram.Flags = 0x400L | 0x800L | 0x4;
1986 Board.CMDiagram.Action = 2;
1987 if(Err == 32755 ) return;
1988 strcpy(SavedSTR, Board.CMDiagram.Filename);
1990 if( !(f3 = fopen(SavedSTR, "w")) ) return;
1992 if(!strcmp(GameName, "Whale") || !strcmp(GameName, "Early") || !strcmp(GameName, "Bird") || !strcmp(GameName, "Micro") || !strcmp(GameName, "Mini") || !strcmp(GameName, "") ) Short = 1; else Short = 0;
1993 if(Drop == 1 ) DiagramDrop();
1994 DropStart = 0; DropEnd = 0;
1995 if(Drop == 1 ) {
1996 DropStart = 1;
1997 DropEnd = BoardSizeY - 1;
1999 if(strcmp(GameName, "") ) {
2000 fprintf(f3, "%s Shogi", GameName);
2001 for(I = 1; I <= strlen(GameName) + 6; I++) {
2002 fprintf(f3, "=");
2003 } // Next I;
2005 fprintf(f3, "\n");
2006 for(I = BoardSizeX; I >= 1; I--) {
2007 if(I < 10 ) fprintf(f3, " ");
2008 if(Short == 0 ) fprintf(f3, " ");
2009 fprintf(f3, "%d", I);
2010 fprintf(f3, " ");
2011 } // Next I;
2012 fprintf(f3, "\n");
2013 fprintf(f3, "+");
2014 for(I = 1; I <= BoardSizeX - 1; I++) {
2015 if(Short == 0 ) fprintf(f3, "----"); else fprintf(f3, "---");
2016 } // Next I;
2017 if(Short == 0 ) fprintf(f3, "----+"); else fprintf(f3, "---+");
2018 if(DropStart == 1 ) fprintf(f3, " White in hand:");
2019 fprintf(f3, "\n");
2020 for(J = 1; J <= BoardSizeY; J++) {
2021 fprintf(f3, "|");
2022 for(I = 1; I <= BoardSizeX; I++) {
2023 if(Squares[I][J] != 0 ) {
2024 if(Squares[I][J] > 0 ) fprintf(f3, "b"); else fprintf(f3, "w");
2025 strcpy(TmpSTR, Pieces[abs(Squares[I][J])].sname); TmpSTR[3 - Short] = 0;
2026 if(Short) fprintf(f3, "%-2s", TmpSTR); else fprintf(f3, "%-3s", TmpSTR);
2027 } else {
2028 if(Short == 0 ) fprintf(f3, " * "); else fprintf(f3, " * ");
2030 } // Next I;
2031 fprintf(f3, "|%c", (96 + J));
2032 if(J == DropStart ) fprintf(f3, " %s", Mid(WhiteDrop[1], 2, 16));
2033 if(J == DropStart + 1 ) fprintf(f3, " %s", Mid(WhiteDrop[2], 2, 16));
2034 if(J == DropEnd + 1 ) fprintf(f3, " %s", Mid(BlackDrop[1], 2, 16));
2035 if(J == DropEnd ) fprintf(f3, " Black in hand:");
2036 fprintf(f3, "\n");
2037 } // Next J;
2038 fprintf(f3, "+");
2039 for(I = 1; I <= BoardSizeX - 1; I++) {
2040 if(Short == 0 ) fprintf(f3, "----"); else fprintf(f3, "---");
2041 } // Next I;
2042 if(Short == 0 ) fprintf(f3, "----+"); else fprintf(f3, "---+");
2043 if(DropEnd > 0 ) fprintf(f3, " %s", Mid(BlackDrop[2], 2, 16));
2044 fprintf(f3, "\n");
2045 fprintf(f3, "%s to move.\n", Turn);
2046 sprintf(Board.Caption, "Diagram text file %s created.", Board.CMDiagram.Filename); Notice = 1;
2047 fclose(f3);
2050 void DisplayEmperor ()
2052 INT K, L, EF;
2053 for(K = 1; K <= BoardSizeY; K++) {
2054 for(J = 1; J <= BoardSizeX; J++) {
2055 Board.ForeColor = 0xFF8080;
2056 Legal[J][K] = 1; L = 0;
2057 if(!strcmp(Turn, "Black") && Squares[J][K] < 0 && ((Camps[J][K] == 1 || Camps[J][K] == 3) || WhiteEmperor == 1) ) Legal[J][K] = 0;
2058 if(!strcmp(Turn, "White") && Squares[J][K] > 0 && (Camps[J][K] > 1 || BlackEmperor == 1) ) Legal[J][K] = 0;
2059 if(!strcmp(Turn, "Black") && Squares[J][K] < 0 && Legal[J][K] == 1 ) Board.ForeColor = 0xC0;
2060 if(!strcmp(Turn, "White") && Squares[J][K] > 0 && Legal[J][K] == 1 ) Board.ForeColor = 0xC0;
2061 if(FirstInitRank == K && FirstInitFile == J ) Legal[J][K] = 0;
2062 if(Squares[J][K] != 0 ) {
2063 if(!strcmp(Pieces[abs(Squares[J][K])].Name, "Emperor") && Sgn(Squares[J][K]) != Sgn(Squares[FirstInitFile][FirstInitRank]) ) {
2064 NewRank = K; NewFile = J; Legal[J][K] = 1; CheckEmperor();
2065 K = NewRank; J = NewFile;
2066 if(Legal[J][K] == 1 ) Board.ForeColor = 0xC0;
2069 if(SeeMove == 1 && Legal[J][K] == 1 ) {
2070 if(Squares[J][K] == 0 ) {
2071 if(Reverse == 0 ) {
2072 Board.Line(XStart + (J - 1) * Pixels, 11 + (K - 1) * Pixels, XStart + (J * Pixels) - 2, 9 + (K * Pixels), NOCOLOR, "BF");
2073 } else {
2074 Board.Line(XStart + (BoardSizeX - J) * Pixels, 11 + (BoardSizeY - K) * Pixels, XStart - 2 + (BoardSizeX - J + 1) * Pixels, 9 + (BoardSizeY - K + 1) * Pixels + L, NOCOLOR, "BF");
2076 } else {
2077 for(EF = 1; EF < Pixels; EF++) { // FIXME: lowered EF by one to access correct PieceMask elements
2078 if(Reverse == 0 ) {
2079 if(Squares[J][K] > 0 ) {
2080 Board.Line(XStart + (J - 1) * Pixels + EF - 2, 11 + (K - 1) * Pixels, XStart + (J - 1) * Pixels + EF - 2, 11 + (K - 1) * Pixels + PieceMask[Pieces[abs(Squares[J][K])].Mask][EF] + 1, NOCOLOR, "");
2081 } else {
2082 Board.Line(XStart + (J - 1) * Pixels + (Pixels - EF), 9 + (K * Pixels), XStart + (J - 1) * Pixels + (Pixels - EF), 8 + (K * Pixels) - PieceMask[Pieces[abs(Squares[J][K])].Mask][EF], NOCOLOR, "");
2084 } else {
2085 if(Squares[J][K] > 0 ) {
2086 Board.Line(XStart + (BoardSizeX - J) * Pixels + (Pixels - EF), 8 + (BoardSizeY - K + 1) * Pixels + 1, XStart + (BoardSizeX - J) * Pixels + (Pixels - EF), 8 + (BoardSizeY - K + 1) * Pixels - PieceMask[Pieces[abs(Squares[J][K])].Mask][EF], NOCOLOR, "");
2087 } else {
2088 Board.Line(XStart + (BoardSizeX - J) * Pixels + EF - 2, 10 + (BoardSizeY - K) * Pixels + 1, XStart + (BoardSizeX - J) * Pixels + EF - 2, 12 + (BoardSizeY - K) * Pixels + PieceMask[Pieces[abs(Squares[J][K])].Mask][EF], NOCOLOR, "");
2091 } // Next EF;
2094 Camps[J][K] = 0;
2095 } // Next J;
2096 } // Next K;
2097 Influence = 0;
2098 Board.ForeColor = 0x0L;
2099 Board.FillColor = 0xFFFFFF;
2102 void DisplayTerritory ()
2104 INT K, L, EF;
2105 for(K = 1; K <= BoardSizeY; K++) {
2106 for(J = 1; J <= BoardSizeX; J++) {
2107 L = 0;
2108 if(!strcmp(Choice, "Heian") || !strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "Tenjiku") ) L = 1;
2109 switch( Camps[J][K] ) {
2110 case 1: Board.ForeColor = 0xFFFFFF; break;
2111 case 2: Board.ForeColor = 0x606060; break;
2112 case 3: Board.ForeColor = 0xC0C0C0; break;
2114 if(Camps[J][K] > 0 ) {
2115 if(Squares[J][K] == 0 ) {
2116 if(Reverse == 0 ) {
2117 Board.Line(XStart + L + (J - 1) * Pixels, 11 + L + (K - 1) * Pixels, XStart + (J * Pixels) - 2 + L, 9 + L + (K * Pixels), NOCOLOR, "BF");
2118 } else {
2119 Board.Line(XStart + L + (BoardSizeX - J) * Pixels, 11 + (BoardSizeY - K) * Pixels + L, XStart - 2 + L + (BoardSizeX - J + 1) * Pixels, 9 + (BoardSizeY - K + 1) * Pixels + L, NOCOLOR, "BF");
2121 } else {
2122 if(Squares[J][K] > 0 && Camps[J][K] == 1 ) Board.ForeColor = 0xFF8080;
2123 if(Squares[J][K] < 0 && Camps[J][K] == 2 ) Board.ForeColor = 0xFF8080;
2124 if(Squares[J][K] < 0 ) {
2125 if((Squares[J][K] == -1 || !strcmp(Pieces[abs(Squares[J][K])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[J][K])].Name, "Prince")) && Camps[J][K] > 1 ) Board.ForeColor = 0xC0L;
2126 } else {
2127 if((Squares[J][K] == 1 || !strcmp(Pieces[abs(Squares[J][K])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[J][K])].Name, "Prince")) && (Camps[J][K] == 1 || Camps[J][K] == 3) ) Board.ForeColor = 0xC0L;
2129 for(EF = 1; EF < Pixels; EF++) { // FIXME: lowered EF by 1 to access correct PieceMask elements ???
2130 if(Reverse == 0 ) {
2131 if(Squares[J][K] > 0 ) {
2132 Board.Line(XStart + (J - 1) * Pixels + EF /*- 2*/ + L, 11 + (K - 1) * Pixels + L, XStart + (J - 1) * Pixels + EF /*- 2*/ + L, 11 + (K - 1) * Pixels + PieceMask[Pieces[abs(Squares[J][K])].Mask][EF] + 1, NOCOLOR, ""); // FIXME: added 2 to x
2133 } else {
2134 Board.Line(XStart + (J - 1) * Pixels + (Pixels - EF) + L, 9 + (K * Pixels) + L + 1, XStart + (J - 1) * Pixels + (Pixels - EF) + L, 8 + K * Pixels - (PieceMask[Pieces[abs(Squares[J][K])].Mask][EF] - (L * 2)) + 1 + YStart, NOCOLOR, ""); // FIXME: added 1 to y
2136 } else {
2137 if(Squares[J][K] > 0 ) {
2138 Board.Line(XStart + (BoardSizeX - J) * Pixels + (Pixels - EF) + L, 8 + (BoardSizeY - K + 1) * Pixels + 1 + L + 1, XStart + (BoardSizeX - J) * Pixels + (Pixels - EF) + L, 8 + (BoardSizeY - K + 1) * Pixels - PieceMask[Pieces[abs(Squares[J][K])].Mask][EF] + (L * 2) + 1, NOCOLOR, ""); // FIXME: added 1 to y
2139 } else {
2140 Board.Line(XStart + (BoardSizeX - J) * Pixels + EF /*- 2*/ + L, 10 + (BoardSizeY - K) * Pixels + 1 + L, XStart + (BoardSizeX - J) * Pixels + EF /*- 2*/ + L, 12 + (BoardSizeY - K) * Pixels + PieceMask[Pieces[abs(Squares[J][K])].Mask][EF], NOCOLOR, ""); // FIXME: added 2 to x
2143 } // Next EF;
2146 Camps[J][K] = 0;
2147 } // Next J;
2148 } // Next K;
2149 Board.ForeColor = 0x0L;
2150 Board.FillColor = 0xFFFFFF;
2153 void DolphinMove ()
2155 if((Squares[InitFile][InitRank] > 0 && InitRank == 1) || (Squares[InitFile][InitRank] < 0 && InitRank == 6) ) {
2156 Pieces[abs(Squares[InitFile][InitRank])].Moves[7] = 64;
2157 Pieces[abs(Squares[InitFile][InitRank])].Moves[8] = 64;
2161 void DoubleMove ()
2163 ClearLegal();
2164 strcpy(LionNameSTR, Pieces[abs(Squares[File][Rank])].Name);
2165 sprintf(Board.Caption, "Extra %s move - Double Click on Piece to End Move.", LionNameSTR);
2166 LionPiece = I;
2167 Teach = Teach - 1;
2168 if(Reverse == 0 ) {
2169 MOVE(1, Board.Frame, XStart + (File - 1) * Pixels, 11 + (Rank - 1) * Pixels);
2170 } else {
2171 MOVE(1, Board.Frame, XStart + (BoardSizeX - File) * Pixels, 11 + (BoardSizeY - Rank) * Pixels);
2173 Board.Frame.Visible = True;
2176 void DropPiece ()
2177 { // MouseUp handler for board piece. I = piece number, NewButton = button
2178 if(NewButton == 1 ) {
2179 strcpy(Board.PieceID.Caption, "");
2180 DRAG(Board.showpic[I], 0);
2181 } else {
2182 strcpy(Board.PieceID.Caption, "");
2183 Board.PieceID.ForeColor = 0xFF0000;
2184 RightClick = 0;
2186 if(LegalMoves == 0 ) ClearLegal();
2189 void DropPiece2 ()
2190 { // MouseUp handler for holdings pieces. I = (holdings) piece number, NewButton = button
2191 if(NewButton == 1 ) {
2192 strcpy(Board.PieceID.Caption, "");
2193 DRAG(Board.HandPic[I], 0);
2194 if(LegalMoves == 0 ) ClearLegal();
2195 } else {
2196 strcpy(Board.PieceID.Caption, "");
2197 Board.PieceID.ForeColor = 0xFF0000;
2198 if(LegalMoves == 0 ) ClearLegal();
2202 void Emperor ()
2204 INT AB, CD;
2205 FirstInitFile = InitFile; FirstInitRank = InitRank; EmperorTest = 1;
2206 Influence = 2;
2207 for(AB = 1; AB <= BoardSizeY; AB++) {
2208 for(CD = 1; CD <= BoardSizeX; CD++) {
2209 if((!strcmp(Turn, "Black") && Squares[CD][AB] < 0) || (!strcmp(Turn, "White") && Squares[CD][AB] > 0) ) {
2210 InitFile = CD; InitRank = AB;
2211 Validate();
2213 } // Next CD;
2214 } // Next AB;
2215 DisplayEmperor();
2216 Influence = 0; EmperorTest = 0;
2217 InitRank = FirstInitRank; InitFile = FirstInitFile;
2220 void EmperorCheck ()
2222 INT AB, CD, OldInfluence, OldCompMove;
2223 int Response; // write-only?
2224 OldInfluence = Influence; OldCompMove = CompMove; OldSeeMove = SeeMove; SeeMove = 1;
2225 CompMove = 0; Influence = 2;
2226 for(AB = 1; AB <= BoardSizeY; AB++) {
2227 for(CD = 1; CD <= BoardSizeX; CD++) {
2228 InitFile = CD; InitRank = AB; Validate();
2229 } // Next CD;
2230 } // Next AB;
2231 if(Camps[BlackEmpX][BlackEmpY] == 0 ) {
2232 if(!strcmp(Turn, "White") ) {
2233 Response = MsgBox("You have left your Emperor in Check! ", 0, "Black");
2234 } else {
2235 strcpy(Board.PieceID.Caption, "Black Emperor is in Check!"); Notice = 1;
2237 } else {
2238 if(Camps[WhiteEmpX][WhiteEmpY] = 0 ) {
2239 if(!strcmp(Turn, "Black") ) {
2240 Response = MsgBox("You have left your Emperor in Check! ", 0, "White");
2241 } else {
2242 strcpy(Board.PieceID.Caption, "White Emperor is in Check!"); Notice = 1;
2246 for(AB = 1; AB <= BoardSizeY; AB++) {
2247 for(CD = 1; CD <= BoardSizeX; CD++) {
2248 Camps[CD][AB] = 0;
2249 } // Next CD;
2250 } // Next AB;
2251 Influence = OldInfluence; CompMove = OldCompMove; SeeMove = OldSeeMove;
2254 void EmperorInfluence ()
2256 INT EF;
2257 if(Squares[InitFile][InitRank] > 0 ) {
2258 Board.ForeColor = 0x606060;
2259 } else {
2260 Board.ForeColor = 0xFFFFFF;
2262 for(EF = 1; EF < Pixels; EF++) {
2263 if(Reverse == 0 ) {
2264 if(Squares[InitFile][InitRank] != 0 ) {
2265 if(Squares[InitFile][InitRank] > 0 ) {
2266 Board.Line(XStart + (InitFile - 1) * Pixels + EF /*- 2*/, 11 + (InitRank - 1) * Pixels, XStart + (InitFile - 1) * Pixels + EF /*- 2*/, 11 + (InitRank - 1) * Pixels + PieceMask[Pieces[abs(Squares[InitFile][InitRank])].Mask][EF] + 1, NOCOLOR, ""); // FIXME: added 2 to x
2267 } else {
2268 Board.Line(XStart + (InitFile - 1) * Pixels + (Pixels - EF), 9 + InitRank * Pixels + 1, XStart + (InitFile - 1) * Pixels + (Pixels - EF), 8 + InitRank * Pixels - PieceMask[Pieces[abs(Squares[InitFile][InitRank])].Mask][EF] + 1, NOCOLOR, ""); // FIXME: added 1 to y
2271 } else {
2272 if(Squares[InitFile][InitRank] != 0 ) {
2273 if(Squares[InitFile][InitRank] > 0 ) {
2274 Board.Line(XStart + (BoardSizeX - InitFile) * Pixels + (Pixels - EF), 8 + (BoardSizeY - InitRank + 1) * Pixels + 2, XStart + (BoardSizeX - InitFile) * Pixels + (Pixels - EF), 8 + (BoardSizeY - InitRank + 1) * Pixels - PieceMask[Pieces[abs(Squares[InitFile][InitRank])].Mask][EF] + 1, NOCOLOR, ""); // FIXME: added 1 to y2
2275 } else {
2276 Board.Line(XStart + (BoardSizeX - InitFile) * Pixels + EF /*- 2*/, 10 + (BoardSizeY - InitRank) * Pixels + 1, XStart + (BoardSizeX - InitFile) * Pixels + EF /*- 2*/, 12 + (BoardSizeY - InitRank) * Pixels + PieceMask[Pieces[abs(Squares[InitFile][InitRank])].Mask][EF], NOCOLOR, ""); // FIXME: added 2 to x
2280 } // Next EF;
2281 Board.ForeColor = 0x0L;
2282 Board.FillColor = 0xFFFFFF;
2285 void EndLionMove ()
2287 STRING PieceName;
2288 INT K, L, Found;
2289 if(LionPiece == I ) {
2290 K = 1;
2291 do {
2292 L = 1;
2293 do {
2294 if(Grafix[L][K] == I ) {
2295 strcpy(PieceName, Pieces[abs(Squares[L][K])].Name);
2296 strcpy(Board.PieceID.Caption, PieceName);
2297 File = L;
2298 Rank = K;
2299 Found = 1;
2301 L = L + 1;
2302 } while( !( L > BoardSizeX || Found == 1) );
2303 K = K + 1;
2304 } while( !(K > BoardSizeY || Found == 1) );
2305 Found = 0;
2306 Board.Frame.Visible = False;
2307 LionPiece = -1;
2308 LionBurn();
2309 NextTurn();
2310 } else {
2311 UnPromote();
2315 void EndSelect ()
2317 if(MovePiece == 1 ) {
2318 strcpy(Board.Caption, Cap);
2319 MovePiece = 0; Handicap = 0; Reduce = 0;
2320 Board.Timer1.Enabled = True;
2321 MoveCount = 0; TurnCount = 0;
2322 if(!strcmp(Turn, "White") ) MoveCount = 1;
2323 strcpy(Board.LastMove.Caption, "");
2324 } else {
2325 Handicap = 0; Reduce = 0; MovePiece = 0;
2326 if(Drop == 1 ) ResetHand();
2327 if(!strcmp(Turn, "White") ) MoveCount = 1;
2328 LoadAddPieces();
2330 BugFix();
2333 void EndSetup ()
2335 MovePiece = 0; Selection = 0; Reduce = 0; Handicap = 0; strcpy(ExtraPiece, "");
2338 void EndTilde ()
2339 { // called when MouseDown on board or holdings piece
2340 if(Tilde == 1 ) {
2341 ClearLegal();
2342 Board.Refresh();
2343 Tilde = 0;
2347 void FillSquare ()
2348 { // Button1-Down handler for Form. (NewX, NewY) is coords, CCC = 1 and CleckPiece = 0;
2349 if(strcmp(Computer, Turn) && strcmp(Computer, "Both") && Level != 0 && GameOver != 1 ) {
2350 if(Selection != 0 ) {
2351 if(NewX > XStart && NewX < XStart + (BoardSizeX * Pixels) && NewY > 11 && NewY < 11 + (BoardSizeY * Pixels) ) {
2352 GetSquare();
2353 Squares[InitFile][InitRank] = Selection;
2354 NewGraf = 0;
2355 while( Board.showpic[NewGraf].Visible == True) {
2356 NewGraf = NewGraf + 1;
2358 SetGrafix();
2360 Reduce = 0; Handicap = 0; MovePiece = 0;
2361 CheckAdd();
2362 } else {
2363 Territory();
2368 void FindEmperorMove ()
2370 INT K, JStart, KStart, JEnd, KEnd, Steps, VacantX, VacantY, CaptureX, CaptureY, Vacant, BestCapture;
2371 BestCapture = 0; Vacant = 0;
2372 if(!strcmp(Turn, "Black") ) {
2373 KStart = BoardSizeY; JStart = BoardSizeX; KEnd = 1; JEnd = 1; Steps = -1;
2374 } else {
2375 KStart = 1; JStart = 1; KEnd = BoardSizeY; JEnd = BoardSizeX; Steps = 1;
2377 for(K = KStart; Steps > 0 ? K <= KEnd : K >= KEnd; K += Steps) {
2378 for(J = JStart; Steps > 0 ? J <= JEnd : J >= JEnd; J += Steps) {
2379 if(!strcmp(Turn, "Black") && Squares[J][K] < 0 && Camps[J][K] != 1 && Camps[J][K] != 3 && WhiteEmperor != 1 ) {
2380 if(Pieces[abs(Squares[J][K])].Value > BestCapture ) {
2381 BestCapture = Pieces[abs(Squares[J][K])].Value; CaptureX = J; CaptureY = K;
2384 if(!strcmp(Turn, "White") && Squares[J][K] > 0 && Camps[J][K] < 2 && BlackEmperor != 1 ) {
2385 if(Pieces[abs(Squares[J][K])].Value > BestCapture ) {
2386 BestCapture = Pieces[abs(Squares[J][K])].Value; CaptureX = J; CaptureY = K;
2389 if(!strcmp(Turn, "Black") && Squares[J][K] == 0 && Camps[J][K] != 1 && Camps[J][K] != 3 && WhiteEmperor != 1 && Vacant != 1 ) {
2390 VacantX = J; VacantY = K; Vacant = 1;
2392 if(!strcmp(Turn, "White") && Squares[J][K] == 0 && Camps[J][K] < 2 && BlackEmperor != 1 && Vacant != 1 ) {
2393 VacantX = J; VacantY = K; Vacant = 1;
2395 if(!strcmp(Turn, "Black") && Squares[J][K] == 0 && Camps[J][K] == 2 && Vacant != 1 ) {
2396 VacantX = J; VacantY = K; Vacant = 1;
2398 if(!strcmp(Turn, "White") && Squares[J][K] == 0 && Camps[J][K] == 1 && Vacant != 1 ) {
2399 VacantX = J; VacantY = K; Vacant = 1;
2401 Camps[J][K] = 0;
2402 } // Next J;
2403 } // Next K;
2404 if(!strcmp(Turn, "Black") ) { InitFile = BlackEmpX; InitRank = BlackEmpY; }
2405 if(!strcmp(Turn, "White") ) { InitFile = WhiteEmpX; InitRank = WhiteEmpY; }
2406 if(BestCapture > 0 ) {
2407 SeeFile = CaptureX; SeeRank = CaptureY; AddEmperorMove();
2409 SeeFile = VacantX; SeeRank = VacantY; AddEmperorMove();
2410 Influence = 0;
2413 void FindInfluence ()
2415 INT LL;
2416 Changed = 1;
2417 if(LookMate == 1 ) {
2418 Clearing[1].File = LastPieceX;
2419 Clearing[1].Rank = LastPieceY;
2420 File = LastPieceX; Rank = LastPieceY;
2421 ClearInfo();
2423 Clearing[Changed].File = CompFile;
2424 Clearing[Changed].Rank = CompRank;
2425 File = InitFile; Rank = InitRank;
2426 if(InitFile != 0 ) ClearInfo();
2427 if(Squares[CompFile][CompRank] != 0 ) {
2428 File = CompFile; Rank = CompRank; CapturedPiece = 1; ClearInfo();
2429 } else {
2430 for(LL = 1; LL <= Attacker[CompFile][CompRank]; LL++) {
2431 File = BanMap[CompFile][CompRank].Info[LL].File;
2432 Rank = BanMap[CompFile][CompRank].Info[LL].Rank;
2433 if(File != 0 && (InitFile != File || InitRank != Rank) ) {
2434 if(Pieces[abs(Squares[File][Rank])].Range != 0 ) ClearInfo();
2436 } // Next LL;
2438 if(ExtraCapture[AA].Piece != 0 ) {
2439 File = ExtraCapture[AA].File; Rank = ExtraCapture[AA].Rank; ClearInfo();
2440 for(LL = 1; LL <= Attacker[ExtraCapture[AA].File][ExtraCapture[AA].Rank]; LL++) {
2441 File = BanMap[ExtraCapture[AA].File][ExtraCapture[AA].Rank].Info[LL].File;
2442 Rank = BanMap[ExtraCapture[AA].File][ExtraCapture[AA].Rank].Info[LL].Rank;
2443 if(Pieces[abs(Squares[File][Rank])].Range != 0 ) ClearInfo();
2444 } // Next LL;
2446 for(LL = 1; LL <= Attacker[InitFile][InitRank]; LL++) {
2447 File = BanMap[InitFile][InitRank].Info[LL].File;
2448 Rank = BanMap[InitFile][InitRank].Info[LL].Rank;
2449 if(File != 0 ) {
2450 if(Pieces[abs(Squares[File][Rank])].Range != 0 ) ClearInfo();
2452 } // Next LL;
2455 void FireDemon ()
2457 INT K, L;
2458 Evaluate = 0;
2459 if(SeeMove == 1 && Other != 1 ) {
2460 if((Influence == 0) || (Squares[NewFile][NewRank] == 0 || Sgn(Squares[InitFile][InitRank]) != Sgn(Squares[NewFile][NewRank])) ) {
2461 for(K = NewRank - 1; K <= NewRank + 1; K++) {
2462 for(L = NewFile - 1; L <= NewFile + 1; L++) {
2463 if(L > 0 && L <= BoardSizeX && K > 0 && K <= BoardSizeY ) {
2464 if(((Sgn(Squares[InitFile][InitRank]) != Sgn(Squares[L][K])) && Squares[L][K] != 0 && Legal[L][K] != 1) ) {
2465 if((K != NewRank || L != NewFile) && Pieces[abs(Squares[L][K])].special != 'F' ) {
2466 Board.FillColor = 0xFFFFL;
2467 if(Legal[L][K] < 1 ) { SeeFile = L; SeeRank = K; LookMove(); }
2470 if((Influence != 0) && (Squares[L][K] == 0) ) {
2471 SeeFile = L; SeeRank = K; LookMove();
2474 } // Next L;
2475 } // Next K;
2480 void Flame ()
2482 INT K, L, W, King=0; // FIXME: read-only variable
2483 W = 0;
2484 for(K = Rank - 1; K <= Rank + 1; K++) {
2485 for(L = File - 1; L <= File + 1; L++) {
2486 if(L > 0 && L <= BoardSizeX && K > 0 && K <= BoardSizeY ) {
2487 if((Sgn(Squares[File][Rank]) != Sgn(Squares[L][K])) && Squares[L][K] != 0 ) {
2488 if(strcmp(Pieces[abs(Squares[L][K])].Name, "Fire Demon") ) {
2489 if(abs(Squares[L][K]) == 1 || (!strcmp(Pieces[abs(Squares[L][K])].Name, "Crown Prince") && King == 1) ) {
2490 File = L; Rank = K;
2491 CheckMate();
2493 if(Mate == 1 ) return;
2494 if(W == 0 ) strcat(CMoveSTR, CR "\n x!"); else strcat(CMoveSTR, ",");
2495 if(W == 3 ) strcat(CMoveSTR, CR "\n ");
2496 sprintf(CMoveSTR + strlen(CMoveSTR), "%d%c", ((BoardSizeX - L) + 1), (K + 96));
2497 Captures[TurnCount].number = Captures[TurnCount].number + 1;
2498 Captures[TurnCount].Positions[Captures[TurnCount].number] = (K * (BoardSizeX + 1)) + L;
2499 Captures[TurnCount].PieceNum[Captures[TurnCount].number] = Squares[L][K];
2500 Squares[L][K] = 0;
2501 Board.showpic[Grafix[L][K]].Visible = False;
2502 MOVE(1, Board.showpic[Grafix[L][K]], 0, 0);
2503 Grafix[L][K] = -1;
2504 W = W + 1;
2508 } // Next L;
2509 } // Next K;
2512 void FlashPiece ()
2514 INT PPP;
2515 if(LastPieceX > -1 && LastPieceY > -1 ) {
2516 if(Grafix[LastPieceX][LastPieceY] > -1 ) {
2517 CCC = 0; XA = 0; Blink = 0; PPP = 2;
2518 Board.Timer2.Interval = 200;
2519 do {
2520 if(Blink / 2. == Int(Blink / 2) && PPP != 2 ) {
2521 Board.showpic[Grafix[LastPieceX][LastPieceY]].Visible = False; PPP = PPP + 1;
2522 PPP = 2;
2523 Board.Refresh();
2525 if(Blink / 2. != Int(Blink / 2) && PPP != 1 ) {
2526 Board.showpic[Grafix[LastPieceX][LastPieceY]].Visible = True;
2527 PPP = 1;
2528 Board.Refresh();
2530 #ifdef MSVC
2531 DoEvents();
2532 #else
2533 Blink++; usleep(200000); // [HGM] added. Freezes application during blink
2534 #endif
2535 } while( !(CCC == 1 || Blink == 14) );
2536 CCC = 0; XA = 0; Blink = 0; Board.Timer2.Interval = 0;
2537 Board.showpic[Grafix[LastPieceX][LastPieceY]].Visible = True;
2542 void FormActing ()
2544 if(!strcmp(Threat, "On") && SeeMove == 1 && GameOver != 1 ) {
2545 GetSquare();
2546 ActingPieces();
2550 void FormDrop ()
2551 { // DragDrop-event handler for Form; (NewX, NewY) pass coords
2552 INT K=0, L=0; // FIXME: read-only
2553 int Response; // write-only?
2554 if(MovePiece == 1 ) MoveFormDrop();
2555 if(InitRank == 0 ) HeldDrop();
2556 if((NewX > XStart && NewX < XStart + (BoardSizeX * Pixels) && NewY > 11 && NewY < 11 + (BoardSizeY * Pixels)) || CompMove == 1 ) {
2557 GetSquare2();
2558 if(Legal[File][Rank] > 0 && RightClick != 1 ) {
2559 if(LionPiece != I ) {
2560 Score[TurnCount].IDStart = Squares[InitFile][InitRank];
2561 Score[TurnCount].PosStart = (InitRank * (BoardSizeX + 1)) + InitFile;
2562 strcat(CMoveSTR, TrimSTR(Pieces[abs(Squares[InitFile][InitRank])].sname));
2563 sprintf(CMoveSTR + strlen(CMoveSTR), "%d%c", ((BoardSizeX - InitFile) + 1), (96 + InitRank));
2564 if((!strcmp(Computer, Turn) || !strcmp(Computer, "Both")) && LionVictim.Piece != 0 ) {
2565 sprintf(CMoveSTR + strlen(CMoveSTR), "x%d%c", (BoardSizeX - LionVictim.File + 1), (96 + LionVictim.Rank));
2568 sprintf(CMoveSTR + strlen(CMoveSTR), "-%d%c", ((BoardSizeX - File) + 1), (Rank + 96));
2569 if(Legal[File][Rank] == 1 ) LionPiece = -1;
2570 Board.Frame.Visible = False;
2571 Squares[File][Rank] = Squares[InitFile][InitRank];
2572 if(Squares[File][Rank] == 1 ) { BlackKingX = File; BlackKingY = Rank; }
2573 if(Squares[File][Rank] == -1 ) { WhiteKingX = File; WhiteKingY = Rank; }
2574 if(!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Emperor") && Squares[File][Rank] > 0 ) { BlackEmpX = File; BlackEmpY = Rank; }
2575 if(!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Emperor") && Squares[File][Rank] < 0 ) { WhiteEmpX = File; WhiteEmpY = Rank; }
2576 Score[TurnCount].PosEnd = (Rank * (BoardSizeX + 1)) + File;
2577 Score[TurnCount].IDEnd = Squares[File][Rank];
2578 if(LionVictim.Piece != 0 ) {
2579 Captures[TurnCount].number = Captures[TurnCount].number + 1;
2580 Captures[TurnCount].Positions[Captures[TurnCount].number] = (LionVictim.Rank * (BoardSizeX + 1)) + LionVictim.File;
2581 Captures[TurnCount].PieceNum[Captures[TurnCount].number] = Squares[LionVictim.File][LionVictim.Rank];
2582 Taken = 1;
2584 Grafix[File][Rank] = I;
2585 if(InitFile != File || InitRank != Rank ) Grafix[InitFile][InitRank] = -1;
2586 if(InitFile != File || InitRank != Rank ) Squares[InitFile][InitRank] = 0;
2587 if(LionVictim.Piece != 0 ) {
2588 Squares[LionVictim.File][LionVictim.Rank] = 0;
2589 Board.showpic[Grafix[LionVictim.File][LionVictim.Rank]].Visible = False;
2590 MOVE(1, Board.showpic[Grafix[LionVictim.File][LionVictim.Rank]], 0, 0);
2591 Grafix[LionVictim.File][LionVictim.Rank] = -1;
2593 if(Legal[File][Rank] == 3 ) {
2594 Score[TurnCount].IDEnd = 0;
2595 Grafix[File][Rank] = -1;
2596 Board.showpic[I].Visible = False;
2597 MOVE(1, Board.showpic[I], 0, 0);
2598 Squares[File][Rank] = 0;
2599 LionPiece = -1;
2600 } else {
2601 if(Reverse == 0 ) {
2602 MOVE(1, Board.showpic[I], XStart + ((File - 1) * Pixels), 11 + ((Rank - 1) * Pixels));
2603 } else {
2604 MOVE(1, Board.showpic[I], XStart + ((BoardSizeX - File) * Pixels), 11 + ((BoardSizeY - Rank) * Pixels));
2607 if(Demon == 1 ) Flame();
2608 if(Mate != 1 ) {
2609 if(Legal[File][Rank] == 3 ) strcat(CMoveSTR, "*");
2610 if(Legal[File][Rank] == 6 ) Teach = 3;
2611 if(Legal[File][Rank] == 2 ) Teach = 2; else Teach = 1;
2612 if(Legal[L][K] == 2 || Legal[L][K] == 6 ) { // FIXME: uninitialized????
2613 DoubleMove();
2614 } else {
2615 LastPieceX = File; LastPieceY = Rank;
2616 if(CompMove != 1 ) NextTurn();
2621 ClearLegal();
2622 if(Mate == 1 ) {
2623 GameOver = 1;
2624 Response = MsgBox(" Checkmate! ", 0, (sprintf(StringTmp, "%s Wins!", Turn), StringTmp)); NextTurn();
2628 void GetSquare ()
2630 if(Reverse == 0 ) {
2631 InitFile = Int((NewX - XStart) / Pixels) + 1;
2632 InitRank = Int((NewY - 11) / Pixels) + 1;
2633 } else {
2634 InitFile = Int((BoardSizeX * Pixels - (NewX - XStart)) / Pixels) + 1;
2635 InitRank = Int((BoardSizeY * Pixels - (NewY - 11)) / Pixels) + 1;
2637 if(InitRank < 1 || InitRank > BoardSizeY || InitFile < 1 || InitFile > BoardSizeX ) {
2638 InitRank = 0; InitFile = 0;
2642 void GetSquare2 ()
2644 if(CompMove != 1 && DropTest != 1 ) {
2645 if(Reverse == 0 ) {
2646 File = Int((NewX - XStart) / Pixels) + 1;
2647 Rank = Int((NewY - 11) / Pixels) + 1;
2648 } else {
2649 File = Int((BoardSizeX * Pixels - (NewX - XStart)) / Pixels) + 1;
2650 Rank = Int((BoardSizeY * Pixels - (NewY - 11)) / Pixels) + 1;
2655 void HeldDown ()
2656 { // Button1-Down handler for holdings piece. CCC = 1, I = (holdings) piece number
2657 if(strcmp(Computer, Turn) && strcmp(Computer, "Both") && Level != 0 && GameOver != 1 ) {
2658 Notice = 0;
2659 Board.PieceID.ForeColor = 0xFF0000;
2660 if(Selection != 0 || MovePiece == 1 ) {
2661 AddHand2();
2662 } else {
2663 if(Reduce == 1 ) {
2664 InHand[I] = InHand[I] - 1;
2665 if(InHand[I] < 2 ) strcpy(Board.Held[I].Caption, ""); else sprintf(Board.Held[I].Caption, "%d", InHand[I]);
2666 if(InHand[I] < 1 ) Board.HandPic[I].Visible = False;
2667 } else {
2668 strcpy(Board.Caption, Cap);
2669 strcpy(Board.PieceID.Caption, Pieces[abs(CapRef[I])].Name);
2670 if((I > Capture && !strcmp(Turn, "White") && Reverse == 0) || (I <= Capture && !strcmp(Turn, "Black") && Reverse == 0) || (I > Capture && !strcmp(Turn, "Black") && Reverse == 1) || (I <= Capture && !strcmp(Turn, "White") && Reverse == 1) ) {
2671 DRAG(Board.HandPic[I], 1);
2672 HeldValid();
2673 } else {
2674 Board.FillStyle = 1; Other = 1;
2675 Board.ForeColor = 0xC00000;
2676 HeldValid();
2677 Board.ForeColor = 0x0;
2678 Board.FillStyle = 0; Other = 0;
2685 void HeldDrop ()
2687 if((NewX > XStart && NewX < XStart + (BoardSizeX * Pixels) && NewY > 11 && NewY < 11 + (BoardSizeY * Pixels)) || DropTest == 1 ) {
2688 GetSquare2();
2689 if(Legal[File][Rank] == 1 ) {
2690 Squares[File][Rank] = CapRef[I];
2691 NewGraf = 0;
2692 while( Board.showpic[NewGraf].Visible == True ) {
2693 NewGraf = NewGraf + 1;
2695 Score[TurnCount].IDStart = Squares[File][Rank];
2696 Score[TurnCount].IDEnd = Squares[File][Rank];
2697 Score[TurnCount].PosStart = 0;
2698 Score[TurnCount].PosEnd = (Rank * (BoardSizeX + 1)) + File;
2699 strcpy(CMoveSTR, TrimSTR(Pieces[abs(Squares[File][Rank])].sname));
2700 sprintf(CMoveSTR + strlen(CMoveSTR), "*%d%c", ((BoardSizeX - File) + 1), (Rank + 96));
2701 Grafix[File][Rank] = NewGraf;
2702 Board.showpic[NewGraf] = Board.HandPic[I];
2703 if(Reverse == 0 ) {
2704 MOVE(1, Board.showpic[NewGraf], XStart + (File - 1) * Pixels, 11 + (Rank - 1) * Pixels);
2705 } else {
2706 MOVE(1, Board.showpic[NewGraf], XStart + (BoardSizeX - File) * Pixels, 11 + (BoardSizeY - Rank) * Pixels);
2708 Board.showpic[NewGraf].Visible = True;
2709 InHand[I] = InHand[I] - 1;
2710 if(InHand[I] < 1 ) Board.HandPic[I].Visible = False;
2711 if(InHand[I] < 2 ) strcpy(Board.Held[I].Caption, ""); else sprintf(Board.Held[I].Caption, "%d", InHand[I]);
2712 if(!strcmp(Choice, "Micro") ) MicroDrop();
2713 InitRank = 0; InitFile = 0;
2714 Dropped = 1;
2715 LastPieceX = File; LastPieceY = Rank;
2716 if(CompMove != 1 ) NextTurn();
2719 ClearLegal();
2722 void HeldProm ()
2723 { // Button2-Down handler for holdings piece. CCC = 1, I = (holdings) piece number
2724 STRING PromName;
2725 if(strcmp(Computer, Turn) && strcmp(Computer, "Both") && Level != 0 && GameOver != 1 ) {
2726 strcpy(Board.PieceID.Caption, "");
2727 Board.PieceID.ForeColor = 0x8000L;
2728 if(Pieces[abs(CapRef[I])].Promotes > 0 && strcmp(Pieces[abs(CapRef[I])].Name, "Killer Whale") ) strcpy(PromName, Pieces[abs(Pieces[abs(CapRef[I])].Promotes)].Name );else strcpy(PromName, "None");
2729 sprintf(Board.PieceID.Caption, "Promotes to %s", PromName);
2733 void HeldShow ()
2735 INT K, L;
2736 if(SeeMove == 1 || CompMove == 1 ) {
2737 Board.FillColor = 0xFFFFFF;
2738 for(K = 1; K <= BoardSizeY; K++) {
2739 for(L = 1; L <= BoardSizeX; L++) {
2740 if(Legal[L][K] == 1 ) { SeeFile = L; SeeRank = K; LookMove(); }
2741 } // Next L;
2742 } // Next K;
2744 if(Evaluate != 1 && DropTest != 1 ) InitRank = 0;
2747 void HeldValid ()
2749 INT K, L, X;
2750 for(K = 1; K <= BoardSizeY; K++) {
2751 for(L = 1; L <= BoardSizeX; L++) {
2752 if(Squares[L][K] == 0 ) Legal[L][K] = 1;
2753 if(Pieces[abs(CapRef[I])].special == '1' ) {
2754 if(CapRef[I] > 0 && K == 1 ) Legal[L][K] = 0;
2755 if(CapRef[I] < 0 && K == BoardSizeY ) Legal[L][K] = 0;
2757 if(Pieces[abs(CapRef[I])].special == '2' ) {
2758 if(CapRef[I] > 0 && K < 3 ) Legal[L][K] = 0;
2759 if(CapRef[I] < 0 && K > BoardSizeY - 2 ) Legal[L][K] = 0;
2761 } // Next L;
2762 } // Next K;
2763 if((strcmp(Choice, "Micro")) && (!strcmp(Pieces[abs(CapRef[I])].Name, "Pawn") || !strcmp(Pieces[abs(CapRef[I])].Name, "Sparrow Pawn")) ) {
2764 for(N = 1; N <= BoardSizeY; N++) {
2765 for(P = 1; P <= BoardSizeX; P++) {
2766 if(Squares[P][N] != 0 ) {
2767 if((!strcmp(Pieces[abs(Squares[P][N])].Name, "Pawn") || !strcmp(Pieces[abs(Squares[P][N])].Name, "Sparrow Pawn")) && Sgn(Squares[P][N]) == Sgn(CapRef[I]) ) {
2768 for(X = 1; X <= BoardSizeY; X++) {
2769 Legal[P][X] = 0;
2770 } // Next X;
2773 } // Next P;
2774 } // Next N;
2776 if(!strcmp(Choice, "Tori") && !strcmp(Pieces[abs(CapRef[I])].Name, "Swallow") ) {
2777 for(N = 1; N <= BoardSizeX; N++) {
2778 C = 0;
2779 for(P = 1; P <= BoardSizeY; P++) {
2780 if(Squares[N][P] != 0 ) {
2781 if(!strcmp(Pieces[abs(Squares[N][P])].Name, "Swallow") && Sgn(Squares[N][P]) == Sgn(CapRef[I]) ) {
2782 C = C + 1;
2783 if(C == 2 ) {
2784 for(X = 1; X <= BoardSizeY; X++) {
2785 Legal[N][X] = 0;
2786 } // Next X;
2790 } // Next P;
2791 } // Next N;
2793 if(!strcmp(Choice, "Whale") && !strcmp(Pieces[abs(CapRef[I])].Name, "Dolphin") ) {
2794 for(N = 1; N <= BoardSizeX; N++) {
2795 C = 0;
2796 for(P = 1; P <= BoardSizeY; P++) {
2797 if(Squares[N][P] != 0 ) {
2798 if(!strcmp(Pieces[abs(Squares[N][P])].Name, "Dolphin") && Sgn(Squares[N][P]) == Sgn(CapRef[I]) ) {
2799 C = C + 1;
2800 if(C == 2 ) {
2801 for(X = 1; X <= BoardSizeY; X++) {
2802 Legal[N][X] = 0;
2803 } // Next X;
2807 } // Next P;
2808 } // Next N;
2810 if(CompMove != 1 ) AskMate();
2811 if(Dropping != 1 ) HeldShow();
2814 void HookMove ()
2816 OldLast = Last; OldFile = NewFile; OldRank = NewRank;
2817 while( NewFile - RankInc > 0 && NewFile - RankInc <= BoardSizeX && NewRank + FileInc > 0 && NewRank + FileInc <= BoardSizeY && Last == 0) {
2818 NewFile = NewFile - RankInc;
2819 NewRank = NewRank + FileInc;
2820 ShowMove();
2822 NewFile = OldFile; NewRank = OldRank; Last = 0;
2823 while( NewFile + RankInc > 0 && NewFile + RankInc <= BoardSizeX && NewRank - FileInc > 0 && NewRank - FileInc <= BoardSizeY && Last == 0) {
2824 NewFile = NewFile + RankInc;
2825 NewRank = NewRank - FileInc;
2826 ShowMove();
2828 NewFile = OldFile; NewRank = OldRank; Last = OldLast;
2831 void Igui ()
2833 INT K, L;
2834 for(K = InitRank - 1; K <= InitRank + 1; K++) {
2835 for(L = InitFile - 1; L <= InitFile + 1; L++) {
2836 if(K > 0 && K <= BoardSizeY && L > 0 && L <= BoardSizeX ) {
2837 if(Sgn(Squares[InitFile][InitRank]) != Sgn(Squares[L][K]) || (Squares[L][K] == 0 && Influence > 0) ) {
2838 Board.FillColor = 0x8000L;
2839 if(SeeMove == 1 ) { SeeFile = L; SeeRank = K; LookMove(); }
2840 Legal[L][K] = 4;
2843 } // Next L;
2844 } // Next K;
2847 void Jumping ()
2849 NewFile = InitFile + (FileInc * 2); NewRank = InitRank + (RankInc * 2);
2850 if(NewFile > 0 && NewFile <= BoardSizeX && NewRank > 0 && NewRank <= BoardSizeY ) ShowMove();
2853 void KingSafety ()
2855 // King Safety \ Attacks;
2857 if(strcmp(Choice, "Micro") && strcmp(Choice, "Mini") && strcmp(Choice, "Judkin") && strcmp(Choice, "Yari") && strcmp(Choice, "Tori") && strcmp(Choice, "Whale") ) {
2858 if(CompLegal[AA].EndPiece == 1 ) {
2859 if(abs(InitFile - ((BoardSizeX / 2) + .5)) < abs(CompFile - ((BoardSizeX / 2) + .5)) ) KingTally[AA] = KingTally[AA] + 3;
2860 KingTally[AA] = KingTally[AA] - (BoardSizeY - CompRank);
2862 if(CompLegal[AA].EndPiece == -1 ) {
2864 if(abs(((BoardSizeX / 2) + .5) - InitFile) < abs(((BoardSizeX / 2) + .5) - CompFile) ) KingTally[AA] = KingTally[AA] + 3;
2865 KingTally[AA] = KingTally[AA] - (CompRank - 1);
2867 if(!strcmp(Turn, "Black") && !strcmp(Pieces[abs(CompLegal[AA].EndPiece)].Name, "Gold") && abs(CompFile - BlackKingX) > 1 && abs(CompRank - BlackKingY) > 1 && (abs(CompFile - BlackKingX) > abs(InitFile - BlackKingX) || abs(CompRank - BlackKingY) > abs(InitRank - BlackKingY)) ) KingTally[AA] = KingTally[AA] - 2;
2868 if(!strcmp(Turn, "White") && !strcmp(Pieces[abs(CompLegal[AA].EndPiece)].Name, "Gold") && abs(CompFile - WhiteKingX) > 1 && abs(CompRank - WhiteKingY) > 1 && (abs(CompFile - WhiteKingX) > abs(InitFile - WhiteKingX) || abs(CompRank - WhiteKingY) > abs(InitRank - WhiteKingY)) ) KingTally[AA] = KingTally[AA] - 2;
2870 if(!strcmp(Turn, "Black") && CompRank <= PromDotY ) KingTally[AA] = KingTally[AA] + 3;
2871 if(!strcmp(Turn, "White") && CompRank > BoardSizeY - PromDotY ) KingTally[AA] = KingTally[AA] + 3;
2872 if(BoardSizeY > 11 ) {
2873 if(!strcmp(Turn, "Black") && Pieces[abs(CompLegal[AA].EndPiece)].Range != 1 && InitRank > CompRank ) KingTally[AA] = KingTally[AA] + 3;
2874 if(!strcmp(Turn, "White") && Pieces[abs(CompLegal[AA].EndPiece)].Range != 1 && InitRank < CompRank ) KingTally[AA] = KingTally[AA] + 3;
2875 if(!strcmp(Turn, "Black") && Pieces[abs(CompLegal[AA].EndPiece)].Range == 1 && InitRank < CompRank ) KingTally[AA] = KingTally[AA] + 2;
2876 if(!strcmp(Turn, "White") && Pieces[abs(CompLegal[AA].EndPiece)].Range == 1 && InitRank > CompRank ) KingTally[AA] = KingTally[AA] + 2;
2878 if(!strcmp(Turn, "Black") && InitRank < BoardSizeY * .35 ) {
2879 if(abs(InitFile - WhiteKingX) > abs(CompFile - WhiteKingX) || abs(InitRank - WhiteKingY) > abs(CompRank - WhiteKingY) ) KingTally[AA] = KingTally[AA] + 5;
2881 if(!strcmp(Turn, "White") && InitRank > BoardSizeY * .65 ) {
2882 if(abs(InitFile - BlackKingX) > abs(CompFile - BlackKingX) || abs(InitRank - BlackKingY) > abs(CompRank - BlackKingY) ) KingTally[AA] = KingTally[AA] + 5;
2886 void KnightJump ()
2888 if(abs(RankInc) == 1 ) {
2889 NewFile = InitFile + 1; NewRank = InitRank + (RankInc * 2);
2890 if(NewFile <= BoardSizeX && NewRank > 0 && NewRank <= BoardSizeY ) ShowMove();
2891 NewFile = InitFile - 1;
2892 if(NewFile > 0 && NewRank > 0 && NewRank <= BoardSizeY ) ShowMove();
2894 if(abs(FileInc) == 1 ) {
2895 NewRank = InitRank + 1; NewFile = InitFile + (FileInc * 2);
2896 if(NewRank <= BoardSizeY && NewFile > 0 && NewFile <= BoardSizeX ) ShowMove();
2897 NewRank = InitRank - 1;
2898 if(NewRank > 0 && NewFile > 0 && NewFile <= BoardSizeX ) ShowMove();
2902 void Lion ()
2904 INT X, Y;
2905 if(Teach == 1 ) {
2906 Lion2();
2907 } else {
2908 for(Y = InitRank - 2; Y <= InitRank + 2; Y++) {
2909 for(X = InitFile - 2; X <= InitFile + 2; X++) {
2910 if(X > 0 && X <= BoardSizeX && Y > 0 && Y <= BoardSizeY ) {
2911 if(Squares[X][Y] == 0 || Sgn(Squares[X][Y]) != Sgn(Squares[InitFile][InitRank]) || (Influence > 0 && (Y != InitRank || X != InitFile)) ) {
2912 if(abs(Y - InitRank) <= 1 && abs(X - InitFile) <= 1 ) {
2913 Board.FillColor = 0xFF0000;
2914 NewRank = Y; NewFile = X;
2915 if(!strcmp(Choice, "Tenjiku") ) CheckBurn();
2916 if(LegalMoves > 0 && Squares[X][Y] != 0 && strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Teaching King") ) {
2917 if(Evaluate == 0 && CompMove == 1 && Influence != 1 ) CompLion();
2918 Legal[X][Y] = 1;
2919 } else {
2920 Legal[X][Y] = 2;
2922 } else {
2923 Legal[X][Y] = 1;
2924 NewRank = Y; NewFile = X;
2925 if(!strcmp(Choice, "Chu") && Squares[X][Y] != 0 && ChuLionTest != 1 ) {
2926 if(!strcmp(Pieces[abs(Squares[X][Y])].Name, "Lion") ) ChuLion();
2928 Board.FillColor = 0xFFFF00;
2929 if(!strcmp(Choice, "Tenjiku") ) CheckBurn();
2931 if(SeeMove == 1 && ProtectLion != 1 && CompLionTest != 1 && Legal[X][Y] > 0 ) { SeeFile = X; SeeRank = Y; LookMove(); }
2932 ProtectLion = 0; CompLionTest = 0;
2935 } // Next X;
2936 } // Next Y;
2940 void Lion2 ()
2942 INT X, Y;
2943 for(Y = InitRank - 1; Y <= InitRank + 1; Y++) {
2944 for(X = InitFile - 1; X <= InitFile + 1; X++) {
2945 if(X > 0 && X <= BoardSizeX && Y > 0 && Y <= BoardSizeY ) {
2946 if(Squares[X][Y] == 0 || Sgn(Squares[X][Y]) != Sgn(Squares[InitFile][InitRank]) || Influence == 2 ) {
2947 Legal[X][Y] = 1;
2948 Board.FillColor = 0xFFFF00;
2949 if(SeeMove == 1 ) { SeeFile = X; SeeRank = Y; LookMove(); }
2950 NewFile = X; NewRank = Y;
2951 if(!strcmp(Choice, "Tenjiku") ) CheckBurn();
2954 } // Next X;
2955 } // Next Y;
2958 void LionBurn ()
2960 INT K, L;
2961 for(K = Rank - 1; K <= Rank + 1; K++) {
2962 for(L = File - 1; L <= File + 1; L++) {
2963 if(LionTest != 1 && L > 0 && L <= BoardSizeX && K > 0 && K <= BoardSizeY ) {
2964 if((K != Rank || L != File) && Squares[L][K] != 0 ) {
2965 if(Pieces[abs(Squares[L][K])].special == 'F' && Sgn(Squares[File][Rank]) != Sgn(Squares[L][K]) ) LionBurn2();
2968 } // Next L;
2969 } // Next K;
2970 LionTest = 0;
2973 void LionBurn2 ()
2975 Score[TurnCount].IDEnd = 0;
2976 strcat(CMoveSTR, "*");
2977 Grafix[File][Rank] = -1;
2978 Board.showpic[I].Visible = False;
2979 MOVE(1, Board.showpic[I], 0, 0);
2980 Squares[File][Rank] = 0;
2981 LionTest = 1;
2984 void LionIgui ()
2986 INT K, L, MMM;
2987 if(BoardSizeY > 11 ) {
2988 MMM = 0;
2989 for(K = 1; K <= BoardSizeY; K++) {
2990 for(L = 1; L <= BoardSizeX; L++) {
2991 if(Grafix[L][K] == I ) { File = L; Rank = K; MMM = 1; break; }
2992 } // Next L;
2993 if(MMM == 1 ) break;
2994 } // Next K;
2995 if(MMM == 1 && ((!strcmp(Turn, "Black") && Squares[File][Rank] > 0) || (!strcmp(Turn, "White") && Squares[File][Rank] < 0)) ) {
2997 if(Pieces[abs(Squares[File][Rank])].special == 'L' || !strcmp(Pieces[abs(Squares[File][Rank])].Name, "Horned Falcon") || !strcmp(Pieces[abs(Squares[File][Rank])].Name, "Soaring Eagle") || (!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Teaching King") && TeachVer == 2) ) {
2998 InitFile = File; InitRank = Rank;
2999 Score[TurnCount].IDStart = Squares[File][Rank];
3000 Score[TurnCount].IDEnd = Squares[File][Rank];
3001 Score[TurnCount].PosStart = (InitRank * (BoardSizeX + 1)) + InitFile;
3002 Score[TurnCount].PosEnd = (InitRank * (BoardSizeX + 1)) + InitFile;
3003 sprintf(CMoveSTR + strlen(CMoveSTR), "%s!", TrimSTR(Pieces[abs(Squares[InitFile][InitRank])].sname));
3004 LastPieceX = File; LastPieceY = Rank;
3005 Ligui = 1;
3006 strcpy(ShortScore[TurnCount + 1], CMoveSTR);
3007 NextTurn();
3013 void LionPower ()
3015 INT K;
3016 for(K = 1; K <= 2; K++) {
3017 C = InitFile; D = InitRank;
3018 NewFile = InitFile + (FileInc * K); NewRank = InitRank + (RankInc * K);
3019 if(NewFile > 0 && NewFile <= BoardSizeX && NewRank > 0 && NewRank <= BoardSizeY ) {
3020 if(Squares[NewFile][NewRank] == 0 || Sgn(Squares[InitFile][InitRank]) != Sgn(Squares[NewFile][NewRank]) || (Influence > 0 && (NewFile != InitFile || NewRank != InitRank)) ) {
3021 if(K == 1 ) {
3022 Board.FillColor = 0xFF0000;
3023 if(!strcmp(Choice, "Tenjiku") ) CheckBurn();
3024 if(LegalMoves > 0 && Squares[NewFile][NewRank] != 0 ) {
3025 if(CompMove == 1 && Evaluate == 0 && Influence != 1 ) CompLionPower();
3026 Legal[NewFile][NewRank] = 1;
3027 } else {
3028 Legal[NewFile][NewRank] = 2;
3030 } else {
3031 Board.FillColor = 0xFFFF00;
3032 Legal[NewFile][NewRank] = 1;
3033 if(!strcmp(Choice, "Tenjiku") ) CheckBurn();
3035 if(SeeMove == 1 && CompLionTest != 1 && Legal[NewFile][NewRank] != 0 ) { SeeFile = NewFile; SeeRank = NewRank; LookMove(); }
3036 CompLionTest = 0;
3039 } // Next K;
3042 void LionPower2 ()
3044 INT X, Y;
3045 Legal[C][D] = 1;
3046 Board.FillColor = 0xFFFF00;
3047 SeeFile = C; SeeRank = D; LookMove();
3048 X = InitFile + (InitFile - C);
3049 Y = InitRank + (InitRank - D);
3050 if(X > 0 && X <= BoardSizeX && Y > 0 && Y <= BoardSizeY ) {
3051 if(Squares[X][Y] == 0 || Sgn(Squares[InitFile][InitRank]) != Sgn(Squares[X][Y]) || (Influence == 2 && (NewFile != InitFile || NewRank != InitRank)) ) {
3052 Legal[X][Y] = 1;
3053 if(SeeMove == 1 ) { SeeFile = X; SeeRank = Y; LookMove(); }
3054 NewFile = X; NewRank = Y;
3055 if(!strcmp(Choice, "Tenjiku") ) CheckBurn();
3060 void LoadGame ()
3061 { // Menu function.
3062 INT Location;
3063 // TODO: On Error Resume Next;
3064 strcpy(Board.CMSave.DialogTitle, "Load Game");
3065 Board.CMSave.Flags = 0x1000L;
3066 Board.CMSave.Action = 1;
3067 if(Err == 32755 ) return; // TODO
3068 strcpy(LoadedSTR, Board.CMSave.Filename);
3069 Loading = 1;
3070 strcpy(OldChoice, Choice);
3071 f2 = fopen(LoadedSTR, "r");
3072 fscanf(f2, "\"%[^\"]\",", Choice);
3073 if(!strcmp(Choice, "Tai") && Display < 800 ) {
3074 TooSmall();
3075 strcpy(Choice, OldChoice);
3076 Loading = 0;
3077 fclose(f2);
3078 } else {
3079 UnloadPieceHelp();
3080 // TODO: Unload RulesHelp;
3081 Board.MousePointer = 11;
3082 if(!strcmp(Choice, OldChoice) ) UnloadBoard();
3083 StartUp();
3084 fscanf(f2, "%s", SaveTitleSTR);
3085 if(strcmp(SaveTitleSTR, "") ) {
3086 strcpy(Cap, SaveTitleSTR);
3087 strcpy(Board.Caption, Cap);
3089 fscanf(f2, "\"%[^\"]\",", Computer);
3090 fscanf(f2, "%d", &Level);
3091 fscanf(f2, "%d", &GameOver);
3092 fscanf(f2, "\"%[^\"]\"", Threat);
3093 fclose(f2);
3094 EndTurn = TurnCount;
3095 ConfigLoad();
3096 Loading = 0;
3097 Board.MnuHandicap.Enabled = False;
3098 if(GameOver != 1 ) ConvertScore();
3099 if(Asc(Score[TurnCount].Caption) > 47 && Asc(Score[TurnCount].Caption) < 58 ) {
3100 strcpy(Board.LastMove.Caption, Score[TurnCount].Caption);
3101 } else {
3102 sprintf(Board.LastMove.Caption, "%d. %s", MoveCount, Score[TurnCount].Caption);
3104 if(TurnCount > 0 ) {
3105 Location = Score[TurnCount - 1].PosEnd;
3106 if(Location > 0 ) {
3107 Rank = Int(Location / (BoardSizeX + 1));
3108 File = Location - (Rank * (BoardSizeX + 1));
3110 LastPieceX = File; LastPieceY = Rank;
3111 } else {
3112 LastPieceX = -1; LastPieceY = -1;
3117 void LoadGame2 ()
3119 INT Location;
3120 // TODO: On Error Resume Next;
3121 strcpy(Start.CMSave.DialogTitle, "Load Game");
3122 Start.CMSave.Flags = 0x1000L;
3123 Start.CMSave.Action = 1;
3124 if(Err == 32755 ) return; // TODO
3125 strcpy(LoadedSTR, Start.CMSave.Filename);
3126 Start.MousePointer = 11;
3127 Loading = 1;
3128 strcpy(OldChoice, Choice);
3129 f2 = fopen(LoadedSTR, "r");
3130 fscanf(f2, "%s", Choice);
3131 if(!strcmp(Choice, "Tai") && Display < 800 ) {
3132 TooSmall();
3133 strcpy(Choice, OldChoice);
3134 Loading = 0;
3135 fclose(f2);
3136 } else {
3137 UnloadPieceHelp();
3138 // TODO: Unload RulesHelp;
3139 UnloadBoard();
3140 StartUp();
3141 fscanf(f2, "%s", SaveTitleSTR);
3142 if(strcmp(SaveTitleSTR, "") ) strcpy(Board.Caption, SaveTitleSTR);
3143 fscanf(f2, "\"%[^\"]\"", Computer);
3144 fscanf(f2, "%d", &Level);
3145 fscanf(f2, "%d", &GameOver);
3146 fscanf(f2, "\"%[^\"]\"", Threat);
3147 fclose(f2);
3148 // Start.Hide();
3149 Start.MousePointer = 0;
3150 ConfigLoad();
3151 Loading = 0;
3152 EndTurn = TurnCount;
3153 Board.MnuHandicap.Enabled = False;
3154 EnableNamedMenuItem("Setup.Handicap", False); // [HGM] added
3155 if(GameOver != 1 ) ConvertScore();
3156 if(Asc(Score[TurnCount].Caption) > 47 && Asc(Score[TurnCount].Caption) < 58 ) {
3157 strcpy(Board.LastMove.Caption, Score[TurnCount].Caption);
3158 } else {
3159 sprintf(Board.LastMove.Caption, "%d. %s", MoveCount, Score[TurnCount].Caption);
3161 if(TurnCount > 0 ) {
3162 Location = Score[TurnCount - 1].PosEnd;
3163 if(Location > 0 ) {
3164 Rank = Int(Location / (BoardSizeX + 1));
3165 File = Location - (Rank * (BoardSizeX + 1));
3167 LastPieceX = File; LastPieceY = Rank;
3168 } else {
3169 LastPieceX = -1; LastPieceY = -1;
3174 void LookAhead ()
3176 INT DDD, ZZZZ;
3177 if(!strcmp(Turn, "White") ) strcpy(Turn, "Black"); else strcpy(Turn, "White");
3178 RealLevel = Level; Level = 0;
3179 for(YYY = 1; YYY <= BoardSizeY; YYY++) {
3180 for(XXX = 1; XXX <= BoardSizeX; XXX++) {
3181 TestBoard[XXX][YYY] = Comp[XXX][YYY];
3182 } // Next XXX;
3183 } // Next YYY;
3184 if(Drop == 1 ) {
3185 for(DDD = 1; DDD <= Capture * 2; DDD++) {
3186 OldHand[DDD] = InHand[DDD];
3187 } // Next DDD;
3189 for(Depth = 1; Depth <= TestDepth; Depth++) {
3190 if(MoveList[Depth].StartFile != 0 ) Comp[MoveList[Depth].StartFile][MoveList[Depth].StartRank] = 0;
3191 Comp[MoveList[Depth].EndFile][MoveList[Depth].EndRank] = MoveList[Depth].EndPiece;
3192 if(MoveList[Depth].StartFile == 0 ) {
3193 for(DDD = 1; DDD <= Capture * 2; DDD++) {
3194 if(MoveList[Depth].EndPiece == CapRef[DDD] ) InHand[DDD] = InHand[DDD] - 1;
3195 } // Next DDD;
3197 TestAhead();
3198 FinalTally[Depth] = BestTally[0] - OldKingTally[Depth];
3199 for(YYY = 1; YYY <= BoardSizeY; YYY++) {
3200 for(XXX = 1; XXX <= BoardSizeX; XXX++) {
3201 Comp[XXX][YYY] = TestBoard[XXX][YYY];
3202 } // Next XXX;
3203 } // Next YYY;
3204 if(Drop == 1 ) {
3205 for(DDD = 1; DDD <= Capture * 2; DDD++) {
3206 InHand[DDD] = OldHand[DDD];
3207 } // Next DDD;
3209 } // Next Depth;
3210 Level = RealLevel; BestMove = TestDepth; BestScore = FinalTally[TestDepth];
3211 if(!strcmp(Turn, "White") ) strcpy(Turn, "Black"); else strcpy(Turn, "White");
3212 for(ZZZZ = 1; ZZZZ <= TestDepth - 1; ZZZZ++) {
3213 if(FinalTally[ZZZZ] < BestScore ) {
3214 BestMove = ZZZZ;
3215 BestScore = FinalTally[ZZZZ];
3217 } // Next ZZZZ;
3218 CompLegal[BestMove].StartFile = MoveList[BestMove].StartFile;
3219 CompLegal[BestMove].StartRank = MoveList[BestMove].StartRank;
3220 CompLegal[BestMove].StartPiece = MoveList[BestMove].StartPiece;
3221 CompLegal[BestMove].EndFile = MoveList[BestMove].EndFile;
3222 CompLegal[BestMove].EndRank = MoveList[BestMove].EndRank;
3223 CompLegal[BestMove].EndPiece = MoveList[BestMove].EndPiece;
3224 if(!strcmp(Choice, "Dai") || !strcmp(Choice, "Chu") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Tai") ) {
3225 LionVictim.Piece = ECapture[BestMove].Piece;
3226 LionVictim.File = ECapture[BestMove].File;
3227 LionVictim.Rank = ECapture[BestMove].Rank;
3231 void LookCheck ()
3233 INT EFF, GHH;
3234 if(!strcmp(Turn, "White") && BlackKing == 0 ) {
3235 OriginalPiece = Squares[BlackKingX][BlackKingY];
3236 OriginalFile = BlackKingX; OriginalRank = BlackKingY;
3237 } else {
3238 if(!strcmp(Turn, "Black") && WhiteKing == 0 ) {
3239 OriginalPiece = Squares[WhiteKingX][WhiteKingY];
3240 OriginalFile = WhiteKingX; OriginalRank = WhiteKingY;
3243 Influence = 0;
3244 CheckTest = 1;
3245 CheckLooked = 0;
3246 LookCheck2();
3247 CheckTest = 0;
3248 if(GameOver == 1 || Checked > 0 ) return;
3249 for(GHH = 1; GHH <= BoardSizeY; GHH++) {
3250 for(EFF = 1; EFF <= BoardSizeX; EFF++) {
3251 if(Squares[EFF][GHH] != 0 ) {
3253 if(abs(Squares[EFF][GHH]) == 1 || !strcmp(Pieces[abs(Squares[EFF][GHH])].Name, "Emperor") || !strcmp(Pieces[abs(Squares[EFF][GHH])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[EFF][GHH])].Name, "Prince") ) {
3254 OriginalPiece = Squares[EFF][GHH];
3255 OriginalFile = EFF; OriginalRank = GHH;
3256 Influence = 0;
3257 CheckTest = 1;
3258 CheckLooked = 0;
3259 LookCheck2();
3260 CheckTest = 0;
3261 if(GameOver == 1 || Checked > 0 ) return;
3264 } // Next EFF;
3265 } // Next GHH;
3266 CheckTest = 0;
3269 void LookCheck2 ()
3271 INT ABB, CDD;
3272 for(ABB = 1; ABB <= BoardSizeY; ABB++) {
3273 for(CDD = 1; CDD <= BoardSizeX; CDD++) {
3274 if(Squares[CDD][ABB] != 0 ) {
3275 if(Sgn(OriginalPiece) != Sgn(Squares[CDD][ABB]) && strcmp(Pieces[abs(Squares[CDD][ABB])].Name, "Emperor") ) {
3276 InitFile = CDD; InitRank = ABB;
3277 Validate();
3278 if(GameOver == 1 || Checked > 0 ) { Influence = 0; return; }
3281 } // Next CDD;
3282 } // Next ABB;
3283 Influence = 0;
3286 void LookComp ()
3288 Attacker[SeeFile][SeeRank] = Attacker[SeeFile][SeeRank] + 1;
3289 BanMap[SeeFile][SeeRank].Info[Attacker[SeeFile][SeeRank]].File = InitFile;
3290 BanMap[SeeFile][SeeRank].Info[Attacker[SeeFile][SeeRank]].Rank = InitRank;
3291 BanMap[SeeFile][SeeRank].Info[Attacker[SeeFile][SeeRank]].Piece = Squares[InitFile][InitRank];
3292 if(Squares[InitFile][InitRank] < 0 ) {
3293 BanMap[SeeFile][SeeRank].WhiteNum = BanMap[SeeFile][SeeRank].WhiteNum + 1;
3294 } else {
3295 BanMap[SeeFile][SeeRank].BlackNum = BanMap[SeeFile][SeeRank].BlackNum + 1;
3297 DoEvents();
3299 if(FirstTime == 1 ) LookComp2();
3302 void LookComp2 ()
3304 OldAttack[SeeFile][SeeRank] = Attacker[SeeFile][SeeRank];
3305 BackMap[SeeFile][SeeRank].Info[Attacker[SeeFile][SeeRank]].File = InitFile;
3306 BackMap[SeeFile][SeeRank].Info[Attacker[SeeFile][SeeRank]].Rank = InitRank;
3307 BackMap[SeeFile][SeeRank].Info[Attacker[SeeFile][SeeRank]].Piece = Squares[InitFile][InitRank];
3308 if(Squares[InitFile][InitRank] < 0 ) {
3309 BackMap[SeeFile][SeeRank].WhiteNum = BanMap[SeeFile][SeeRank].WhiteNum;
3310 } else {
3311 BackMap[SeeFile][SeeRank].BlackNum = BanMap[SeeFile][SeeRank].BlackNum;
3315 void LookForMate ()
3317 STRING OldTurn;
3318 LookMate = 1;
3319 strcpy(OldComputer, Computer);
3320 strcpy(Computer, Turn2); strcpy(OldTurn, Turn); strcpy(Turn, Turn2);
3321 RealLevel = Level; Level = 0;
3322 CompMain();
3323 Level = RealLevel;
3324 LookMate = 0; LegalMoves = 0; strcpy(Turn, OldTurn);
3325 strcpy(Computer, OldComputer);
3328 void LookMove ()
3330 INT L, EF;
3331 int Response;
3332 if(ChuLionTest == 1 ) {
3333 if(SeeFile == OldNewFile && SeeRank == OldNewRank ) { ProtectLion = 1; return; }
3334 } else {
3335 if(Evaluate == 1 ) {
3336 LookComp();
3337 } else {
3338 if(CompMove == 1 && Influence != 2 && Evaluate == 0 ) {
3339 AddLegalMove();
3340 } else {
3341 if((Influence < 1 && CheckTest != 1) ) {
3342 if(Reverse == 0 ) {
3343 Board.Circle(XStart + (SeeFile - 1) * Pixels + (Pixels / 2), 11 + (SeeRank - 1) * Pixels + (Pixels / 2), Pixels / 4);
3344 } else {
3345 Board.Circle(XStart + (BoardSizeX - SeeFile) * Pixels + (Pixels / 2), 11 + (BoardSizeY - SeeRank) * Pixels + (Pixels / 2), Pixels / 4);
3347 } else {
3348 if(Influence == 2 ) {
3349 if(Legal[SeeFile][SeeRank] > 0 ) {
3350 if(Squares[InitFile][InitRank] < 0 ) {
3351 if((Camps[SeeFile][SeeRank] != 2 && Camps[SeeFile][SeeRank] != 3) ) Camps[SeeFile][SeeRank] = 1; else Camps[SeeFile][SeeRank] = 3;
3352 } else {
3353 if((Camps[SeeFile][SeeRank] != 1 && Camps[SeeFile][SeeRank] != 3) ) Camps[SeeFile][SeeRank] = 2; else Camps[SeeFile][SeeRank] = 3;
3356 } else {
3357 if(OriginalFile == SeeFile && OriginalRank == SeeRank ) {
3358 if(CheckTest == 1 && CheckLooked == 0 ) {
3359 Response = 0;
3360 if(OriginalPiece > 0 && !strcmp(Turn, "White") && strcmp(Computer, "Black") && strcmp(Computer, "Both") && ((BlackKing == 0 && BlackPrince > 0) || (!strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai"))) ) { Response = MsgBox((sprintf(StringTmp, "You have left your %s in Check! ", Pieces[abs(OriginalPiece)].Name), StringTmp), 0, "Black"); Response = 6; }
3361 if(OriginalPiece < 0 && !strcmp(Turn, "Black") && strcmp(Computer, "White") && strcmp(Computer, "Both") && ((WhiteKing == 0 && WhitePrince > 0) || (!strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai"))) ) { Response = MsgBox((sprintf(StringTmp, "You have left your %s in Check! ", Pieces[abs(OriginalPiece)].Name), StringTmp), 0, "White"); Response = 6; }
3362 if(strcmp(Choice, "Tenjiku") && strcmp(Choice, "Maka") && strcmp(Choice, "Tai") ) {
3363 if(OriginalPiece > 0 && !strcmp(Turn, "White") && strcmp(Computer, "Black") && strcmp(Computer, "Both") && (BlackKing == 1 || BlackPrince == 0) ) { Response = MsgBox((sprintf(StringTmp, "You can't leave your %s in Check! ", Pieces[abs(OriginalPiece)].Name), StringTmp), 0, "Black"); Response = 7; }
3364 if(OriginalPiece < 0 && !strcmp(Turn, "Black") && strcmp(Computer, "White") && strcmp(Computer, "Both") && (WhiteKing == 1 || WhitePrince == 0) ) { Response = MsgBox((sprintf(StringTmp, "You can't leave your %s in Check! ", Pieces[abs(OriginalPiece)].Name), StringTmp), 0, "White"); Response = 7; }
3366 Legal[SeeFile][SeeRank] = 0;
3367 CheckLooked = 1;
3368 if(Response != 7 ) {
3369 if((OriginalPiece > 0 && (BlackKing == 1 || BlackPrince == 0)) || (OriginalPiece < 0 && (WhiteKing == 1 || WhitePrince == 0)) && strcmp(Choice, "Tenjiku") && strcmp(Choice, "Maka") && strcmp(Choice, "Tai") ) {
3370 if(OriginalPiece < 0 ) strcpy(Turn2, "White"); else strcpy(Turn2, "Black");
3371 LookForMate();
3373 SeeMove = OldSeeMove;
3374 if(!strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai") ) { BestTally[0] = 0; strcpy(Turn2, Turn); }
3375 if(BestTally[0] == -999999 ) {
3376 if(!strcmp(Turn2, "Black") ) strcpy(Board.PieceID.Caption, "Checkmate! White wins."); else strcpy(Board.PieceID.Caption, "Checkmate! Black wins.");
3377 Notice = 5; BestTally[0] = -99999;
3378 GameOver = 1;
3379 return;
3380 } else {
3381 if(Response != 6 ) {
3382 sprintf(Board.PieceID.Caption, "%s %s is in Check!", Turn2, Pieces[abs(OriginalPiece)].Name);
3383 Notice = 1;
3385 Checked = 1;
3386 return;
3388 } else {
3389 Checked = 2;
3390 SeeMove = OldSeeMove;
3392 } else {
3393 if(CheckTest != 1 ) {
3394 L = 0;
3395 if(!strcmp(Choice, "Heian") || !strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "Tenjiku") ) L = 1;
3396 if(Squares[InitFile][InitRank] > 0 ) {
3397 BlackInfluence = 1;
3398 Board.ForeColor = 0x606060;
3399 } else {
3400 WhiteInfluence = 1;
3401 Board.ForeColor = 0xFFFFFF;
3403 Legal[SeeFile][SeeRank] = 0;
3404 for(EF = 1; EF < Pixels; EF++) { // FIXME: lowered EF by 1 to access correct PieceMask elements ???
3405 if(Reverse == 0 ) {
3406 if(Squares[InitFile][InitRank] > 0 ) {
3407 Board.Line(XStart + (InitFile - 1) * Pixels + EF /*- 2*/ + L, 11 + (InitRank - 1) * Pixels + L, XStart + (InitFile - 1) * Pixels + EF /*- 2*/ + L, 11 + (InitRank - 1) * Pixels + PieceMask[Pieces[abs(Squares[InitFile][InitRank])].Mask][EF] + 1, NOCOLOR, ""); // FIXME: added 2 to x
3408 } else {
3409 Board.Line(XStart + (InitFile - 1) * Pixels + (Pixels - EF) + L, 9 + (InitRank * Pixels) + L + 1, XStart + (InitFile - 1) * Pixels + (Pixels - EF) + L, 8 + (InitRank * Pixels) - (PieceMask[Pieces[abs(Squares[InitFile][InitRank])].Mask][EF] - (L * 2)) + 1, NOCOLOR, ""); // FIXME: added 1 to y
3411 } else {
3412 if(Squares[InitFile][InitRank] > 0 ) {
3413 Board.Line(XStart + (BoardSizeX - InitFile) * Pixels + (Pixels - EF) + L, 8 + (BoardSizeY - InitRank + 1) * Pixels + 1 + L + 1, XStart + (BoardSizeX - InitFile) * Pixels + (Pixels - EF) + L, 8 + (BoardSizeY - InitRank + 1) * Pixels - PieceMask[Pieces[abs(Squares[InitFile][InitRank])].Mask][EF] + (L * 2) + 1, NOCOLOR, ""); // FIXME: added 1 to y2
3414 } else {
3415 Board.Line(XStart + (BoardSizeX - InitFile) * Pixels + EF /*- 2*/ + L, 10 + (BoardSizeY - InitRank) * Pixels + 1 + L, XStart + (BoardSizeX - InitFile) * Pixels + EF /*- 2*/ + L, 12 + (BoardSizeY - InitRank) * Pixels + PieceMask[Pieces[abs(Squares[InitFile][InitRank])].Mask][EF], NOCOLOR, ""); // FIXME: added 2 to x
3418 } // Next EF;
3421 Legal[SeeFile][SeeRank] = 0;
3422 Board.ForeColor = 0x0L;
3423 Board.FillColor = 0xFFFFFF;
3432 void Main ()
3434 int Response; // read-only?
3435 // TODO: initialize screen params
3436 // if(screen.Width / screen.TwipsPerPixelY > 650 ) Display = 800; else Display = 640;
3437 // if(screen.Width / screen.TwipsPerPixelY > 810 ) Display = 1240;
3438 LoadStart();
3439 if(Start.ScaleWidth > 640 ) {
3440 UnloadStart();
3441 Response = MsgBox("This program will not run with LARGE FONTS. You must change your display settings to SMALL FONTS before running the program.", 0, "Shogi Variants 1.55a");
3445 void MakeDrop ()
3447 INT DD;
3448 File = CompLegal[BestMove].EndFile;
3449 Rank = CompLegal[BestMove].EndRank;
3450 for(DD = 1; DD <= Capture * 2; DD++) {
3451 if(CompLegal[BestMove].EndPiece == CapRef[DD] ) I = DD;
3452 } // Next DD;
3453 HeldDrop();
3456 void MakeMap ()
3458 INT FF, GG;
3459 for(FF = 1; FF <= BoardSizeY; FF++) {
3460 for(GG = 1; GG <= BoardSizeX; GG++) {
3461 Attacker[GG][FF] = 0; OldAttack[GG][FF] = 0;
3462 BanMap[GG][FF].WhiteNum = 0; BackMap[GG][FF].WhiteNum = 0;
3463 BanMap[GG][FF].BlackNum = 0; BackMap[GG][FF].BlackNum = 0;
3464 BanMap[GG][FF].WhiteValue = 0; BackMap[GG][FF].WhiteValue = 0;
3465 BanMap[GG][FF].BlackValue = 0; BackMap[GG][FF].BlackValue = 0;
3466 } // Next GG;
3467 } // Next FF;
3468 FirstTime = 1;
3469 for(FF = 1; FF <= BoardSizeY; FF++) {
3470 for(GG = 1; GG <= BoardSizeX; GG++) {
3471 if(Squares[GG][FF] != 0 ) {
3472 InitFile = GG; InitRank = FF;
3473 Validate();
3475 } // Next GG;
3476 } // Next FF;
3477 FirstTime = 0;
3480 void MicroAdd ()
3482 if((MicroCap > 4 && MicroCap < 9) || MicroCap > 12 ) {
3483 InHand[MicroCap - 4] = InHand[MicroCap - 4] + 1;
3484 Board.HandPic[MicroCap - 4].Visible = True;
3485 if(InHand[MicroCap - 4] > 1 ) sprintf(Board.Held[MicroCap - 4].Caption, "%d", InHand[MicroCap - 4]);
3486 } else {
3487 InHand[MicroCap + 4] = InHand[MicroCap + 4] + 1;
3488 Board.HandPic[MicroCap + 4].Visible = True;
3489 if(InHand[MicroCap + 4] > 1 ) sprintf(Board.Held[MicroCap + 4].Caption, "%d", InHand[MicroCap + 4]);
3493 void MicroDrop ()
3495 if((I < 5) || (I > 8 && I < 13) ) {
3496 InHand[I + 4] = InHand[I + 4] - 1;
3497 if(InHand[I + 4] < 1 ) Board.HandPic[I + 4].Visible = False;
3498 if(InHand[I + 4] < 2 ) strcpy(Board.Held[I + 4].Caption, ""); else sprintf(Board.Held[I - 4].Caption, "%d", InHand[I - 4]);
3499 } else {
3500 InHand[I - 4] = InHand[I - 4] - 1;
3501 if(InHand[I - 4] < 1 ) Board.HandPic[I - 4].Visible = False;
3502 if(InHand[I - 4] < 2 ) strcpy(Board.Held[I - 4].Caption, ""); else sprintf(Board.Held[I - 4].Caption, "%d", InHand[I - 4]);
3506 void Move2 ()
3508 INT K, L;
3509 for(K = 1; K <= BoardSizeY; K++) {
3510 for(L = 1; L <= BoardSizeX; L++) {
3511 if(Grafix[L][K] == I ) {
3512 InitFile = L;
3513 InitRank = K;
3515 } // Next L;
3516 } // Next K;
3517 DRAG(Board.showpic[Grafix[InitFile][InitRank]], 1);
3518 strcpy(Board.PieceID.Caption, Pieces[abs(Squares[InitFile][InitRank])].Name);
3521 void MoveFormDrop ()
3523 if(NewX > XStart && NewX < XStart + (BoardSizeX * Pixels) && NewY > 11 && NewY < 11 + (BoardSizeY * Pixels) ) {
3524 GetSquare2();
3525 Squares[File][Rank] = Squares[InitFile][InitRank];
3526 Squares[InitFile][InitRank] = 0;
3527 Grafix[File][Rank] = I;
3528 Grafix[InitFile][InitRank] = -1;
3529 if(Reverse == 0 ) {
3530 MOVE(1, Board.showpic[I], XStart + ((File - 1) * Pixels), 11 + ((Rank - 1) * Pixels));
3531 } else {
3532 MOVE(1, Board.showpic[I], XStart + ((BoardSizeX - File) * Pixels), 11 + ((BoardSizeY - Rank) * Pixels));
3534 ClearLegal();
3538 void MovePicDrop ()
3540 STRING VictimSTR;
3541 INT K, L;
3542 for(K = 1; K <= BoardSizeY; K++) {
3543 for(L = 1; L <= BoardSizeX; L++) {
3544 File = L; Rank = K;
3545 if(Grafix[L][K] == NewIndex ) {
3546 if((L != InitFile) || (K != InitRank) ) {
3547 Board.showpic[I].Visible = False;
3548 Grafix[L][K] = I;
3549 Grafix[InitFile][InitRank] = -1;
3550 Board.showpic[NewIndex].Visible = False;
3551 MOVE(1, Board.showpic[NewIndex], 0, 0);
3552 if(Reverse == 0 ) {
3553 MOVE(1, Board.showpic[I], XStart + ((L - 1) * Pixels), 11 + ((K - 1) * Pixels));
3554 } else {
3555 MOVE(1, Board.showpic[I], XStart + ((BoardSizeX - L) * Pixels), 11 + ((BoardSizeY - K) * Pixels));
3557 Board.showpic[I].Visible = True;
3558 strcpy(VictimSTR, Pieces[abs(Squares[File][Rank])].Name);
3559 if(Squares[File][Rank] > 0 && (!strcmp(VictimSTR, "Prince") || !strcmp(VictimSTR, "Crown Prince")) ) BlackPrince = BlackPrince - 1;
3560 if(Squares[File][Rank] < 0 && (!strcmp(VictimSTR, "Prince") || !strcmp(VictimSTR, "Crown Prince")) ) WhitePrince = WhitePrince - 1;
3561 Squares[L][K] = Squares[InitFile][InitRank];
3562 Squares[InitFile][InitRank] = 0;
3565 } // Next L;
3566 } // Next K;
3569 void MovePieces ()
3570 { // Menu function. (Calls EndSetup() before.)
3571 Board.Refresh();
3572 strcpy(Board.Caption, "Move Pieces with Left Mouse Button (Press Right Mouse Button to Finish)");
3573 MovePiece = 1;
3574 strcpy(Board.BlackClock.Caption, "00:00:00");
3575 strcpy(Board.WhiteClock.Caption, "00:00:00");
3576 Board.Timer1.Enabled = False;
3579 void NextTurn ()
3581 if(CompMove == 1 ) {
3582 NextTurn2();
3583 } else {
3584 if(Notice < 1 ) strcpy(Board.Caption, Cap);
3585 Board.MnuHandicap.Enabled = False;
3586 EnableNamedMenuItem("Setup.Handicap", False); // [HGM] added
3587 if((!strcmp(Choice, "Micro") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai")) && Taken == 1 ) Promessage();
3588 if(!strcmp(Choice, "Chu") ) {
3589 if(Squares[File][Rank] == 2 && (Rank == 2 || Rank == 3) ) NoPro = 1;
3590 if(Squares[File][Rank] == -2 && (Rank == 10 || Rank == 11) ) NoPro = 1;
3591 if(Squares[File][Rank] == LastBlack && Taken != 1 ) {
3592 NoPro = 1;
3593 LastBlack = 0;
3595 if(Squares[File][Rank] == LastWhite && Taken != 1 ) {
3596 NoPro = 1;
3597 LastWhite = 0;
3599 if(Squares[File][Rank] > 0 ) LastBlack = 0; else LastWhite = 0;
3601 if(Dropped != 1 && NoPro != 1 && strcmp(Choice, "Micro") ) {
3602 if(Squares[File][Rank] > 0 && (Rank <= PromDotY || InitRank <= PromDotY) ) Promessage();
3603 if(Squares[File][Rank] < 0 && (Rank > BoardSizeY - PromDotY || InitRank > BoardSizeY - PromDotY) ) Promessage();
3604 if(LionPro == 1 ) Promessage();
3606 if(Eval == 1 ) { AddTally(); sprintf(Board.Caption, "%-90sEvaluation: %ld", Cap, BestTally[1]); }
3607 UpdateCaptions(); // [HGM] added
3608 NextTurn2();
3612 void NextTurn2 ()
3614 INT OrigSeeMove;
3615 LionVictim.Piece = 0;
3616 if(!strcmp(Computer, Turn) ) SeeMove = FirstSeeMove;
3617 if(Eval == 1 ) sprintf(Board.Caption, "%-90sEvaluation: %d", Cap, Int(BestTally[1]));
3618 MakeMove = 0; Dropped = 0; NoPro = 0; LionPro = 0; CompMove = 0; Evaluate = 0;
3619 SetKings();
3620 if(!strcmp(Turn, "Black") ) {
3621 MoveCount = MoveCount + 1;
3622 strcpy(Turn, "White");
3623 WhiteLion = 0;
3624 Board.MnuNextBlack.Enabled = True;
3625 Board.MnuNextWhite.Enabled = False;
3626 Board.MnuNextBlack.Checked = False;
3627 Board.MnuNextWhite.Checked = True;
3628 } else {
3629 strcpy(Turn, "Black");
3630 BlackLion = 0;
3631 Board.MnuNextBlack.Enabled = False;
3632 Board.MnuNextWhite.Enabled = True;
3633 Board.MnuNextBlack.Checked = True;
3634 Board.MnuNextWhite.Checked = False;
3636 if(Ligui != 1 ) Convert();
3637 TurnCount = TurnCount + 1; EndTurn = TurnCount;
3638 Captures[TurnCount].number = 0;
3639 InitFile = 0; InitRank = 0; Teach = 0; Taken = 0; Ligui = 0;
3640 sprintf(Board.LastMove.Caption, "%d. %s", MoveCount, ShortScore[TurnCount]); // Format$(MoveCount) + ". " + ShortScore[TurnCount]
3641 strcpy(Score[TurnCount].Caption, ShortScore[TurnCount]); strcpy(CMoveSTR, "");
3642 Board.Refresh();
3643 if((!strcmp(Turn, "White") && Squares[File][Rank] == 1 && BlackPrince == 0) || (!strcmp(Turn, "Black") && Squares[File][Rank] == -1 && WhitePrince == 0) ) TwoKings();
3644 if(Checked != 2 ) {
3645 OrigSeeMove = SeeMove; SeeMove = 1;
3646 LookCheck();
3647 SeeMove = OrigSeeMove;
3649 if(GameOver == 1 ) {
3650 sprintf(Score[TurnCount].Caption, "%d. %s mate", MoveCount, ShortScore[TurnCount]); // Format$(MoveCount) + ". " + ShortScore[TurnCount] + " mate"
3651 sprintf(Board.LastMove.Caption, "%d. %s mate", MoveCount, ShortScore[TurnCount]); // Format$(MoveCount) + ". " + ShortScore[TurnCount] + " mate"
3653 if(Checked == 2 ) TakeBack();
3654 if(PawnMate == 1 ) TakeBack();
3655 Checked = 0; CheckTest = 0; CheckLooked = 0; PawnMate = 0; Mate = 0;
3656 if((Backwards == 1) || (strcmp(Choice, "Chu") && strcmp(Choice, "Dai") && strcmp(Choice, "Tenjiku") && strcmp(Choice, "Maka") && strcmp(Choice, "DiaDai") && strcmp(Choice, "Tai")) ) BugFix();
3657 if(BlackEmperor == 1 && WhiteEmperor == 1 ) EmperorCheck();
3658 if(ShowLast == 1 && strcmp(Computer, Turn) ) FlashPiece();
3659 if(!strcmp(Computer, Turn) ) {
3660 FirstSeeMove = SeeMove;
3661 SeeMove = 1;
3662 CompMain();
3666 void NoCompTeach ()
3668 Board.MnuVer2.Enabled = True;
3669 Board.MnuVer1.Enabled = False;
3670 Board.MnuVer1.Checked = True;
3671 Board.MnuVer2.Checked = False;
3672 TeachVer = 1;
3675 void Notation ()
3676 { // Menu function. Notate = 0 (on) or 1 (off)
3677 if(Notate == 0 ) {
3678 Board.NotTop.Visible = False;
3679 Board.NotSide.Visible = False;
3680 } else {
3681 Board.NotTop.Visible = True;
3682 Board.NotSide.Visible = True;
3684 if(Board.MnuNotOn.Enabled == False ) Board.MnuNotOn.Enabled = True; else Board.MnuNotOn.Enabled = False;
3685 if(Board.MnuNotOff.Enabled == False ) Board.MnuNotOff.Enabled = True; else Board.MnuNotOff.Enabled = False;
3686 if(Board.MnuNotOn.Checked == False ) Board.MnuNotOn.Checked = True; else Board.MnuNotOn.Checked = False;
3687 if(Board.MnuNotOff.Checked == False ) Board.MnuNotOff.Checked = True; else Board.MnuNotOff.Checked = False;
3690 void NotSet ()
3692 INT K;
3693 Board.AutoRedraw = True;
3694 for(K = 1; K <= BoardSizeX; K++) {
3695 Board.CurrentX = (XStart - 3) + ((K - 1) * Pixels) + Int(Pixels / 3);
3696 Board.CurrentY = 0;
3697 if(strcmp(Choice, "Chu") && strcmp(Choice, "Heian") && strcmp(Choice, "Dai") && strcmp(Choice, "Tenjiku") ) {
3698 Board.CurrentX = Board.CurrentX - 1;
3699 Board.CurrentY = Board.CurrentY - 1;
3701 if(Reverse == 0 ) Board.Print(NumSTR(BoardSizeX - K + 1)); else Board.Print(NumSTR(K));
3702 Board.CurrentX = (XStart + 2) + (BoardSizeX * Pixels);
3703 Board.CurrentY = 11 + (K - 1) * Pixels + Int(Pixels / 3);
3704 if(strcmp(Choice, "Chu") && strcmp(Choice, "Heian") && strcmp(Choice, "Dai") && strcmp(Choice, "Tenjiku") ) {
3705 Board.CurrentX = Board.CurrentX - 1;
3706 Board.CurrentY = Board.CurrentY - 1;
3708 if(K <= BoardSizeY ) {
3709 if(Reverse == 0 ) Board.Print(CharSTR(96 + K)); else Board.Print(CharSTR(96 + (BoardSizeY - K + 1)));
3711 } // Next K;
3712 if(!strcmp(Choice, "Yari") ) {
3713 Board.CurrentX = (XStart + 1) + (BoardSizeX * Pixels);
3714 Board.CurrentY = 11 + 7 * Pixels + Int(Pixels / 3);
3715 if(Reverse == 0 ) Board.Print(CharSTR(104)); else Board.Print(CharSTR(98));
3716 Board.CurrentX = (XStart + 1) + (BoardSizeX * Pixels);
3717 Board.CurrentY = 11 + 8 * Pixels + Int(Pixels / 3);
3718 if(Reverse == 0 ) Board.Print(CharSTR(105)); else Board.Print(CharSTR(97));
3720 if(!strcmp(Choice, "Micro") ) {
3721 Board.CurrentY = 270;
3722 Board.CurrentX = 441;
3723 if(Reverse == 0 ) Board.Print(CharSTR(101)); else Board.Print(CharSTR(97));
3725 Board.AutoRedraw = False;
3728 void PawnMates ()
3730 INT SS, TT;
3731 if(CompLegal[AA].EndPiece != 0 ) {
3732 if((!strcmp(Pieces[abs(CompLegal[AA].EndPiece)].Name, "Pawn") || !strcmp(Pieces[abs(CompLegal[AA].EndPiece)].Name, "Sparrow Pawn") || !strcmp(Pieces[abs(CompLegal[AA].EndPiece)].Name, "Swallow") || !strcmp(Pieces[abs(CompLegal[AA].EndPiece)].Name, "Dolphin")) && CompLegal[AA].StartFile == 0 && strcmp(Choice, "Micro") && strcmp(Choice, "Yari") ) {
3733 if(!strcmp(Turn, "Black") && CompLegal[AA].EndRank > 1 ) {
3734 if(Squares[CompLegal[AA].EndFile][CompLegal[AA].EndRank - 1] == -1 ) {
3735 PawnMate = 1;
3736 for(SS = CompLegal[AA].EndRank - 2; SS <= CompLegal[AA].EndRank; SS++) {
3737 for(TT = CompLegal[AA].EndFile - 1; TT <= CompLegal[AA].EndFile + 1; TT++) {
3738 if(TT > 0 && TT <= BoardSizeX && SS > 0 && SS <= BoardSizeY && (TT != CompLegal[AA].EndFile || SS != CompLegal[AA].EndRank) ) {
3739 if(BanMap[TT][SS].BlackNum == 0 && Squares[TT][SS] >= 0 ) PawnMate = 0;
3741 } // Next TT;
3742 } // Next SS;
3743 if(PawnMate == 1 ) WhiteTally = WhiteTally + 999999;
3746 if(!strcmp(Turn, "White") && CompLegal[AA].EndRank < BoardSizeY ) {
3747 if(Squares[CompLegal[AA].EndFile][CompLegal[AA].EndRank + 1] == 1 ) {
3748 PawnMate = 1;
3749 for(SS = CompLegal[AA].EndRank; SS <= CompLegal[AA].EndRank + 2; SS++) {
3750 for(TT = CompLegal[AA].EndFile - 1; TT <= CompLegal[AA].EndFile + 1; TT++) {
3751 if(TT > 0 && TT <= BoardSizeX && SS > 0 && SS <= BoardSizeY && (SS != CompLegal[AA].EndRank || TT != CompLegal[AA].EndFile) ) {
3752 if(BanMap[TT][SS].WhiteNum == 0 && Squares[TT][SS] <= 0 ) PawnMate = 0;
3754 } // Next TT;
3755 } // Next SS;
3756 if(PawnMate == 1 ) BlackTally = BlackTally + 999999;
3759 PawnMate = 0;
3764 void PicDown ()
3765 { // Button1-Down on board piece. CCC = 1, I = piece number, ClickPiece = 1, NewButton = button
3766 STRING PieceName;
3767 INT K, L, Found=0; // was uninitialized?
3768 if(strcmp(Computer, Turn) && strcmp(Computer, "Both") && Level != 0 && GameOver != 1 ) {
3769 Notice = 0;
3770 Board.PieceID.ForeColor = 0xFF0000;
3771 if(Handicap == 1 || Reduce == 1 || Selection != 0 || MovePiece == 1 ) {
3772 RemovePiece();
3773 } else {
3774 if(LionPiece == -1 ) strcpy(Board.Caption, Cap);
3775 if(LionPiece == I || LionPiece == -1 ) {
3776 K = 1;
3777 do {
3778 L = 1;
3779 do {
3780 if(Grafix[L][K] == I ) {
3781 strcpy(PieceName, Pieces[abs(Squares[L][K])].Name);
3782 strcpy(Board.PieceID.Caption, PieceName);
3783 InitFile = L;
3784 InitRank = K;
3785 Found = 1;
3787 L = L + 1;
3788 } while( !(L > BoardSizeX || Found == 1) );
3789 K = K + 1;
3790 } while( !(K > BoardSizeY || Found == 1) );
3791 Found = 0;
3792 if((Squares[InitFile][InitRank] > 0 && !strcmp(Turn, "Black")) || (Squares[InitFile][InitRank] < 0 && !strcmp(Turn, "White")) ) {
3793 DRAG(Board.showpic[I], 1);
3794 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) Emperor(); else Validate();
3795 } else {
3796 Board.FillStyle = 1; Other = 1;
3797 Board.ForeColor = 0xC00000;
3798 Validate();
3799 Board.ForeColor = 0x0;
3800 Board.FillStyle = 0; Other = 0;
3802 } else {
3803 Board.PieceID.ForeColor = 0xFFL;
3804 sprintf(Board.PieceID.Caption, "You must move your %s !", LionNameSTR);
3805 Notice = 1;
3811 void PicDrop ()
3812 { // DragDrop handler for pieces. I = piece number
3813 INT K, L, Found;
3814 int Response; // write-only?
3815 if(ShowLast == 1 ) Board.Refresh();
3816 Found = 0;
3817 if(InitRank == 0 ) ClearLegal();
3818 if(InitRank != 0 && MovePiece != 1 ) {
3819 K = 1;
3820 do {
3821 L = 1;
3822 do {
3823 if(Grafix[L][K] == NewIndex ) {
3824 Found = 1; File = L; Rank = K;
3825 if(Legal[L][K] > 0 ) {
3826 if(LionPiece != I ) {
3827 Score[TurnCount].IDStart = Squares[InitFile][InitRank];
3828 Score[TurnCount].PosStart = (InitRank * (BoardSizeX + 1)) + InitFile;
3829 strcat(CMoveSTR, TrimSTR(Pieces[abs(Squares[InitFile][InitRank])].sname));
3830 sprintf(CMoveSTR + strlen(CMoveSTR), "%d%c", ((BoardSizeX - InitFile) + 1), (96 + InitRank));
3831 if((!strcmp(Computer, Turn) || !strcmp(Computer, "Both")) && LionVictim.Piece != 0 ) {
3832 sprintf(CMoveSTR + strlen(CMoveSTR), "x%d%c", ((BoardSizeX - LionVictim.File) + 1), (96 + LionVictim.Rank));
3835 if(!strcmp(Choice, "Chu") && !strcmp(Pieces[abs(Squares[L][K])].Name, "Lion") && strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Lion") ) {
3836 if(!strcmp(Turn, "Black") ) BlackLion = 1; else WhiteLion = 1;
3838 if(Legal[L][K] == 1 ) LionPiece = -1;
3839 Board.Frame.Visible = False;
3840 if(Legal[L][K] == 4 ) {
3841 Score[TurnCount].IDEnd = Squares[InitFile][InitRank];
3842 Score[TurnCount].PosEnd = Score[TurnCount].PosStart;
3843 strcat(CMoveSTR, "x!");
3844 } else {
3845 Score[TurnCount].IDEnd = Squares[File][Rank];
3846 Score[TurnCount].PosEnd = (Rank * (BoardSizeX + 1)) + File;
3847 Board.showpic[I].Visible = False;
3848 Grafix[L][K] = I;
3849 if(InitFile != File || InitRank != Rank ) Grafix[InitFile][InitRank] = -1;
3851 if(Legal[L][K] != 4 ) {
3852 if((InitFile != File || InitRank != Rank) ) strcat(CMoveSTR, "x"); else strcat(CMoveSTR, "-");
3854 sprintf(CMoveSTR + strlen(CMoveSTR), "%d%c", ((BoardSizeX - File) + 1), (Rank + 96));
3855 Captures[TurnCount].number = Captures[TurnCount].number + 1;
3856 Captures[TurnCount].Positions[Captures[TurnCount].number] = (Rank * (BoardSizeX + 1)) + File;
3858 Captures[TurnCount].PieceNum[Captures[TurnCount].number] = Squares[File][Rank];
3859 if(LionVictim.Piece != 0 ) {
3860 Captures[TurnCount].number = Captures[TurnCount].number + 1;
3861 Captures[TurnCount].Positions[Captures[TurnCount].number] = (LionVictim.Rank * (BoardSizeX + 1)) + LionVictim.File;
3862 Captures[TurnCount].PieceNum[Captures[TurnCount].number] = Squares[LionVictim.File][LionVictim.Rank];
3864 Board.showpic[NewIndex].Visible = False;
3865 MOVE(1, Board.showpic[NewIndex], 0, 0);
3866 if(abs(Squares[L][K]) == 1 || !strcmp(Pieces[abs(Squares[L][K])].Name, "Emperor") || !strcmp(Pieces[abs(Squares[L][K])].Name, "Crown Prince") || !strcmp(Pieces[abs(Squares[L][K])].Name, "Prince") ) CheckMate();
3867 Taken = 1;
3868 if(Drop == 1 ) ChangeSides();
3869 if(Legal[File][Rank] == 3 ) {
3870 Score[TurnCount].IDEnd = 0;
3871 Grafix[File][Rank] = -1;
3872 MOVE(1, Board.showpic[I], 0, 0);
3873 Squares[InitFile][InitRank] = 0;
3874 Squares[File][Rank] = 0;
3875 NoPro = 1;
3876 } else {
3877 if(Legal[File][Rank] != 4 ) {
3878 Squares[File][Rank] = Squares[InitFile][InitRank];
3879 if(Squares[File][Rank] == 1 ) { BlackKingX = File; BlackKingY = Rank; }
3880 if(Squares[File][Rank] == -1 ) { WhiteKingX = File; WhiteKingY = Rank; }
3881 if(!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Emperor") && Squares[File][Rank] > 0 ) { BlackEmpX = File; BlackEmpY = Rank; }
3882 if(!strcmp(Pieces[abs(Squares[File][Rank])].Name, "Emperor") && Squares[File][Rank] < 0 ) { WhiteEmpX = File; WhiteEmpY = Rank; }
3883 if(Reverse == 0 ) {
3884 MOVE(1, Board.showpic[I], XStart + ((File - 1) * Pixels), 11 + ((Rank - 1) * Pixels));
3885 } else {
3886 MOVE(1, Board.showpic[I], XStart + ((BoardSizeX - File) * Pixels), 11 + ((BoardSizeY - Rank) * Pixels));
3888 Board.showpic[I].Visible = True;
3889 if(InitFile != File || InitRank != Rank ) Squares[InitFile][InitRank] = 0;
3890 if(LionVictim.Piece != 0 ) {
3891 Squares[LionVictim.File][LionVictim.Rank] = 0;
3892 Board.showpic[Grafix[LionVictim.File][LionVictim.Rank]].Visible = False;
3893 MOVE(1, Board.showpic[Grafix[LionVictim.File][LionVictim.Rank]], 0, 0);
3894 Grafix[LionVictim.File][LionVictim.Rank] = -1;
3898 if(Legal[L][K] == 4 ) { Squares[L][K] = 0; Grafix[L][K] = -1; File = InitFile; Rank = InitRank; }
3899 if(Demon == 1 ) Flame();
3900 if(Legal[L][K] == 3 ) strcat(CMoveSTR, "*");
3901 if(Legal[L][K] == 6 ) Teach = 3;
3902 if(Legal[L][K] == 2 ) Teach = 2; else Teach = 1;
3903 if(Mate != 1 ) {
3904 if(Legal[L][K] == 2 || Legal[L][K] == 6 ) {
3905 DoubleMove();
3906 } else {
3907 LastPieceX = File; LastPieceY = Rank;
3908 if(CompMove != 1 ) NextTurn();
3913 L = L + 1;
3914 } while( !(L > BoardSizeX || Found == 1) );
3915 K = K + 1;
3916 } while( !(K > BoardSizeY || Found == 1) );
3917 Found = 0;
3918 ClearLegal();
3919 if(Mate == 1 ) { GameOver = 1; Response = MsgBox(" Checkmate! ", 0, (sprintf(StringTmp, "%s Wins!", Turn), StringTmp)); NextTurn(); }
3920 } else {
3921 if(MovePiece == 1 ) MovePicDrop();
3925 void PrintScore ()
3926 { // Menu function.
3927 #if 0
3928 Printer.Print((sprintf(StringTmp, "%s Shogi - Game Record\n", GameName), StringTmp));
3929 Printer.Print ("____________________________________\n");
3930 Printer.Print("\n");
3932 PrintMax = 4;
3933 PrintInc = 20;
3934 if(!strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Tai") ) {
3935 PrintMax = 3;
3936 PrintInc = 27;
3938 if(!strcmp(Choice, "Tenjiku") ) {
3939 PrintMax = 2;
3940 PrintInc = 40;
3942 K = 0; J = 0;
3943 for(W = 1; W <= TurnCount; W += 2) {
3944 K = K + 1; J = J + 1;
3945 strcpy(FirstScore, Score[W].Caption);
3946 strcpy(SecondScore, Score[W + 1].Caption);
3947 if(strstr(FirstScore, " ") ) TenjikuScore1();
3948 if(strstr(SecondScore, " ") ) TenjikuScore2();
3949 if(HandGame == 1 && W == 1 ) {
3950 Printer.Print("1. - %s", SecondScore, Tab(PrintInc)); // TODO tab to desired column
3951 } else {
3952 Printer.Print("%d. %s %s", K, FirstScore, SecondScore, Tab(J * PrintInc));
3954 if(J == PrintMax ) { Printer.Print("\n"); J = 0; }
3955 } // Next W;
3956 strcpy(Board.Caption, "Printing..."); Notice = 1;
3957 Printer.EndDoc;
3958 #endif
3961 void Promessage ()
3963 STRING KSTR, LSTR, MessageSTR;
3964 int Response;
3965 ClearLegal();
3966 ForceProm = 0; Taken = 0;
3967 if(!strcmp(Choice, "Micro") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai") ) ForceProm = 1;
3968 if(Pieces[abs(Squares[File][Rank])].special == '1' ) {
3969 if(Squares[File][Rank] > 0 && Rank == 1 ) ForceProm = 1;
3970 if(Squares[File][Rank] < 0 && Rank == BoardSizeY ) ForceProm = 1;
3972 if(Pieces[abs(Squares[File][Rank])].special == '2' ) {
3973 if(Squares[File][Rank] > 0 && Rank < 3 ) ForceProm = 1;
3974 if(Squares[File][Rank] < 0 && Rank > BoardSizeY - 2 ) ForceProm = 1;
3976 if(Prom == 0 && ForceProm != 1 ) {
3977 if(Pieces[abs(Squares[File][Rank])].Promotes > 0 ) {
3978 if(AutoPromote != 1 ) {
3979 strcpy(LSTR, Pieces[Pieces[abs(Squares[File][Rank])].Promotes].Name);
3980 strcpy(KSTR, Pieces[abs(Squares[File][Rank])].Name);
3981 sprintf(MessageSTR, "Promote to %s ?", LSTR);
3982 Response = MsgBox(MessageSTR, 36, KSTR);
3983 if(Response == 6 ) {
3984 Promote();
3985 } else {
3986 strcat(CMoveSTR, "=");
3987 if(!strcmp(Turn, "White") && InitRank < 9 ) LastWhite = Squares[File][Rank];
3988 if(!strcmp(Turn, "Black") && InitRank > 4 ) LastBlack = Squares[File][Rank];
3990 } else {
3991 Promote();
3995 if(Prom == 1 || ForceProm == 1 ) {
3996 if(Pieces[abs(Squares[File][Rank])].Promotes > 0 ) {
3997 Board.PieceID.ForeColor = 0x8000L;
3998 strcpy(KSTR, Pieces[abs(Squares[File][Rank])].Name);
3999 sprintf(Board.PieceID.Caption, "%s promotes", KSTR);
4000 Notice = 1;
4001 Promote();
4006 void Promote ()
4008 if(Reverse == 0 ) PromGraf = (TotGraph / 2) - 1; else PromGraf = -1;
4009 if(Squares[File][Rank] < 0 && Pieces[abs(Squares[File][Rank])].Promotes != 0 ) {
4010 // if(!strcmp(Choice, "Tai") ) {
4011 // Board.showpic[I].Picture = TaiPieces.Pix[PromGraf + Pieces[abs(Squares[File][Rank])].PrGraphic].Picture;
4012 // } else {
4013 Board.showpic[I].Picture = Board.Pix[PromGraf + Pieces[abs(Squares[File][Rank])].PrGraphic].Picture;
4014 // }
4015 strcpy(PromPieceSTR, Pieces[abs(Squares[File][Rank])].Name);
4016 if(!strcmp(PromPieceSTR, "Drunk Elephant") ) WhitePrince = WhitePrince + 1;
4017 if(!strcmp(PromPieceSTR, "King") ) {
4018 WhiteEmperor = 1; WhiteEmpX = File; WhiteEmpY = Rank;
4020 Squares[File][Rank] = 0 - Pieces[abs(Squares[File][Rank])].Promotes;
4021 Score[TurnCount].IDEnd = Squares[File][Rank];
4022 Board.showpic[I].Visible = True;
4023 strcat(CMoveSTR, "+");
4024 if(AutoPromote == 1 && ForceProm != 1 ) AutoMessage();
4026 if(Reverse == 1 ) PromGraf = (TotGraph / 2) - 1; else PromGraf = -1;
4027 if(Squares[File][Rank] > 0 && Pieces[abs(Squares[File][Rank])].Promotes != 0 ) {
4028 // if(!strcmp(Choice, "Tai") ) {
4029 // Board.showpic[I].Picture = TaiPieces.Pix[PromGraf + Pieces[Squares[File][Rank]].PrGraphic].Picture;
4030 // } else {
4031 Board.showpic[I].Picture = Board.Pix[PromGraf + Pieces[Squares[File][Rank]].PrGraphic].Picture;
4032 // }
4033 strcpy(PromPieceSTR, Pieces[abs(Squares[File][Rank])].Name);
4034 if(!strcmp(PromPieceSTR, "Drunk Elephant") ) BlackPrince = BlackPrince + 1;
4035 if(!strcmp(PromPieceSTR, "King") ) {
4036 BlackEmperor = 1; BlackEmpX = File; BlackEmpY = Rank;
4038 Squares[File][Rank] = Pieces[abs(Squares[File][Rank])].Promotes;
4039 Score[TurnCount].IDEnd = Squares[File][Rank];
4040 Board.showpic[I].Visible = True;
4041 strcat(CMoveSTR, "+");
4042 if(AutoPromote == 1 && ForceProm != 1 ) AutoMessage();
4046 void RangeJump ()
4048 M = 64; Range = 1;
4049 SingleStep();
4052 void ReduceHand ()
4054 INT Z, OldPiece;
4055 if(Replaying == 1 ) {
4056 CaptPiece = Score[TurnCount].IDEnd;
4057 OldPiece = Squares[InitFile][InitRank];
4058 Squares[InitFile][InitRank] = 0 - CaptPiece;
4059 } else {
4060 if(Pieces[abs(Squares[InitFile][InitRank])].Promotes == 0 && Pieces[abs(Squares[InitFile][InitRank])].PrGraphic > 0 ) {
4061 CaptPiece = Pieces[abs(Squares[InitFile][InitRank])].PrGraphic;
4062 if(Squares[InitFile][InitRank] > 0 ) CaptPiece = 0 - CaptPiece;
4063 } else {
4064 CaptPiece = 0 - Squares[InitFile][InitRank];
4067 for(Z = 1; Z <= Capture; Z++) {
4068 if((Squares[InitFile][InitRank] < 0 && Reverse == 0) || (Squares[InitFile][InitRank] > 0 && Reverse == 1) ) {
4069 if(CapRef[Z] == CaptPiece ) {
4070 InHand[Z] = InHand[Z] - 1;
4071 if(InHand[Z] < 2 ) strcpy(Board.Held[Z].Caption, ""); else sprintf(Board.Held[Z].Caption, "%d", InHand[Z]);
4072 if(InHand[Z] < 1 ) Board.HandPic[Z].Visible = False;
4073 if(!strcmp(Choice, "Micro") ) {
4074 I = Z; MicroDrop();
4077 } else {
4078 if(CapRef[Z] == 0 - CaptPiece ) {
4079 InHand[Capture + Z] = InHand[Capture + Z] - 1;
4080 if(InHand[Capture + Z] < 2 ) strcpy(Board.Held[Capture + Z].Caption, ""); else sprintf(Board.Held[Capture + Z].Caption, "%d", InHand[Capture + Z]);
4081 if(InHand[Capture + Z] < 1 ) Board.HandPic[Capture + Z].Visible = False;
4082 if(!strcmp(Choice, "Micro") ) {
4083 I = Capture + Z; MicroDrop();
4087 } // Next Z;
4088 if(Replaying == 1 ) Squares[InitFile][InitRank] = OldPiece;
4091 void ReduceHand2 ()
4093 INT Z, OldPiece;
4094 if(Replaying == 1 ) {
4095 CaptPiece = Score[TurnCount].IDEnd;
4096 OldPiece = Squares[InitFile][InitRank];
4097 Squares[InitFile][InitRank] = 0 - CaptPiece;
4098 } else {
4099 if(Pieces[abs(Squares[InitFile][InitRank])].Promotes == 0 && Pieces[abs(Squares[InitFile][InitRank])].PrGraphic > 0 ) {
4100 CaptPiece = Pieces[abs(Squares[InitFile][InitRank])].PrGraphic;
4101 if(Squares[InitFile][InitRank] > 0 ) CaptPiece = 0 - CaptPiece;
4102 } else {
4103 CaptPiece = 0 - Squares[InitFile][InitRank];
4106 for(Z = 1; Z <= Capture; Z++) {
4107 if((Squares[InitFile][InitRank] < 0 && Reverse == 0) || (Squares[InitFile][InitRank] > 0 && Reverse == 1) ) {
4108 if(CapRef[Z] == CaptPiece ) {
4109 InHand[Z] = InHand[Z] - 1;
4110 if(!strcmp(Choice, "Micro") ) {
4111 I = Z;
4112 if((I < 5) || (I > 8 && I < 13) ) InHand[I + 4] = InHand[I + 4] - 1; else InHand[I - 4] = InHand[I - 4] - 1;
4115 } else {
4116 if(CapRef[Z] == 0 - CaptPiece ) {
4117 InHand[Capture + Z] = InHand[Capture + Z] - 1;
4118 if(!strcmp(Choice, "Micro") ) {
4119 I = Capture + Z;
4120 if((I < 5) || (I > 8 && I < 13) ) InHand[I + 4] = InHand[I + 4] - 1; else InHand[I - 4] = InHand[I - 4] - 1;
4124 } // Next Z;
4125 if(Replaying == 1 ) Squares[InitFile][InitRank] = OldPiece;
4128 void RemovePiece ()
4130 INT K, L, Found=0; // FIXME: was uninitialized?
4131 STRING PieceName, VictimSTR;
4132 if(Selection != 0 || MovePiece == 1 ) {
4133 SquareReplace();
4134 } else {
4135 K = 1;
4136 do {
4137 L = 1;
4138 do {
4139 if(Grafix[L][K] == I ) {
4140 strcpy(PieceName, Pieces[abs(Squares[L][K])].Name);
4141 strcpy(Board.PieceID.Caption, PieceName);
4142 File = L;
4143 Rank = K;
4145 L = L + 1;
4146 } while( !(L > BoardSizeX || Found == 1) );
4147 K = K + 1;
4148 } while( !(K > BoardSizeY || Found == 1) );
4149 Found = 0;
4150 if(Handicap == 1 ) {
4151 if(Squares[File][Rank] > 0 ) {
4152 Board.PieceID.ForeColor = 0xFFL;
4153 strcpy(Board.PieceID.Caption, "Select a White piece");
4154 Notice = 1;
4156 if(Squares[File][Rank] < 0 ) {
4157 strcpy(VictimSTR, Pieces[abs(Squares[File][Rank])].Name);
4158 if(abs(Squares[File][Rank]) == 1 || !strcmp(VictimSTR, "Emperor") || !strcmp(VictimSTR, "Prince") || !strcmp(VictimSTR, "Crown Prince") ) {
4159 Board.PieceID.ForeColor = 0xFFL;
4160 sprintf(Board.PieceID.Caption, "The White %scan not be removed", VictimSTR);
4161 Notice = 1;
4162 } else {
4163 sprintf(Board.PieceID.Caption, "%s removed", Pieces[abs(Squares[File][Rank])].Name);
4164 Notice = 1;
4165 Squares[File][Rank] = 0;
4166 Board.showpic[Grafix[File][Rank]].Visible = False;
4167 MOVE(1, Board.showpic[Grafix[File][Rank]], 0, 0);
4168 Grafix[File][Rank] = -1;
4169 strcpy(Turn, "White");
4170 strcpy(Board.NextMove.Caption, "White to Move");
4171 MoveCount = 1; HandGame = 1;
4174 } else {
4175 strcpy(Board.PieceID.Caption, "");
4176 strcpy(VictimSTR, Pieces[abs(Squares[File][Rank])].Name);
4177 if(Squares[File][Rank] > 0 && (!strcmp(VictimSTR, "Prince") || !strcmp(VictimSTR, "Crown Prince")) ) BlackPrince = BlackPrince - 1;
4178 if(Squares[File][Rank] < 0 && (!strcmp(VictimSTR, "Prince") || !strcmp(VictimSTR, "Crown Prince")) ) WhitePrince = WhitePrince - 1;
4179 Squares[File][Rank] = 0;
4180 Board.showpic[Grafix[File][Rank]].Visible = False;
4181 MOVE(1, Board.showpic[Grafix[File][Rank]], 0, 0);
4182 Grafix[File][Rank] = -1;
4183 MoveCount = 0; TurnCount = 0;
4184 if(!strcmp(Turn, "White") ) MoveCount = 1;
4185 strcpy(Board.LastMove.Caption, "");
4190 void ReorderMoves ()
4192 INT XX, YY;
4193 if(Level > 1 ) {
4194 for(XX = 1; XX <= TestDepth; XX++) {
4195 if(BestTally[Level + 1] > BestTally[XX] ) {
4196 for(YY = TestDepth - 1; YY >= XX; YY--) {
4197 BestTally[YY + 1] = BestTally[YY];
4198 MoveList[YY + 1].StartPiece = MoveList[YY].StartPiece;
4199 MoveList[YY + 1].EndPiece = MoveList[YY].EndPiece;
4200 MoveList[YY + 1].StartFile = MoveList[YY].StartFile;
4201 MoveList[YY + 1].EndFile = MoveList[YY].EndFile;
4202 MoveList[YY + 1].StartRank = MoveList[YY].StartRank;
4203 MoveList[YY + 1].EndRank = MoveList[YY].EndRank;
4204 OldKingTally[YY + 1] = OldKingTally[YY];
4205 if(!strcmp(Choice, "Dai") || !strcmp(Choice, "Chu") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Tai") ) {
4206 ECapture[YY + 1].Piece = ECapture[YY].Piece;
4207 ECapture[YY + 1].File = ECapture[YY].File;
4208 ECapture[YY + 1].Rank = ECapture[YY].Rank;
4210 } // Next YY;
4211 BestTally[XX] = BestTally[Level + 1];
4212 MoveList[XX].StartPiece = CompLegal[BestMove].StartPiece;
4213 MoveList[XX].EndPiece = CompLegal[BestMove].EndPiece;
4214 MoveList[XX].StartFile = CompLegal[BestMove].StartFile;
4215 MoveList[XX].EndFile = CompLegal[BestMove].EndFile;
4216 MoveList[XX].StartRank = CompLegal[BestMove].StartRank;
4217 MoveList[XX].EndRank = CompLegal[BestMove].EndRank;
4218 OldKingTally[XX] = KingTally[BestMove];
4219 if(!strcmp(Choice, "Dai") || !strcmp(Choice, "Chu") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tenjiku") || !strcmp(Choice, "Tai") ) {
4220 ECapture[XX].Piece = ExtraCapture[BestMove].Piece;
4221 ECapture[XX].File = ExtraCapture[BestMove].File;
4222 ECapture[XX].Rank = ExtraCapture[BestMove].Rank;
4224 return;
4226 DoEvents();
4227 } // Next XX;
4231 void Replay ()
4232 { // Menu function.
4233 INT V, Location;
4234 if((LegalMoves == 0 || Checked == 2) && LionPiece != I && XA == 0 ) {
4235 Notice = 0;
4236 strcpy(Board.PieceID.Caption, "");
4237 if(Forwards != 1 ) strcpy(Board.Caption, Cap);
4238 BugFix();
4239 if(TurnCount >= EndTurn ) {
4240 Board.PieceID.ForeColor = 0xFFL;
4241 strcpy(Board.PieceID.Caption, "No moves to replay!");
4242 Notice = 1;
4243 } else {
4244 Replaying = 1;
4245 for(V = 1; V <= Captures[TurnCount].number; V++) {
4246 Location = Captures[TurnCount].Positions[V];
4247 InitRank = Int(Location / (BoardSizeX + 1));
4248 InitFile = Location - (InitRank * (BoardSizeX + 1));
4249 NewGraf = Grafix[InitFile][InitRank];
4250 Grafix[InitFile][InitRank] = -1;
4251 Board.showpic[NewGraf].Visible = False;
4252 MOVE(1, Board.showpic[NewGraf], 0, 0);
4253 Squares[InitFile][InitRank] = 0;
4254 } // Next V;
4255 if(Drop == 1 && Captures[TurnCount].number > 0 ) {
4256 CaptPiece = Captures[TurnCount].PieceNum[1];
4257 if(Pieces[abs(CaptPiece)].Promotes == 0 && Pieces[abs(CaptPiece)].PrGraphic > 0 ) {
4258 CaptPiece = Pieces[abs(CaptPiece)].PrGraphic;
4259 if(Captures[TurnCount].PieceNum[1] > 0 ) CaptPiece = 0 - CaptPiece;
4260 } else {
4261 CaptPiece = 0 - CaptPiece;
4263 AddHand();
4265 Location = Score[TurnCount].PosStart;
4266 if(Location > 0 ) {
4267 Rank = Int(Location / (BoardSizeX + 1));
4268 File = Location - (Rank * (BoardSizeX + 1));
4269 Squares[File][Rank] = 0;
4270 NewGraf = Grafix[File][Rank];
4271 Grafix[File][Rank] = -1;
4272 Board.showpic[NewGraf].Visible = False;
4273 MOVE(1, Board.showpic[NewGraf], 0, 0);
4275 Location = Score[TurnCount].PosEnd;
4276 if(Location > 0 ) {
4277 InitRank = Int(Location / (BoardSizeX + 1));
4278 InitFile = Location - (InitRank * (BoardSizeX + 1));
4279 Squares[InitFile][InitRank] = Score[TurnCount].IDStart;
4280 if(Sgn(Score[TurnCount].IDStart) == Sgn(Score[TurnCount].IDEnd) && Score[TurnCount].IDEnd != Score[TurnCount].IDStart ) Squares[InitFile][InitRank] = Score[TurnCount].IDEnd;
4281 if(Squares[InitFile][InitRank] < 0 ) {
4282 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) { WhiteEmpX = InitFile; WhiteEmpY = InitRank; }
4283 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "King") ) { WhiteKingX = InitFile; WhiteKingY = InitRank; }
4285 if(Squares[InitFile][InitRank] > 0 ) {
4286 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) { BlackEmpX = InitFile; BlackEmpY = InitRank; }
4287 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "King") ) { BlackKingX = InitFile; BlackKingY = InitRank; }
4289 if(Score[TurnCount].IDEnd != 0 ) {
4290 NewGraf = 0;
4291 while( Board.showpic[NewGraf].Visible == True ) {
4292 NewGraf = NewGraf + 1;
4294 SetGrafix();
4297 if(Drop == 1 && Score[TurnCount].PosStart == 0 ) ReduceHand();
4298 if(!strcmp(Turn, "Black") ) {
4299 strcpy(Turn, "White");
4300 strcpy(Board.NextMove.Caption, "White to Move");
4301 MoveCount = MoveCount + 1;
4302 } else {
4303 strcpy(Turn, "Black");
4304 strcpy(Board.NextMove.Caption, "Black to Move");
4306 TurnCount = TurnCount + 1;
4307 Board.MnuHandicap.Enabled = False;
4308 EnableNamedMenuItem("Setup.Handicap", False); // [HGM] added
4309 if(Asc(Score[TurnCount].Caption) > 47 && Asc(Score[TurnCount].Caption) < 58 ) {
4310 strcpy(Board.LastMove.Caption, Score[TurnCount].Caption);
4311 } else {
4312 sprintf(Board.LastMove.Caption, "%d. %s", MoveCount, Score[TurnCount].Caption); // Format$(MoveCount) + ". " + Score[TurnCount].Caption;
4314 Backwards = 1;
4315 SetKings();
4316 Location = Score[TurnCount - 1].PosEnd;
4317 if(Location > 0 ) {
4318 Rank = Int(Location / (BoardSizeX + 1));
4319 File = Location - (Rank * (BoardSizeX + 1));
4321 LastPieceX = File; LastPieceY = Rank;
4322 if(!strcmp(Computer, "Black") || !strcmp(Computer, "White") ) {
4323 sprintf(Board.Caption, "Move Replayed (%d of %d ) ; Press [ESC] to continue play.", TurnCount, EndTurn);
4324 } else {
4325 sprintf(Board.Caption, "Move Replayed (%d of %d )", TurnCount, EndTurn);
4328 Replaying = 0;
4332 void Replay2 ()
4334 INT V, Location;
4335 if((LegalMoves == 0 || Checked == 2) && LionPiece != I && XA == 0 ) {
4336 if(TurnCount < EndTurn ) {
4337 Replaying = 1;
4338 for(V = 1; V <= Captures[TurnCount].number; V++) {
4339 Location = Captures[TurnCount].Positions[V];
4340 InitRank = Int(Location / (BoardSizeX + 1));
4341 InitFile = Location - (InitRank * (BoardSizeX + 1));
4342 Squares[InitFile][InitRank] = 0;
4343 } // Next V;
4344 if(Drop == 1 && Captures[TurnCount].number > 0 ) {
4345 CaptPiece = Captures[TurnCount].PieceNum[1];
4346 if(Pieces[abs(CaptPiece)].Promotes == 0 && Pieces[abs(CaptPiece)].PrGraphic > 0 ) {
4347 CaptPiece = Pieces[abs(CaptPiece)].PrGraphic;
4348 if(Captures[TurnCount].PieceNum[1] > 0 ) CaptPiece = 0 - CaptPiece;
4349 } else {
4350 CaptPiece = 0 - CaptPiece;
4352 AddHand3();
4354 Location = Score[TurnCount].PosStart;
4355 if(Location > 0 ) {
4356 Rank = Int(Location / (BoardSizeX + 1));
4357 File = Location - (Rank * (BoardSizeX + 1));
4358 Squares[File][Rank] = 0;
4360 Location = Score[TurnCount].PosEnd;
4361 if(Location > 0 ) {
4362 InitRank = Int(Location / (BoardSizeX + 1));
4363 InitFile = Location - (InitRank * (BoardSizeX + 1));
4364 Squares[InitFile][InitRank] = Score[TurnCount].IDStart;
4365 if(Sgn(Score[TurnCount].IDStart) == Sgn(Score[TurnCount].IDEnd) && Score[TurnCount].IDEnd != Score[TurnCount].IDStart ) Squares[InitFile][InitRank] = Score[TurnCount].IDEnd;
4366 if(Squares[InitFile][InitRank] < 0 ) {
4367 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) { WhiteEmpX = InitFile; WhiteEmpY = InitRank; }
4368 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "King") ) { WhiteKingX = InitFile; WhiteKingY = InitRank; }
4370 if(Squares[InitFile][InitRank] > 0 ) {
4371 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) { BlackEmpX = InitFile; BlackEmpY = InitRank; }
4372 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "King") ) { BlackKingX = InitFile; BlackKingY = InitRank; }
4375 if(Drop == 1 && Score[TurnCount].PosStart == 0 ) ReduceHand2();
4376 if(!strcmp(Turn, "Black") ) {
4377 strcpy(Turn, "White");
4378 strcpy(Board.NextMove.Caption, "White to Move");
4379 MoveCount = MoveCount + 1;
4380 } else {
4381 strcpy(Turn, "Black");
4382 strcpy(Board.NextMove.Caption, "Black to Move");
4384 TurnCount = TurnCount + 1;
4385 Board.MnuHandicap.Enabled = False;
4386 EnableNamedMenuItem("Setup.Handicap", False); // [HGM] added
4387 if(Asc(Score[TurnCount].Caption) > 47 && Asc(Score[TurnCount].Caption) < 58 ) {
4388 strcpy(Board.LastMove.Caption, Score[TurnCount].Caption);
4389 } else {
4390 sprintf(Board.LastMove.Caption, "%d. %s", MoveCount, Score[TurnCount].Caption); // Format$(MoveCount) + ". " + Score[TurnCount].Caption;
4392 Board.MnuHandicap.Enabled = False;
4393 EnableNamedMenuItem("Setup.Handicap", False); // [HGM] added
4394 Backwards = 1;
4395 if(Location > 0 ) {
4396 Rank = Int(Location / (BoardSizeX + 1));
4397 File = Location - (Rank * (BoardSizeX + 1));
4399 LastPieceX = File; LastPieceY = Rank;
4401 Replaying = 0;
4405 void ReplayAll ()
4406 { // Menu function.
4407 if(LegalMoves == 0 ) {
4408 while( TurnCount < EndTurn) {
4409 Replay2();
4411 strcpy(Board.Caption, Cap);
4412 RestoreGrafix();
4413 SetKings();
4417 void ResetBoard ()
4419 INT W;
4420 Board.Hide();
4421 if(!strcmp(Choice, "Wa") ) {
4422 for(W = 1; W <= Capture * 2; W++) {
4423 strcpy(Board.Held[W].Caption, "");
4424 Board.HandPic[W].Visible = False;
4425 } // Next W;
4427 NewGame = 1;
4428 SetPieces();
4431 void ResetHand ()
4433 INT X;
4434 for(X = 1; X <= Capture; X++) {
4435 if(InHand[X] < 1 ) Board.HandPic[X].Visible = False;
4436 if(InHand[X] < 2 ) strcpy(Board.Held[X].Caption, "");
4437 if(InHand[Capture + X] < 1 ) Board.HandPic[Capture + X].Visible = False;
4438 if(InHand[Capture + X] < 2 ) strcpy(Board.Held[Capture + X].Caption, "");
4439 } // Next X;
4442 void ResetLegal ()
4444 INT MM, NN;
4445 for(MM = 1; MM <= BoardSizeY; MM++) {
4446 for(NN = 1; NN <= BoardSizeX; NN++) {
4447 Legal[NN][MM] = 0;
4448 } // Next NN;
4449 } // Next MM;
4452 void RestoreGrafix ()
4454 INT ABC, DEF;
4455 Board.Hide();
4456 Count = 0; M = 0;
4457 for(J = 1; J <= BoardSizeY; J++) {
4458 for(I = 1; I <= BoardSizeX; I++) {
4459 Grafix[I][J] = -1;
4460 if(Squares[I][J] != 0 ) {
4461 Graphnum = Pieces[abs(Squares[I][J])].Graphic;
4462 if((Squares[I][J] < 0 && Reverse == 0) || (Squares[I][J] > 0 && Reverse == 1) ) Graphnum = Graphnum + (TotGraph / 2);
4463 /* if(!strcmp(Choice, "Tai") ) Board.showpic[COUNT] = TaiPieces.Pix[Graphnum - 1]; else */ Board.showpic[COUNT] = Board.Pix[Graphnum - 1];
4464 if(Reverse == 0 ) {
4465 MOVE(0, Board.showpic[COUNT], XStart + ((I - 1) * Pixels), 11 + ((J - 1) * Pixels));
4466 } else {
4467 MOVE(0, Board.showpic[COUNT], XStart + ((BoardSizeX - I) * Pixels), 11 + ((BoardSizeY - J) * Pixels));
4470 Board.showpic[COUNT].Visible = True;
4471 Grafix[I][J] = Count;
4472 Count = Count + 1;
4474 } // Next I;
4475 } // Next J;
4476 if(Drop == 1 || !strcmp(Choice, "Wa") ) {
4477 for(I = 1; I <= Capture * 2; I++) {
4478 Graphnum = Pieces[abs(CapRef[I])].Graphic;
4479 if(I > Capture ) Graphnum = Graphnum + (TotGraph / 2);
4480 Board.HandPic[I].Picture = Board.Pix[Graphnum - 1].Picture; // [HGM] only picture, not coords!
4481 Board.HandPic[I].Visible = False;
4482 strcpy(Board.Held[I].Caption, "");
4483 if(InHand[I] > 0 ) Board.HandPic[I].Visible = True;
4484 if(InHand[I] > 1 ) sprintf(Board.Held[I].Caption, "%d", InHand[I]);
4485 } // Next I;
4487 BugFix();
4488 Board.Show();
4489 if(!strcmp(Choice, "Tai") || !strcmp(Choice, "Maka") ) {
4490 for(ABC = 1; ABC <= BoardSizeY; ABC++) {
4491 for(DEF = 1; DEF <= BoardSizeX; DEF++) {
4492 if(Squares[DEF][ABC] > 0 ) {
4493 if(!strcmp(Pieces[abs(Squares[DEF][ABC])].Name, "Emperor") ) { BlackEmpX = DEF; BlackEmpY = ABC; BlackEmperor = 1; }
4495 if(Squares[DEF][ABC] < 0 ) {
4496 if(!strcmp(Pieces[abs(Squares[DEF][ABC])].Name, "Emperor") ) { WhiteEmpX = DEF; WhiteEmpY = ABC; WhiteEmperor = 1; }
4498 } // Next DEF;
4499 } // Next ABC;
4503 void RestoreMap ()
4505 INT JJ, KK, LL;
4506 for(JJ = 1; JJ <= BoardSizeY; JJ++) {
4507 for(KK = 1; KK <= BoardSizeX; KK++) {
4508 BanMap[KK][JJ].WhiteNum = BackMap[KK][JJ].WhiteNum;
4509 BanMap[KK][JJ].BlackNum = BackMap[KK][JJ].BlackNum;
4510 Attacker[KK][JJ] = OldAttack[KK][JJ];
4511 for(LL = 1; LL <= OldAttack[KK][JJ]; LL++) {
4512 BanMap[KK][JJ].Info[LL].File = BackMap[KK][JJ].Info[LL].File;
4513 BanMap[KK][JJ].Info[LL].Rank = BackMap[KK][JJ].Info[LL].Rank;
4514 BanMap[KK][JJ].Info[LL].Piece = BackMap[KK][JJ].Info[LL].Piece;
4515 } // Next LL;
4516 } // Next KK;
4517 DoEvents();
4518 } // Next JJ;
4521 void Rotate ()
4522 { // Menu function.
4523 if(LegalMoves == 0 ) {
4524 Board.Picture = LoadPicture((sprintf(StringTmp, "%s/boards/%s", Direct, Boardbmp), StringTmp));
4525 if(Reverse == 1 ) {
4526 Reverse = 0;
4527 Board.White.Picture = LoadPicture((sprintf(StringTmp, "%s/%s", Direct, "WhiteDn.bmp"), StringTmp));
4528 Board.Black.Picture = LoadPicture((sprintf(StringTmp, "%s/%s", Direct, "BlackUp.bmp"), StringTmp));
4529 } else {
4530 Reverse = 1;
4531 Board.White.Picture = LoadPicture((sprintf(StringTmp, "%s/%s", Direct, "WhiteUp.bmp"), StringTmp));
4532 Board.Black.Picture = LoadPicture((sprintf(StringTmp, "%s/%s", Direct, "BlackDn.bmp"), StringTmp));
4534 for(J = 1; J <= BoardSizeY; J++) {
4535 for(I = 1; I <= BoardSizeX; I++) {
4536 if(Squares[I][J] != 0 ) {
4537 Board.showpic[Grafix[I][J]].Visible = False;
4538 Graphnum = Pieces[abs(Squares[I][J])].Graphic;
4539 if((Squares[I][J] < 0 && Reverse == 0) || (Squares[I][J] > 0 && Reverse == 1) ) Graphnum = Graphnum + (TotGraph / 2);
4540 /* if(!strcmp(Choice, "Tai") ) Board.showpic[Grafix[I][J]] = TaiPieces.Pix[Graphnum - 1]; else */ Board.showpic[Grafix[I][J]] = Board.Pix[Graphnum - 1];
4541 if(Reverse == 0 ) {
4542 MOVE(0, Board.showpic[Grafix[I][J]], XStart + ((I - 1) * Pixels), 11 + ((J - 1) * Pixels));
4543 } else {
4544 MOVE(0, Board.showpic[Grafix[I][J]], XStart + ((BoardSizeX - I) * Pixels), 11 + ((BoardSizeY - J) * Pixels));
4546 Board.showpic[Grafix[I][J]].Visible = True;
4548 } // Next I;
4549 } // Next J;
4550 if(Drop == 1 ) {
4551 // TODO ReDim TempHand(Capture * 2);
4552 for(I = 1; I <= Capture * 2; I++) {
4553 Board.HandPic[I].Visible = False;
4554 strcpy(Board.Held[I].Caption, "");
4555 CapRef[I] = 0 - CapRef[I];
4556 if(I > Capture ) TempHand[I] = InHand[I - Capture]; else TempHand[I] = InHand[I + Capture];
4557 } // Next I;
4558 for(I = 1; I <= Capture * 2; I++) {
4559 InHand[I] = TempHand[I];
4560 if(InHand[I] > 0 ) Board.HandPic[I].Visible = True;
4561 if(InHand[I] > 1 ) sprintf(Board.Held[I].Caption, "%d", InHand[I]);
4562 } // Next I;
4564 NotSet();
4568 void SaveGame ()
4569 { // Menu function.
4570 INT V, W, Z;
4571 STRING AnswerSTR;
4572 FILE *f2;
4573 // TODO: On Error Resume Next;
4574 strcpy(Board.CMSave.DialogTitle, "Save Game");
4575 Board.CMSave.Flags = 0x400L | 0x800L | 0x4L;
4576 Board.CMSave.Action = 2;
4577 if(Err == 32755 ) return; // TODO This is for if we cancel the file-browse dialog?
4578 strcpy(SavedSTR, Board.CMSave.Filename);
4579 f2 = fopen(SavedSTR, "w");
4580 fprintf(f2, "\"%s\",%d,%d,\"%s\",%d,%d,%d,%d,%d\n", Choice, Drop, MoveCount, Turn, Notate, SeeMove, TurnCount, WhiteKing, BlackKing);
4581 fprintf(f2, "%d,%d,%d,%d,%d,%d,\"%s\"\n", WhiteLion, BlackLion, WhitePrince, BlackPrince, WhiteEmperor, BlackEmperor, Board.LastMove.Caption);
4582 fprintf(f2, "\"%s\",\"%s\",%d,%d\n", Board.WhiteClock.Caption, Board.BlackClock.Caption, HandGame, Reverse);
4583 for(W = 0; W <= TurnCount; W++) {
4584 fprintf(f2, "\"%s\",%d,%d,%d,%d\n", Score[W].Caption, Score[W].IDStart, Score[W].IDEnd, Score[W].PosStart, Score[W].PosEnd);
4585 fprintf(f2, "%d\n", Captures[W].number);
4586 for(V = 1; V <= Captures[W].number; V++) {
4587 fprintf(f2, "%d\n", Captures[W].Positions[V]);
4588 fprintf(f2, "%d\n", Captures[W].PieceNum[V]);
4589 } // Next V;
4590 } // Next W;
4591 for(W = 1; W <= BoardSizeY; W++) {
4592 for(Z = 1; Z <= BoardSizeX; Z++) {
4593 fprintf(f2, "%d\n", Squares[Z][W]);
4594 } // Next Z;
4595 } // Next W;
4596 if(Drop == 1 ) {
4597 for(W = 1; W <= Capture * 2; W++) {
4598 fprintf(f2, "%d\n", InHand[W]);
4599 } // Next W;
4601 strcpy(AnswerSTR, InputBoxSTR("Please enter a short description of the game.", "Saved Game Description", SaveTitleSTR));
4602 if(strcmp(AnswerSTR, "") ) fprintf(f2, "\"%s\"\n", AnswerSTR); else fprintf(f2, "\"Saved Game - No Title\"\n");
4603 fprintf(f2, "\"%s\"\n", Computer);
4604 fprintf(f2, "%d\n", Level);
4605 fprintf(f2, "%d\n", GameOver);
4606 fprintf(f2, "\"%s\"\n", Threat);
4607 fclose(f2);
4610 void SeeMoves ()
4611 { // Menu function. SeeMoves = 0 (off) or 1 (on)
4612 if(Board.MnuShowOn.Enabled == False ) Board.MnuShowOn.Enabled = True; else Board.MnuShowOn.Enabled = False;
4613 if(Board.MnuShowOff.Enabled == False ) Board.MnuShowOff.Enabled = True; else Board.MnuShowOff.Enabled = False;
4614 if(Board.MnuShowOn.Checked == False ) Board.MnuShowOn.Checked = True; else Board.MnuShowOn.Checked = False;
4615 if(Board.MnuShowOff.Checked == False ) Board.MnuShowOff.Checked = True; else Board.MnuShowOff.Checked = False;
4616 if(SeeMove == 1 ) {
4617 strcpy(Board.PieceID.Caption, "Show Legal Moves - On");
4618 Board.MnuThreatOn.Enabled = True;
4619 EnableNamedMenuItem("Moves.ShowThreat", True); // [HGM] added
4620 if(!strcmp(OldThreat, "On") ) {
4621 strcpy(Threat, "On");
4622 SetThreat();
4623 strcpy(OldThreat, "None");
4624 MarkMenuItem("Moves.ShowThreat", True); // [HGM] added
4625 } else {
4626 strcpy(Threat, "Off");
4627 Board.MnuThreatOn.Enabled = False;
4628 SetThreat();
4629 strcpy(OldThreat, "None");
4631 } else {
4632 strcpy(Board.PieceID.Caption, "Show Legal Moves - Off");
4633 strcpy(OldThreat, Threat);
4634 strcpy(Threat, "Off");
4635 SetThreat();
4636 Board.MnuThreatOn.Enabled = False;
4637 MarkMenuItem("Moves.ShowThreat", False); EnableNamedMenuItem("Moves.ShowThreat", False); // [HGM] added
4639 Notice = 1;
4642 void SetAutoPromote ()
4643 { // Menu function. Autopromote = 0 (off) or 1 (on)
4644 if(Board.MnuAutoOn.Enabled == False ) Board.MnuAutoOn.Enabled = True; else Board.MnuAutoOn.Enabled = False;
4645 if(Board.MnuAutoOff.Enabled == False ) Board.MnuAutoOff.Enabled = True; else Board.MnuAutoOff.Enabled = False;
4646 if(Board.MnuAutoOn.Checked == False ) Board.MnuAutoOn.Checked = True; else Board.MnuAutoOn.Checked = False;
4647 if(Board.MnuAutoOff.Checked == False ) Board.MnuAutoOff.Checked = True; else Board.MnuAutoOff.Checked = False;
4648 if(AutoPromote == 1 ) {
4649 strcpy(Board.PieceID.Caption, "Auto-Promote On");
4650 } else {
4651 strcpy(Board.PieceID.Caption, "Auto-Promote Off");
4653 Notice = 1;
4656 void SetBlackPlayer ()
4657 { // Menu function. Called if black player changes (which sets Computer before calling this).
4658 if(Board.MnuBlackPlayer.Enabled == False ) Board.MnuBlackPlayer.Enabled = True; else Board.MnuBlackPlayer.Enabled = False;
4659 if(Board.MnuBlackComp.Enabled == False ) Board.MnuBlackComp.Enabled = True; else Board.MnuBlackComp.Enabled = False;
4660 if(Board.MnuBlackPlayer.Checked == False ) Board.MnuBlackPlayer.Checked = True; else Board.MnuBlackPlayer.Checked = False;
4661 if(Board.MnuBlackComp.Checked == False ) Board.MnuBlackComp.Checked = True; else Board.MnuBlackComp.Checked = False;
4662 if(!strcmp(Choice, "Tai") || !strcmp(Choice, "Maka") ) {
4663 if(!strcmp(Computer, "White") || !strcmp(Computer, "Black") || !strcmp(Computer, "Both") ) CompTeach(); else NoCompTeach();
4665 if(!strcmp(Computer, "Both") ) CompVComp();
4668 void SetClock ()
4670 INT Mins, Secs, Hrs;
4671 if(Notice > 0 ) Notice = Notice + 1;
4672 if(Notice == 4 && Checked != 1 ) {
4673 strcpy(Board.PieceID.Caption, "");
4674 Notice = 0;
4675 if(strcmp(Board.Caption, SaveTitleSTR) ) strcpy(Board.Caption, Cap);
4677 sscanf(ElapsedSTR, "%d:%d:%d", &Hrs, &Mins, &Secs);
4678 // Secs = Val(Right$(Elapsed$, 2))
4679 // Mins = Val(Mid$(Elapsed$, 4, 2))
4680 // Hrs = Val(Left$(Elapsed$, 2))
4681 Secs = Secs + 1;
4682 if(Secs == 60 ) { Secs = 0; Mins = Mins + 1; }
4683 if(Mins == 60 ) { Mins = 0; Hrs = Hrs + 1; }
4684 if(Hrs == 100 ) Hrs = 0;
4685 // Hours$ = LTrim$(Str$(Hrs))
4686 // Minutes$ = LTrim$(Str$(Mins))
4687 // Seconds$ = LTrim$(Str$(Secs))
4688 // if(Len(Hours$) = 1 Then Hours$ = "0" + Hours$
4689 // if(Len(Minutes$) = 1 Then Minutes$ = "0" + Minutes$
4690 // if(Len(Seconds$) = 1 Then Seconds$ = "0" + Seconds$
4691 // Elapsed$ = Hours$ + ":" + Minutes$ + ":" + Seconds$
4692 sprintf(ElapsedSTR, "%02d:%02d:%02d", Hrs, Mins, Secs);
4695 void SetDifficulty ()
4696 { // Menu function. Grade = "Best" / "LessWeak" / "Weak depending on menu item.
4697 if(!strcmp(Grade, "Weak") ) {
4698 Board.MnuWeak.Enabled = False;
4699 Board.MnuWeak.Checked = True;
4700 Board.MnuBest.Visible = False;
4701 Board.MnuLessWeak.Enabled = True;
4702 Board.MnuLessWeak.Checked = False;
4704 if(!strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai") ) Board.MnuLessWeak.Visible = False, EnableNamedMenuItem("Setup.LessWeak", False); // [HGM] added
4705 else EnableNamedMenuItem("Setup.LessWeak", True); // [HGM] added
4706 if(!strcmp(Grade, "LessWeak") ) {
4707 Board.MnuWeak.Enabled = True;
4708 Board.MnuWeak.Checked = False;
4709 Board.MnuBest.Visible = False;
4710 Board.MnuLessWeak.Enabled = False;
4711 Board.MnuLessWeak.Checked = True;
4713 Board.MnuBest.Visible = False;
4714 SetGrade();
4717 void SetEval ()
4718 { // Menu function. Eval = 0 (off) or 1 (on)
4719 if(Board.MnuEvalOn.Enabled == False ) Board.MnuEvalOn.Enabled = True; else Board.MnuEvalOn.Enabled = False;
4720 if(Board.MnuEvalOff.Enabled == False ) Board.MnuEvalOff.Enabled = True; else Board.MnuEvalOff.Enabled = False;
4721 if(Board.MnuEvalOn.Checked == False ) Board.MnuEvalOn.Checked = True; else Board.MnuEvalOn.Checked = False;
4722 if(Board.MnuEvalOff.Checked == False ) Board.MnuEvalOff.Checked = True; else Board.MnuEvalOff.Checked = False;
4725 void SetGeneral ()
4726 { // Menu function.
4727 #if 0
4728 INT Z;
4729 // TODO: if(GeneralInfo == 0 ) Unload RulesHelp;
4730 GeneralInfo = 1;
4731 for(Z = 0; Z <= 17; Z++) {
4732 RulesHelp.Title[Z].Visible = False;
4733 } // Next Z;
4734 RulesHelp.Title[9].Visible = True;
4735 RulesHelp.CmdPiece.Visible = False;
4736 RulesHelp.Show();
4737 #else
4738 static char text[20000];
4739 STRING name;
4740 FILE *f;
4741 sprintf(name, "%s/General.rul", Direct);
4742 if((f = fopen(name, "r"))) {
4743 fread(text, 1, 20000, f);
4744 TagsPopUp(text+1, "General");
4745 fclose(f);
4747 #endif
4750 void SetGrade ()
4752 if(!strcmp(Grade, "Weak") ) Level = 1;
4753 if(!strcmp(Grade, "LessWeak") ) Level = 5;
4754 if(!strcmp(Grade, "LessWeak") ) {
4755 if(!strcmp(Choice, "Micro") || !strcmp(Choice, "Mini")) Level = 12;
4756 if(!strcmp(Choice, "Judkin") || !strcmp(Choice, "Whale") || !strcmp(Choice, "Yari") || !strcmp(Choice, "Tori") || !strcmp(Choice, "HeianSho")) Level = 7;
4757 if(!strcmp(Choice, "Wa") || !strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai")) Level = 4;
4758 if(!strcmp(Choice, "Tenjiku")) Level = 3;
4762 void SetGrafix ()
4764 Grafix[InitFile][InitRank] = NewGraf;
4765 Graphnum = Pieces[abs(Squares[InitFile][InitRank])].Graphic;
4766 if((Squares[InitFile][InitRank] < 0 && Reverse == 0) || (Squares[InitFile][InitRank] > 0 && Reverse == 1) ) Graphnum = Graphnum + (TotGraph / 2);
4767 /* if(!strcmp(Choice, "Tai") ) Board.showpic[NewGraf] = TaiPieces.Pix[Graphnum - 1]; else */ Board.showpic[NewGraf] = Board.Pix[Graphnum - 1];
4768 if(Reverse == 0 ) {
4769 MOVE(1, Board.showpic[NewGraf], XStart + ((InitFile - 1) * Pixels), 11 + ((InitRank - 1) * Pixels));
4770 } else {
4771 MOVE(1, Board.showpic[NewGraf], XStart + ((BoardSizeX - InitFile) * Pixels), 11 + ((BoardSizeY - InitRank) * Pixels));
4773 Board.showpic[NewGraf].Visible = True;
4776 void SetHandicap ()
4777 { // Menu function. (Calls EndSetup before.) Reduce = 1 for minus item
4778 if(Reduce != 1 ) {
4779 strcpy(Board.Caption, "Select Handicap Pieces - (Press Right Mouse Button to Start Game)");
4780 } else {
4781 strcpy(Board.Caption, "Select Pieces to Remove - (Press Right Mouse Button When Finished)");
4783 if(Reduce != 1 ) Handicap = 1;
4784 strcpy(Board.BlackClock.Caption, "00:00:00");
4785 strcpy(Board.WhiteClock.Caption, "00:00:00");
4786 Board.Timer1.Enabled = False;
4789 void SetKings ()
4791 INT GG, HH;
4792 BlackPrince = 0; BlackKing = 1; BlackEmperor = 0;
4793 WhitePrince = 0; WhiteKing = 1; WhiteEmperor = 0;
4794 for(GG = 1; GG <= BoardSizeY; GG++) {
4795 for(HH = 1; HH <= BoardSizeX; HH++) {
4796 if(Squares[HH][GG] == 1 ) { BlackKing = 0; BlackKingX = HH; BlackKingY = GG; }
4797 if(Squares[HH][GG] == -1 ) { WhiteKing = 0; WhiteKingX = HH; WhiteKingY = GG; }
4798 if(Squares[HH][GG] > 0 ) {
4799 if(!strcmp(Pieces[abs(Squares[HH][GG])].Name, "Prince") || !strcmp(Pieces[abs(Squares[HH][GG])].Name, "Crown Prince") ) BlackPrince = BlackPrince + 1;
4800 if(!strcmp(Pieces[abs(Squares[HH][GG])].Name, "Emperor") ) { BlackEmperor = 1; BlackEmpX = HH; BlackEmpY = GG; }
4802 if(Squares[HH][GG] < 0 ) {
4803 if(!strcmp(Pieces[abs(Squares[HH][GG])].Name, "Prince") || !strcmp(Pieces[abs(Squares[HH][GG])].Name, "Crown Prince") ) WhitePrince = WhitePrince + 1;
4804 if(!strcmp(Pieces[abs(Squares[HH][GG])].Name, "Emperor") ) { WhiteEmperor = 1; WhiteEmpX = HH; WhiteEmpY = GG; }
4806 } // Next HH;
4807 } // Next GG;
4810 void SetLastMove ()
4811 { // Menu function. ShowLast = 0 (off) or 1 (on).
4812 if(Board.MnuShowLastOn.Enabled == False ) Board.MnuShowLastOn.Enabled = True; else Board.MnuShowLastOn.Enabled = False;
4813 if(Board.MnuShowLastOff.Enabled == False ) Board.MnuShowLastOff.Enabled = True; else Board.MnuShowLastOff.Enabled = False;
4814 if(Board.MnuShowLastOn.Checked == False ) Board.MnuShowLastOn.Checked = True; else Board.MnuShowLastOn.Checked = False;
4815 if(Board.MnuShowLastOff.Checked == False ) Board.MnuShowLastOff.Checked = True; else Board.MnuShowLastOff.Checked = False;
4818 void SetLionHawk ()
4819 { // Menu function. LionHawkVer = 1 or 2 depending on item. (Sets piece values before.)
4820 if(Board.MnuLVer1.Enabled == False ) Board.MnuLVer1.Enabled = True; else Board.MnuLVer1.Enabled = False;
4821 if(Board.MnuLVer2.Enabled == False ) Board.MnuLVer2.Enabled = True; else Board.MnuLVer2.Enabled = False;
4822 if(Board.MnuLVer1.Checked == False ) Board.MnuLVer1.Checked = True; else Board.MnuLVer1.Checked = False;
4823 if(Board.MnuLVer2.Checked == False ) Board.MnuLVer2.Checked = True; else Board.MnuLVer2.Checked = False;
4826 void SetPieces ()
4827 { // Called from New menu with NewGame = 1 if LegalMoves == 0.
4828 INT K, V, W, X, Y;
4829 STRING LastGoSTR, WhiteTimeSTR, BlackTimeSTR;
4830 FILE *f1;
4831 Randomize();
4832 XA = 0; GameOver = 0; LegalMoves = 0; strcpy(OldThreat, "None");
4833 if(Reload != 1 ) ConfigLoad(); else ConfigLoad2();
4834 Reload = 1; Influence = 0; CompMove = 0; Evaluate = 0;
4835 LionPiece = -1; CheckTest = 0; Checked = 0;
4836 sprintf(Datafile, "%s/%s.dat", Direct, Choice);
4837 strcpy(Turn, "Black"); LionPiece = -1; WhiteKing = 0; BlackKing = 0; WhitePrince = 0; BlackPrince = 0; RealLion = 0;
4838 HandGame = 0; WhiteLion = 0; BlackLion = 0; WhiteEmperor = 0; BlackEmperor = 0; Taken = 0; Mate = 0;
4839 strcpy(CMoveSTR, ""); TurnCount = 0; EndTurn = 0; MoveCount = 0;
4840 strcpy(Board.LastMove.Caption, ""); strcpy(Board.NextMove.Caption, "Black to Move");
4841 if(Reverse != 1 ) Reverse = 0;
4842 XStart = 110;
4843 if(!strcmp(Choice, "Tenjiku") ) strcpy(Computer, "None");
4844 if(!strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "DaiDai") || !strcmp(Choice, "Maka") || !strcmp(Choice, "Tai") ) { strcpy(Grade, "Weak"); SetDifficulty(); }
4845 if(!strcmp(Choice, "Whale") || !strcmp(Choice, "Judkin") ) XStart = 140;
4846 if(!strcmp(Choice, "Mini") ) XStart = 170;
4847 if(!strcmp(Choice, "Micro") ) XStart = 200;
4848 if(!strcmp(Choice, "Yari") ) XStart = 157;
4849 YStart = 0; // FIXME: this & next line: 3 variants need a correction, but only for flipped pieces. Why???
4850 if(!strcmp(Choice, "Chu") || !strcmp(Choice, "Dai") || !strcmp(Choice, "Tenjiku") ) YStart = 4;
4851 // ReDim ShortScore[4000];
4852 // ReDim Score[4000];
4853 // ReDim Captures[4000];
4855 f1 = fopen(Datafile, "r");
4857 // load general game data;
4859 fscanf(f1, "%[^\n\r] %s %d,%d,%d,%d", Cap, Boardbmp, &Drop, &Boardsize, &Prom, &PromDotY);
4860 fscanf(f1, ",%d,%d,%d,%d,%d,%d", &XCorner, &YCorner, &Pixels, &Totpiece, &PieceNum, &TotGraph);
4861 BoardSizeX = Boardsize; BoardSizeY = Boardsize;
4862 if(!strcmp(Choice, "HShogi") ) BoardSizeY = 8;
4863 if(!strcmp(Choice, "Micro") ) BoardSizeY = 5;
4864 if(!strcmp(Choice, "Yari") ) { BoardSizeY = 9; BoardSizeX = 7; }
4865 if(Loading == 1 ) {
4866 fscanf(f2, "%d,%d,\"%[^\"]\",%d,%d,%d,%d,%d", &Drop, &MoveCount, Turn, &Notate, &SeeMove, &TurnCount, &WhiteKing, &BlackKing);
4867 fscanf(f2, "%d,%d,%d,%d,%d,%d,\"%[^\"]\"", &WhiteLion, &BlackLion, &WhitePrince, &BlackPrince, &WhiteEmperor, &BlackEmperor, LastGoSTR);
4868 fscanf(f2, " \"%[^\"]\",\"%[^\"]\",%d,%d", WhiteTimeSTR, BlackTimeSTR, &HandGame, &Reverse);
4869 EndTurn = TurnCount;
4870 strcpy(Board.LastMove.Caption, LastGoSTR);
4871 strcpy(Board.WhiteClock.Caption, WhiteTimeSTR);
4872 strcpy(Board.BlackClock.Caption, BlackTimeSTR);
4873 if(GameOver == 1 ) {
4874 strcpy(Board.NextMove.Caption, "Game Ended");
4875 } else {
4876 if(!strcmp(Turn, "White") ) strcpy(Board.NextMove.Caption, "White to Move");
4878 for(W = 0; W <= TurnCount; W++) {
4879 if(!fscanf(f2, " \"%[^\"]\",", Score[W].Caption)) fscanf(f2, "\","), Score[W].Caption[0] = '\0'; // scanf chokes on empty string!
4880 fscanf(f2, "%d,%d,%d,%d", &Score[W].IDStart, &Score[W].IDEnd, &Score[W].PosStart, &Score[W].PosEnd);
4881 fscanf(f2, "%d", &Captures[W].number);
4882 for(V = 1; V <= Captures[W].number; V++) {
4883 fscanf(f2, "%d", &Captures[W].Positions[V]);
4884 fscanf(f2, "%d", &Captures[W].PieceNum[V]);
4885 } // Next V;
4886 } // Next W;
4887 } else {
4888 Board.MnuHandicap.Enabled = True;
4890 // ReDim Pieces(1 To PieceNum / 2) As Piece;
4891 // ReDim TestBoard(BoardSizeX, BoardSizeY);
4892 // ReDim Grafix[BoardSizeX][BoardSizeY] As Integer;
4893 // ReDim Squares[BoardSizeX][BoardSizeY] As Integer;
4894 // ReDim Legal[BoardSizeX][BoardSizeY] As Integer;
4895 // ReDim OldLegal[BoardSizeX][BoardSizeY] As Integer;
4896 // ReDim AreaOK[BoardSizeX][BoardSizeY] As Integer;
4897 // ReDim Camps[BoardSizeX][BoardSizeY] As Integer;
4898 // ReDim Comp[BoardSizeX][BoardSizeY] As Integer;
4899 // ReDim Clearing(200) As Empty;
4900 // ReDim BanMap[BoardSizeX][BoardSizeY] As Map;
4901 // ReDim BackMap[BoardSizeX][BoardSizeY] As Map;
4902 // ReDim Attacker[BoardSizeX][BoardSizeY] As Integer;
4903 // ReDim OldAttack(BoardSizeX, BoardSizeY) As Integer;
4904 // ReDim PieceMask(6, Pixels)
4905 // ReDim CompLegal[2000] As LegalList;
4906 // ReDim KingTally[2000] As Long;
4907 // ReDim LowBlack[BoardSizeX][BoardSizeY] As Integer;
4908 // ReDim LowWhite[BoardSizeX][BoardSizeY] As Integer;
4909 if(!strcmp(Choice, "Wa") && Loading != 1 ) WaDrop();
4910 if(!strcmp(Choice, "Wa") && Drop == 1 ) strcpy(Boardbmp, "Waboard2.bmp");
4911 Board.Picture = LoadPicture((sprintf(StringTmp, "%s/boards/%s", Direct, Boardbmp), StringTmp));
4912 strcpy(Board.Caption, Cap);
4914 // load piece data;
4916 for(I = 1; I <= PieceNum / 2; I++) {
4917 fscanf(f1, "%d,%[^,]", &Pieces[I].number, Pieces[I].Name);
4918 fscanf(f1, ",%[^,],%d", Pieces[I].sname, &Pieces[I].Value);
4919 fscanf(f1, ",%d,%d,%d", &Pieces[I].PrValue, &Pieces[I].Promotes, &Pieces[I].Graphic);
4920 fscanf(f1, ",%d", &Pieces[I].PrGraphic);
4921 for(J = 1; J <= 8; J++) {
4922 fscanf(f1, ",%d", &Pieces[I].Moves[J]);
4923 } // Next J;
4924 fscanf(f1, ",%c", &Pieces[I].special);
4925 fscanf(f1, ",%d", &Pieces[I].Mask);
4926 fscanf(f1, ",%d", &Pieces[I].Range); // WARNING: original .dat files leave this out if 0
4927 } // Next I;
4929 // load board data;
4931 Count = 0; M = 0;
4932 for(J = 1; J <= BoardSizeY; J++) {
4933 for(I = 1; I <= BoardSizeX; I++) {
4934 fscanf(f1, "%d,", &Squares[I][J]);
4935 if(Loading == 1 ) fscanf(f2, "%d", &Squares[I][J]);
4936 Grafix[I][J] = -1;
4937 if(Squares[I][J] != 0 ) {
4938 Graphnum = Pieces[abs(Squares[I][J])].Graphic;
4939 if((Squares[I][J] < 0 && Reverse == 0) || (Squares[I][J] > 0 && Reverse == 1) ) Graphnum = Graphnum + (TotGraph / 2);
4940 /* if(!strcmp(Choice, "Tai") ) Board.showpic[COUNT] = TaiPieces.Pix[Graphnum - 1]; else */ Board.showpic[COUNT] = Board.Pix[Graphnum - 1];
4941 if(Reverse == 0 ) {
4942 MOVE(0, Board.showpic[COUNT], XStart + ((I - 1) * Pixels), 11 + ((J - 1) * Pixels));
4943 } else {
4944 MOVE(0, Board.showpic[COUNT], XStart + ((BoardSizeX - I) * Pixels), 11 + ((BoardSizeY - J) * Pixels));
4946 Board.showpic[COUNT].Visible = True;
4947 Grafix[I][J] = Count;
4948 Count = Count + 1;
4950 } // Next I;
4951 } // Next J;
4953 //Load Drop Data;
4955 if(Drop == 1 || !strcmp(Choice, "Wa") ) {
4956 if(Loading == 1 ) {
4957 for(K = Count; K <= Totpiece; K++) {
4958 Board.showpic[K].Visible = False;
4959 } // Next K;
4961 fscanf(f1, "%d,", &Capture);
4962 // ReDim CapRef(Capture * 2) As Integer;
4963 // ReDim InHand(Capture * 2) As Integer;
4964 // ReDim CompHeld(Capture * 2) As Integer;
4965 // ReDim OldHand(Capture * 2) As Integer;
4966 for(I = 1; I <= Capture; I++) {
4967 fscanf(f1, "%d,", &CapRef[I]);
4968 CapRef[I + Capture] = 0 - CapRef[I];
4969 } // Next I;
4970 if(Reverse == 0 ) {
4971 Board.White.Picture = LoadPicture((sprintf(StringTmp, "%s/%s", Direct, "WhiteDn.bmp"), StringTmp));
4972 Board.Black.Picture = LoadPicture((sprintf(StringTmp, "%s/%s", Direct, "BlackUp.bmp"), StringTmp));
4973 } else {
4974 Board.White.Picture = LoadPicture((sprintf(StringTmp, "%s/%s", Direct, "WhiteUp.bmp"), StringTmp));
4975 Board.Black.Picture = LoadPicture((sprintf(StringTmp, "%s/%s", Direct, "BlackDn.bmp"), StringTmp));
4976 for(I = 1; I <= Capture * 2; I++) {
4977 CapRef[I] = 0 - CapRef[I];
4978 } // Next I;
4980 for(I = 1; I <= Capture * 2; I++) {
4981 InHand[I] = 0;
4982 if(Loading == 1 ) fscanf(f2, "%d", &InHand[I]);
4983 Graphnum = Pieces[abs(CapRef[I])].Graphic;
4984 if(I > Capture ) Graphnum = Graphnum + (TotGraph / 2);
4985 Board.HandPic[I] = Board.Pix[Graphnum - 1];
4986 Board.HandPic[I].Visible = False;
4987 strcpy(Board.Held[I].Caption, "");
4988 if(Loading == 1 && InHand[I] > 0 ) Board.HandPic[I].Visible = True;
4989 if(Loading == 1 && InHand[I] > 1 ) sprintf(Board.Held[I].Caption, "%d", InHand[I]);
4990 if(strcmp(Choice, "Wa") && strcmp(Choice, "Micro") ) {
4991 if(I <= Capture ) {
4992 X = 629 - Pixels;
4993 Y = 11 + (I - 1) * Pixels;
4994 } else {
4995 X = 10;
4996 Y = 11 + (Capture - I + Capture) * Pixels;
4998 MOVE(0, Board.HandPic[I], X, Y);
5000 if(!strcmp(Choice, "Wa") || !strcmp(Choice, "Micro") ) {
5001 if(I <= Capture ) {
5002 if(I <= Capture / 2 ) {
5003 X = 629 - Pixels;
5004 Y = 11 + (I - 1) * Pixels;
5005 } else {
5006 X = 629 - (Pixels * 2);
5007 Y = 11 + (I - (Capture / 2) - 1) * Pixels;
5009 } else {
5010 if(I <= Capture * 1.5 ) {
5011 X = 10;
5012 Y = 11 + (Capture - I + (Capture / 2)) * Pixels;
5013 } else {
5014 X = 10 + Pixels;
5015 Y = 11 + (Capture - (I - (Capture / 2)) + (Capture / 2)) * Pixels;
5018 MOVE(0, Board.HandPic[I], X, Y);
5020 } // Next I;
5022 fscanf(f1, "%d", &PieceSizes);
5023 for(J = 1; J <= PieceSizes; J++) {
5024 for(K = 1; K <= Pixels-1; K++) {
5025 fscanf(f1, "%d,", &PieceMask[J][K]);
5026 } // Next K;
5027 } // Next J;
5028 fclose(f1);
5029 SetKings();
5030 NotSet();
5031 Notation();
5032 if(Board.WindowState != 2 ) {
5033 if(strcmp(Choice, "Tai") ) {
5034 Board.Left = (screen.Width / 2) - 4860;
5035 Board.Top = (screen.Height / 2) - 3650;
5036 } else {
5037 Board.Left = (screen.Width / 2) - 6075;
5038 Board.Top = (screen.Height / 2) - 4562;
5041 if((Display == 640 || !strcmp(Choice, "Tai")) && NewGame != 1 ) {
5042 Board.Left = 5;
5043 Board.Top = 5;
5044 Board.WindowState = 2;
5045 } else {
5046 Board.WindowState = 0;
5048 if(!strcmp(Choice, "Tai") ) Board.WindowState = 2;
5049 if(Loading != 1 && Timing != 1 ) ClocksOn();
5050 if(strcmp(Board.WhiteClock.Caption, "00:00:00") || strcmp(Board.BlackClock.Caption, "00:00:00") ) Board.Timer1.Enabled = True;
5051 if(Timing == 1 ) ClocksOff();
5052 if(!strcmp(Choice, "Tai") || !strcmp(Choice, "Maka") ) {
5053 if(!strcmp(Computer, "White") || !strcmp(Computer, "Black") || !strcmp(Computer, "Both") ) CompTeach(); else NoCompTeach();
5055 Board.MnuBest.Visible = False;
5056 Board.Show();
5057 Start.MousePointer = 0;
5058 // Start.Hide();
5059 if(!strcmp(Computer, "White") || !strcmp(Computer, "Black") ) {
5060 Board.MnuSwitch.Enabled = True;
5061 EnableNamedMenuItem("Setup.SwitchSides", True); // [HGM] added
5062 sprintf(Board.PieceID.Caption, "Computer plays %s", Computer); Notice = 1;
5063 } else {
5064 Board.MnuSwitch.Enabled = False;
5065 EnableNamedMenuItem("Setup.SwitchSides", False); // [HGM] added
5067 if(!strcmp(Computer, Turn) || !strcmp(Computer, "Both") ) CompMain();
5070 void SetRules ()
5071 { // Menu function.
5072 #if 0
5073 INT Z;
5074 // TODO: if(GeneralInfo == 1 ) Unload RulesHelp;
5075 GeneralInfo = 0;
5076 for(Z = 0; Z <= 17; Z++) {
5077 RulesHelp.Title[Z].Visible = False;
5078 } // Next Z;
5079 if(GameNo < 10 ) RulesHelp.Title[GameNo - 1].Visible = True; else RulesHelp.Title[GameNo].Visible = True;
5080 RulesHelp.CmdPiece.Visible = True;
5081 RulesHelp.Show();
5082 #else
5083 static char text[20000];
5084 STRING name;
5085 FILE *f;
5086 sprintf(name, "%s/%s.rul", Direct, Choice);
5087 if((f = fopen(name, "r"))) {
5088 fread(text, 1, 20000, f);
5089 TagsPopUp(text+1, NULL);
5090 fclose(f);
5092 #endif
5095 void SetSuggest ()
5096 { // Menu function.
5097 Suggest = 1;
5098 OldSeeMove = SeeMove;
5099 strcpy(OldComputer, Computer);
5100 strcpy(Computer, Turn);
5101 strcpy(Board.Caption, "The Computer suggests...."); Notice = 5;
5102 RealLevel = Level; Level = 1;
5103 CompMain();
5104 Level = RealLevel;
5105 LegalMoves = 0;
5108 void SetTeach ()
5110 if(Board.MnuVer1.Enabled == False ) Board.MnuVer1.Enabled = True; else Board.MnuVer1.Enabled = False;
5111 if(Board.MnuVer2.Enabled == False ) Board.MnuVer2.Enabled = True; else Board.MnuVer2.Enabled = False;
5112 if(Board.MnuVer1.Checked == False ) Board.MnuVer1.Checked = True; else Board.MnuVer1.Checked = False;
5113 if(Board.MnuVer2.Checked == False ) Board.MnuVer2.Checked = True; else Board.MnuVer2.Checked = False;
5116 void SetThreat ()
5117 { // Menu function. Threat = "On" or "Off" depending on the item.
5118 if(Board.MnuThreatOn.Enabled == False ) Board.MnuThreatOn.Enabled = True; else Board.MnuThreatOn.Enabled = False;
5119 if(Board.MnuThreatOff.Enabled == False ) Board.MnuThreatOff.Enabled = True; else Board.MnuThreatOff.Enabled = False;
5120 if(Board.MnuThreatOn.Checked == False ) Board.MnuThreatOn.Checked = True; else Board.MnuThreatOn.Checked = False;
5121 if(Board.MnuThreatOn.Checked == False ) Board.MnuThreatOff.Checked = True; else Board.MnuThreatOff.Checked = False;
5122 if(SeeMove == 1 && strcmp(OldThreat, "On") && strcmp(OldThreat, "Off") ) {
5123 if(Board.MnuThreatOff.Enabled == False ) strcpy(Board.PieceID.Caption, "Show Influence or Threats Off");
5125 if(strcmp(OldThreat, "On") && strcmp(OldThreat, "Off") ) {
5126 if(Board.MnuThreatOff.Enabled == True ) strcpy(Board.PieceID.Caption, "Show Influence or Threats On");
5128 Notice = 1;
5131 void SetWhitePlayer ()
5132 { // Menu function, called when white player changes, after setting Computer.
5133 if(Board.MnuWhitePlayer.Enabled == False ) Board.MnuWhitePlayer.Enabled = True; else Board.MnuWhitePlayer.Enabled = False;
5134 if(Board.MnuWhiteComp.Enabled == False ) Board.MnuWhiteComp.Enabled = True; else Board.MnuWhiteComp.Enabled = False;
5135 if(Board.MnuWhitePlayer.Checked == False ) Board.MnuWhitePlayer.Checked = True; else Board.MnuWhitePlayer.Checked = False;
5136 if(Board.MnuWhiteComp.Checked == False ) Board.MnuWhiteComp.Checked = True; else Board.MnuWhiteComp.Checked = False;
5137 if(!strcmp(Choice, "Tai") || !strcmp(Choice, "Maka") ) {
5138 if(!strcmp(Computer, "White") || !strcmp(Computer, "Black") || !strcmp(Computer, "Both") ) CompTeach(); else NoCompTeach();
5140 if(!strcmp(Computer, "Both") ) CompVComp();
5143 void ShowMove ()
5145 if(GameOver == 1 || Checked > 0 ) return;
5146 if(Squares[NewFile][NewRank] == 0 && (Range != 1 || Influence > 0) ) {
5147 if(Pieces[abs(Squares[InitFile][InitRank])].special != 'T' || M != 1 ) {
5148 if(Pieces[abs(Squares[InitFile][InitRank])].special == 'T' ) Tetrarchs();
5149 if(Blocked != 1 ) {
5150 Legal[NewFile][NewRank] = 1;
5151 Board.FillColor = 0xFFFFFF;
5152 if(SeeMove == 1 || CompMove == 1 || Evaluate == 1 ) { SeeFile = NewFile; SeeRank = NewRank; LookMove(); }
5153 if(Demon == 1 ) FireDemon();
5155 Blocked = 0;
5157 if(!strcmp(Choice, "Tenjiku") ) CheckBurn();
5158 } else {
5159 if(Pieces[abs(Squares[InitFile][InitRank])].special != 'T' || M != 1 ) Last = 1;
5160 if(Pieces[abs(Squares[InitFile][InitRank])].special == 'T' ) Tetrarchs();
5161 if(Blocked != 1 ) {
5162 if((Sgn(Squares[InitFile][InitRank]) != Sgn(Squares[NewFile][NewRank]) || Influence > 0) && Legal[NewFile][NewRank] != 4 && Squares[NewFile][NewRank] != 0 ) {
5163 if(Squares[NewFile][NewRank] != 0 && Range == 1 ) TestStrength();
5164 if(!strcmp(Choice, "Chu") && !strcmp(Pieces[abs(Squares[NewFile][NewRank])].Name, "Lion") && strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Lion") ) {
5165 NoLionCapture = 0;
5166 if(!strcmp(Turn, "Black") ) {
5167 if(WhiteLion == 1 ) NoLionCapture = 1;
5168 } else {
5169 if(BlackLion == 1 ) NoLionCapture = 1;
5172 if(Weaker != 1 && NoLionCapture != 1 ) {
5173 Board.FillColor = 0xFFL;
5174 Legal[NewFile][NewRank] = 1;
5175 if(SeeMove == 1 ) { SeeFile = NewFile; SeeRank = NewRank; LookMove(); }
5176 if(Demon == 1 ) FireDemon();
5177 if(!strcmp(Choice, "Tenjiku") ) CheckBurn();
5179 NoLionCapture = 0;
5182 Blocked = 0;
5186 void ShowProm ()
5187 { // Button2-Down handler for Form & board piece. (NewX, NewY) is coords.
5188 // CCC = 1 and ClickPiece = 0 (Form) or 1 (piece). NewButton is button nr for piece
5189 STRING PromName;
5190 INT K, L;
5191 if(strcmp(Computer, Turn) && strcmp(Computer, "Both") && Level != 0 && GameOver != 1 ) {
5192 if(Selection != 0 || MovePiece == 1 ) {
5193 EndSelect();
5194 } else {
5195 if(Handicap == 1 || Reduce == 1 ) {
5196 strcpy(Board.Caption, Cap);
5197 Handicap = 0; Reduce = 0;
5198 Board.Timer1.Enabled = True;
5199 } else {
5200 if(ClickPiece == 1 ) {
5201 RightClick = 1;
5202 strcpy(Board.PieceID.Caption, "");
5203 Board.PieceID.ForeColor = 0x8000L;
5204 for(K = 1; K <= BoardSizeY; K++) {
5205 for(L = 1; L <= BoardSizeX; L++) {
5206 if(Grafix[L][K] == I ) {
5207 if(Pieces[abs(Squares[L][K])].Promotes > 0 && strcmp(Pieces[abs(Squares[L][K])].Name, "Killer Whale") ) sprintf(PromName, "Promotes to %s", Pieces[abs(Pieces[abs(Squares[L][K])].Promotes)].Name); else strcpy(PromName, "Does not promote");
5208 if(!strcmp(Pieces[abs(Squares[L][K])].Name, "Porpoise") ) strcpy(PromName, "Promotes to Killer Whale");
5209 strcpy(Board.PieceID.Caption, PromName);
5210 InitFile = L; InitRank = K;
5211 if(SeeMove == 1 && !strcmp(Threat, "On") ) ActingPieces();
5213 } // Next L;
5214 } // Next K;
5215 ClickPiece = 0;
5216 } else {
5217 FormActing();
5224 void SingleStep ()
5226 Last = 0; M = 0; NewFile = InitFile; NewRank = InitRank;
5227 while( NewFile + FileInc > 0 && NewFile + FileInc <= BoardSizeX && NewRank + RankInc > 0 && NewRank + RankInc <= BoardSizeY && M < MoveTest && Last == 0) {
5228 NewFile = NewFile + FileInc;
5229 NewRank = NewRank + RankInc;
5230 M = M + 1;
5231 ShowMove();
5232 if(NewRank <= BoardSizeY && NewRank > 0 && NewFile > 0 && NewFile <= BoardSizeX ) {
5233 if(Range == 1 && Squares[NewFile][NewRank] != 0 ) TestStrength();
5234 if(Range == 1 && Weaker == 0 ) Last = 0;
5236 if(Hook == 1 && Last != 1 ) HookMove();
5238 Range = 0; Weaker = 0; Hook = 0;
5241 void SpecialMove ()
5243 switch( Pieces[abs(Squares[InitFile][InitRank])].special) {
5244 case 'L': if(LionPiece == I ) Lion2(); else Lion(); break;
5245 case 'T': Igui(); break;
5246 case 'D': Area = 2; P = InitFile; N = InitRank; AreaMove(); break;
5247 case 'F': Area = 3; P = InitFile; N = InitRank; AreaMove(); break;
5248 //case "E"; Emperor();
5250 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Vice General") ) {
5251 Area = 3; N = InitRank; P = InitFile;
5252 AreaMove();
5256 void SquareReplace ()
5258 INT K, L, Found;
5259 STRING VictimSTR;
5260 if(MovePiece == 1 ) {
5261 Move2();
5262 } else {
5263 K = 1;
5264 do {
5265 L = 1;
5266 do {
5267 if(Grafix[L][K] == I ) {
5268 InitFile = L;
5269 InitRank = K;
5270 Found = 1;
5272 L = L + 1;
5273 } while( !(L > BoardSizeX || Found == 1) );
5274 K = K + 1;
5275 } while( !(K > BoardSizeY || Found == 1) );
5276 Found = 0;
5277 strcpy(VictimSTR, Pieces[abs(Squares[InitFile][InitRank])].Name);
5278 if(Squares[InitFile][InitRank] > 0 && (!strcmp(VictimSTR, "Prince") || !strcmp(VictimSTR, "Crown Prince")) ) BlackPrince = BlackPrince - 1;
5279 if(Squares[InitFile][InitRank] < 0 && (!strcmp(VictimSTR, "Prince") || !strcmp(VictimSTR, "Crown Prince")) ) WhitePrince = WhitePrince - 1;
5280 Squares[InitFile][InitRank] = Selection;
5281 Board.showpic[Grafix[InitFile][InitRank]].Visible = False;
5282 MOVE(1, Board.showpic[Grafix[InitFile][InitRank]], 0, 0);
5283 NewGraf = Grafix[InitFile][InitRank];
5284 SetGrafix();
5285 Reduce = 0; MovePiece = 0;
5289 void StartUp ()
5291 if(!strcmp(Choice, "Micro") ) { strcpy(GameName, "Micro"); GameNo = 14; } // Load Micro; Set Board = Micro; }
5292 if(!strcmp(Choice, "Whale") ) { strcpy(GameName, "Whale"); GameNo = 15; } // Load Whale; Set Board = Whale; }
5293 if(!strcmp(Choice, "Shogi") ) { strcpy(GameName, ""); GameNo = 2; } // Load Shogi; Set Board = Shogi; }
5294 if(!strcmp(Choice, "Tori") ) { strcpy(GameName, "Bird"); GameNo = 1; } // Load Tori; Set Board = Tori; }
5295 if(!strcmp(Choice, "Sho") ) { strcpy(GameName, "Little"); GameNo = 11; } // Load Shogi; Set Board = Shogi; }
5296 if(!strcmp(Choice, "Wa") ) { strcpy(GameName, "Wa"); GameNo = 3; } // Load Wa; Set Board = Wa; }
5297 if(!strcmp(Choice, "Chu") ) { strcpy(GameName, "Middle"); GameNo = 4; } // } // Load Chu; Set Board = Chu; }
5298 if(!strcmp(Choice, "Dai") ) { strcpy(GameName, "Great"); GameNo = 5; } // Load Dai; Set Board = Dai; }
5299 if(!strcmp(Choice, "Tenjiku") ) { strcpy(GameName, "Exotic"); GameNo = 6; } // Load Tenjiku; Set Board = Tenjiku; }
5300 if(!strcmp(Choice, "DaiDai") ) { strcpy(GameName, "Great Great"); GameNo = 7; } // Load DaiDai; Set Board = DaiDai; }
5301 if(!strcmp(Choice, "Maka") ) { strcpy(GameName, "Ultra Great Great"); GameNo = 8; } // Load Maka; Set Board = Maka; }
5302 if(!strcmp(Choice, "Tai") ) { strcpy(GameName, "Grand"); GameNo = 9; } // Load Tai; Set Board = Tai; }
5303 if(!strcmp(Choice, "HShogi") ) { strcpy(GameName, "Early"); GameNo = 12; } // Load HeianSho; Set Board = HeianSho; }
5304 if(!strcmp(Choice, "Heian") ) { strcpy(GameName, "Early Great"); GameNo = 10; } // Load Heian; Set Board = Heian; }
5305 if(!strcmp(Choice, "Mini") ) { strcpy(GameName, "Mini"); GameNo = 13; } // Load Mini; Set Board = Mini; }
5306 if(!strcmp(Choice, "Yari") ) { strcpy(GameName, "Yari"); GameNo = 16; } // Load Yari; Set Board = Yari; }
5307 if(!strcmp(Choice, "Judkin") ) { strcpy(GameName, "Judkin's"); GameNo = 17; } // Load Judkin; Set Board = Judkin; }
5308 LoadBoard(Choice); // replaces all the commented-out loads above
5309 SetPieces();
5310 DrawBoard(); // [HGM]added to redraw the board with pieces
5311 #if 0
5312 // Unload is not needed
5313 if(strcmp(OldChoice, Choice) ) {
5314 if(!strcmp(OldChoice, "Micro")) Unload Micro;
5315 if(!strcmp(OldChoice, "Whale")) Unload Whale;
5316 if(!strcmp(OldChoice, "Sho")) Unload Shogi;
5317 if(!strcmp(OldChoice, "Shogi")) Unload Shogi;
5318 if(!strcmp(OldChoice, "Tori")) Unload Tori;
5319 if(!strcmp(OldChoice, "Wa")) Unload Wa;
5320 if(!strcmp(OldChoice, "Chu")) Unload Chu;
5321 if(!strcmp(OldChoice, "Dai")) Unload Dai;
5322 if(!strcmp(OldChoice, "Tenjiku")) Unload Tenjiku;
5323 if(!strcmp(OldChoice, "DaiDai")) Unload DaiDai;
5324 if(!strcmp(OldChoice, "Maka")) Unload Maka;
5325 if(!strcmp(OldChoice, "Tai")) { Unload Tai; Unload TaiPieces; }
5326 if(!strcmp(OldChoice, "Heian")) Unload Heian;
5327 if(!strcmp(OldChoice, "HShogi")) Unload HeianSho;
5328 if(!strcmp(OldChoice, "Mini")) Unload Mini;
5329 if(!strcmp(OldChoice, "Yari")) Unload Yari;
5330 if(!strcmp(OldChoice, "Judkin")) Unload Judkin;
5331 } else {
5332 Board.MousePointer = 0;
5334 #endif
5337 void SuggestMove ()
5339 INT X, Y, GG, HH, II, MM;
5340 SeeMove = OldSeeMove;
5341 Suggest = 0;
5342 strcpy(Computer, OldComputer);
5343 Board.ForeColor = 0xFFL;
5344 Board.FillStyle = 1;
5345 Board.DrawWidth = 2;
5346 Board.ForeColor = 0xFFFFFF;
5347 if(CompLegal[BestMove].StartFile != 0 ) {
5348 if(Reverse == 0 ) {
5349 Board.Line(XStart - 1 + (CompLegal[BestMove].StartFile - 1) * Pixels, 10 + (CompLegal[BestMove].StartRank - 1) * Pixels, XStart - 1 + (CompLegal[BestMove].StartFile * Pixels), 10 + (CompLegal[BestMove].StartRank * Pixels), NOCOLOR, "B");
5350 } else {
5351 Board.Line(XStart - 1 + (BoardSizeX - CompLegal[BestMove].StartFile) * Pixels, 10 + (BoardSizeY - CompLegal[BestMove].StartRank) * Pixels, XStart - 1 + (BoardSizeX - CompLegal[BestMove].StartFile + 1) * Pixels, 10 + (BoardSizeY - CompLegal[BestMove].StartRank + 1) * Pixels, NOCOLOR, "B");
5353 } else {
5354 for(HH = 1; HH <= Capture * 2; HH++) {
5355 if(CapRef[HH] == CompLegal[BestMove].EndPiece ) II = HH;
5356 } // Next HH;
5357 if(strcmp(Choice, "Wa") && strcmp(Choice, "Micro") ) {
5358 if(II <= Capture ) {
5359 X = 629 - Pixels;
5360 Y = 11 + (II - 1) * Pixels;
5361 } else {
5362 X = 10;
5363 Y = 11 + (Capture - II + Capture) * Pixels;
5365 Board.Line(X, Y, X + Pixels, Y + Pixels, NOCOLOR, "B");
5367 if(!strcmp(Choice, "Wa") || !strcmp(Choice, "Micro") ) {
5368 if(II <= Capture ) {
5369 if(II <= Capture / 2 ) {
5370 X = 629 - Pixels;
5371 Y = 11 + (II - 1) * Pixels;
5372 } else {
5373 X = 629 - (Pixels * 2);
5374 Y = 11 + (II - (Capture / 2) - 1) * Pixels;
5376 } else {
5377 if(II <= Capture * 1.5 ) {
5378 X = 10;
5379 Y = 11 + (Capture - II + (Capture / 2)) * Pixels;
5380 } else {
5381 X = 10 + Pixels;
5382 Y = 11 + (Capture - (II - (Capture / 2)) + (Capture / 2)) * Pixels;
5385 Board.Line(X, Y, X + Pixels, Y + Pixels, NOCOLOR, "B");
5388 Board.FillStyle = 0;
5389 Board.DrawWidth = 1;
5390 Board.ForeColor = 0x0L;
5391 if(Reverse == 0 ) {
5392 Board.Circle(XStart + (CompLegal[BestMove].EndFile - 1) * Pixels + (Pixels / 2), 11 + (CompLegal[BestMove].EndRank - 1) * Pixels + (Pixels / 2), Pixels / 4);
5393 } else {
5394 Board.Circle(XStart + (BoardSizeX - CompLegal[BestMove].EndFile) * Pixels + (Pixels / 2), 11 + (BoardSizeY - CompLegal[BestMove].EndRank) * Pixels + (Pixels / 2), Pixels / 4);
5396 for(MM = 1; MM <= BoardSizeY; MM++) {
5397 for(GG = 1; GG <= BoardSizeX; GG++) {
5398 Squares[GG][MM] = Comp[GG][MM];
5399 } // Next GG;
5400 } // Next MM;
5401 ResetLegal();
5404 void SwitchCompPlayer ()
5405 { // Menu function.
5406 if(LegalMoves == 0 ) {
5407 if(!strcmp(Computer, "White") ) {
5408 strcpy(Computer, "Black");
5409 Board.MnuWhitePlayer.Enabled = False; Board.MnuBlackPlayer.Enabled = True;
5410 Board.MnuWhitePlayer.Checked = True; Board.MnuBlackPlayer.Checked = False;
5411 Board.MnuWhiteComp.Enabled = True; Board.MnuBlackComp.Enabled = False;
5412 Board.MnuBlackComp.Checked = True; Board.MnuWhiteComp.Checked = False;
5413 strcpy(Board.PieceID.Caption, "Computer plays Black"); Notice = 1;
5414 if(!strcmp(Turn, "Black") ) {
5415 FirstSeeMove = SeeMove;
5416 SeeMove = 1;
5417 CompMain();
5418 SeeMove = FirstSeeMove;
5420 } else {
5421 strcpy(Computer, "White");
5422 Board.MnuWhitePlayer.Enabled = True; Board.MnuBlackPlayer.Enabled = False;
5423 Board.MnuWhitePlayer.Checked = False; Board.MnuBlackPlayer.Checked = True;
5424 Board.MnuWhiteComp.Enabled = False; Board.MnuBlackComp.Enabled = True;
5425 Board.MnuBlackComp.Checked = False; Board.MnuWhiteComp.Checked = True;
5426 strcpy(Board.PieceID.Caption, "Computer plays White"); Notice = 1;
5427 if(!strcmp(Turn, "White") ) {
5428 FirstSeeMove = SeeMove;
5429 SeeMove = 1;
5430 CompMain();
5431 SeeMove = FirstSeeMove;
5437 void Take2 ()
5439 INT V, Location;
5440 if((LegalMoves == 0 || Checked == 2) && LionPiece != I && XA == 0 ) {
5441 if(TurnCount > 0 ) {
5442 GameOver = 0;
5443 TurnCount = TurnCount - 1;
5444 Location = Score[TurnCount].PosEnd;
5445 if(Location > 0 ) {
5446 Rank = Int(Location / (BoardSizeX + 1));
5447 File = Location - (Rank * (BoardSizeX + 1));
5448 Squares[File][Rank] = Score[TurnCount].IDEnd;
5450 Location = Score[TurnCount].PosStart;
5451 if(Location > 0 ) {
5452 InitRank = Int(Location / (BoardSizeX + 1));
5453 InitFile = Location - (InitRank * (BoardSizeX + 1));
5454 Squares[InitFile][InitRank] = Score[TurnCount].IDStart;
5455 if(Squares[InitFile][InitRank] < 0 ) {
5456 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) { WhiteEmpX = InitFile; WhiteEmpY = InitRank; }
5457 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "King") ) { WhiteKingX = InitFile; WhiteKingY = InitRank; }
5459 if(Squares[InitFile][InitRank] > 0 ) {
5460 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) { BlackEmpX = InitFile; BlackEmpY = InitRank; }
5461 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "King") ) { BlackKingX = InitFile; BlackKingY = InitRank; }
5464 if(InitFile != File || InitRank != Rank ) Squares[File][Rank] = 0;
5465 if(Score[TurnCount].IDEnd != 0 ) {
5466 if(Score[TurnCount].PosStart == 0 ) {
5467 CaptPiece = Score[TurnCount].IDEnd;
5468 Squares[File][Rank] = 0;
5469 AddHand3();
5472 for(V = 1; V <= Captures[TurnCount].number; V++) {
5473 Location = Captures[TurnCount].Positions[V];
5474 InitRank = Int(Location / (BoardSizeX + 1));
5475 InitFile = Location - (InitRank * (BoardSizeX + 1));
5476 Squares[InitFile][InitRank] = Captures[TurnCount].PieceNum[V];
5477 } // Next V;
5478 if(Drop == 1 && Captures[TurnCount].number > 0 ) ReduceHand2();
5479 if(!strcmp(Turn, "Black") ) {
5480 strcpy(Turn, "White");
5481 strcpy(Board.NextMove.Caption, "White to Move");
5482 } else {
5483 MoveCount = MoveCount - 1; strcpy(Turn, "Black");
5484 strcpy(Board.NextMove.Caption, "Black to Move");
5486 if(TurnCount == 0 ) {
5487 strcpy(Board.LastMove.Caption, "");
5488 if(HandGame != 1 && !strcmp(Turn, "Black") ) Board.MnuHandicap.Enabled = True;
5489 if(!strcmp(Turn, "Black") ) MoveCount = 0;
5490 } else {
5491 if(Asc(Score[TurnCount].Caption) > 47 && Asc(Score[TurnCount].Caption) < 58 ) {
5492 strcpy(Board.LastMove.Caption, Score[TurnCount].Caption);
5493 } else {
5494 sprintf(Board.LastMove.Caption, "%d. %s", MoveCount, Score[TurnCount].Caption);
5497 Backwards = 1;
5502 void TakeAll ()
5503 { // Menu function.
5504 if(LegalMoves == 0 ) {
5505 while( TurnCount > 0 || (TurnCount > 1 && HandGame != 1) ) {
5506 Take2();
5508 strcpy(Board.Caption, Cap);
5509 RestoreGrafix();
5510 SetKings();
5514 void TakeBack ()
5515 { // Menu function.
5516 INT V, Location;
5517 if((LegalMoves == 0 || Checked == 2) && LionPiece != I && XA == 0 ) {
5518 Notice = 0;
5519 strcpy(Board.PieceID.Caption, "");
5520 if(Tabbing != 1 ) strcpy(Board.Caption, Cap);
5521 BugFix();
5522 if(TurnCount < 1 ) {
5523 Board.PieceID.ForeColor = 0xFFL;
5524 strcpy(Board.PieceID.Caption, "No moves to take back!");
5525 Notice = 1;
5526 } else {
5527 GameOver = 0;
5528 TurnCount = TurnCount - 1;
5529 Location = Score[TurnCount].PosEnd;
5530 if(Location > 0 ) {
5531 Rank = Int(Location / (BoardSizeX + 1));
5532 File = Location - (Rank * (BoardSizeX + 1));
5533 Squares[File][Rank] = Score[TurnCount].IDEnd;
5535 Location = Score[TurnCount].PosStart;
5536 if(Location > 0 ) {
5537 InitRank = Int(Location / (BoardSizeX + 1));
5538 InitFile = Location - (InitRank * (BoardSizeX + 1));
5539 Squares[InitFile][InitRank] = Score[TurnCount].IDStart;
5540 if(Squares[InitFile][InitRank] < 0 ) {
5541 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) { WhiteEmpX = InitFile; WhiteEmpY = InitRank; }
5542 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "King") ) { WhiteKingX = InitFile; WhiteKingY = InitRank; }
5544 if(Squares[InitFile][InitRank] > 0 ) {
5545 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Emperor") ) { BlackEmpX = InitFile; BlackEmpY = InitRank; }
5546 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "King") ) { BlackKingX = InitFile; BlackKingY = InitRank; }
5549 if(InitFile != File || InitRank != Rank ) Squares[File][Rank] = 0;
5550 if(Score[TurnCount].IDEnd == 0 ) {
5551 NewGraf = 0;
5552 while( Board.showpic[NewGraf].Visible == True ) {
5553 NewGraf = NewGraf + 1;
5555 SetGrafix();
5556 } else {
5557 NewGraf = Grafix[File][Rank];
5558 Grafix[File][Rank] = -1;
5559 Board.showpic[NewGraf].Visible = False;
5560 MOVE(1, Board.showpic[NewGraf], 0, 0);
5561 if(Score[TurnCount].PosStart > 0 ) {
5562 SetGrafix();
5563 } else {
5564 CaptPiece = Score[TurnCount].IDEnd;
5565 Squares[File][Rank] = 0;
5566 AddHand();
5569 for(V = 1; V <= Captures[TurnCount].number; V++) {
5570 Location = Captures[TurnCount].Positions[V];
5571 InitRank = Int(Location / (BoardSizeX + 1));
5572 InitFile = Location - (InitRank * (BoardSizeX + 1));
5573 Squares[InitFile][InitRank] = Captures[TurnCount].PieceNum[V];
5574 NewGraf = 0;
5575 while( Board.showpic[NewGraf].Visible == True ) {
5576 NewGraf = NewGraf + 1;
5578 SetGrafix();
5579 } // Next V;
5580 if(Drop == 1 && Captures[TurnCount].number > 0 ) ReduceHand();
5581 if(!strcmp(Turn, "Black") ) {
5582 strcpy(Turn, "White");
5583 strcpy(Board.NextMove.Caption, "White to Move");
5584 } else {
5585 MoveCount = MoveCount - 1; strcpy(Turn, "Black");
5586 strcpy(Board.NextMove.Caption, "Black to Move");
5588 if(TurnCount == 0 ) {
5589 strcpy(Board.LastMove.Caption, "");
5590 if(HandGame != 1 && !strcmp(Turn, "Black") ) Board.MnuHandicap.Enabled = True;
5591 if(!strcmp(Turn, "Black") ) MoveCount = 0;
5592 } else {
5593 if(Asc(Score[TurnCount].Caption) > 47 && Asc(Score[TurnCount].Caption) < 58 ) {
5594 strcpy(Board.LastMove.Caption, Score[TurnCount].Caption);
5595 } else {
5596 sprintf(Board.LastMove.Caption, "%d. %s", MoveCount, Score[TurnCount].Caption);
5599 Backwards = 1;
5600 SetKings();
5601 if(TurnCount > 0 ) {
5602 Location = Score[TurnCount - 1].PosEnd;
5603 if(Location > 0 ) {
5604 Rank = Int(Location / (BoardSizeX + 1));
5605 File = Location - (Rank * (BoardSizeX + 1));
5607 LastPieceX = File; LastPieceY = Rank;
5608 } else {
5609 LastPieceX = -1; LastPieceY = -1;
5611 if(!strcmp(Turn, Computer) && Tabbing != 1 ) {
5612 if(TurnCount > 0 ) {
5613 TakeBack();
5614 } else {
5615 FirstSeeMove = SeeMove;
5616 SeeMove = 1;
5617 CompMain();
5620 if(Tabbing == 1 ) {
5621 if(!strcmp(Computer, "Black") || !strcmp(Computer, "White") ) {
5622 sprintf(Board.Caption, "Move Taken Back (% d of% d ) ; Press [ESC] to continue play.", TurnCount, EndTurn);
5623 } else {
5624 sprintf(Board.Caption, "Move Taken Back (% d of% d )", TurnCount, EndTurn);
5631 void TeachingKing ()
5633 INT X, Y;
5634 for(Y = InitRank - 3; Y <= InitRank + 3; Y++) {
5635 for(X = InitFile - 3; X <= InitFile + 3; X++) {
5636 if(X > 0 && X <= BoardSizeX && Y > 0 && Y <= BoardSizeY ) {
5637 if(Squares[X][Y] == 0 || Sgn(Squares[X][Y]) != Sgn(Squares[InitFile][InitRank]) ) {
5638 if(abs(Y - InitRank) <= 1 && abs(X - InitFile) <= 1 ) {
5639 Board.FillColor = 0x800080;
5640 Legal[X][Y] = 6;
5641 } else {
5642 if(abs(Y - InitRank) == 3 || abs(X - InitFile) == 3 ) {
5643 Board.FillColor = 0xFFFF00;
5644 Legal[X][Y] = 1;
5645 } else {
5646 Board.FillColor = 0xFF0000;
5647 Legal[X][Y] = 2;
5650 if(SeeMove == 1 ) { SeeFile = X; SeeRank = Y; LookMove(); }
5653 } // Next X;
5654 } // Next Y;
5657 void TenjikuScore1 ()
5659 STRING TmpSTR;
5660 INT AB, CD;
5661 CD = strlen(FirstScore);
5662 for(AB = 1; AB <= CD; AB++) {
5663 if(FirstScore[AB-1] == ' ' || FirstScore[AB-1] == 10 || FirstScore[AB-1] == 13 ) {
5664 strcpy(TmpSTR, FirstScore); FirstScore[AB-1] = 0;
5665 strcat(FirstScore, TmpSTR + AB);
5667 } // Next AB;
5670 void TenjikuScore2 ()
5672 STRING TmpSTR;
5673 INT AB, CD;
5674 CD = strlen(SecondScore);
5675 for(AB = 1; AB <= CD; AB++) {
5676 if(SecondScore[AB-1] == ' ' || SecondScore[AB-1] == 10 || SecondScore[AB-1] == 13 ) {
5677 strcpy(TmpSTR, SecondScore); SecondScore[AB-1] = 0;
5678 strcat(SecondScore, TmpSTR + AB);
5680 } // Next AB;
5683 void Territory ()
5685 INT AB, CD;
5686 if((!strcmp(Threat, "On") && Tilde == 0) || (Tilde == 1 && LegalMoves == 0) ) {
5687 if(Tilde == 1 ) {
5688 OldSeeMove = SeeMove;
5689 SeeMove = 1;
5691 if(Tilde != 1 ) GetSquare(); else InitFile = 1;
5692 if(InitFile > 0 ) {
5693 Influence = 2;
5694 for(AB = 1; AB <= BoardSizeY; AB++) {
5695 for(CD = 1; CD <= BoardSizeX; CD++) {
5696 if(Squares[CD][AB] != 0 ) {
5697 InitFile = CD; InitRank = AB;
5698 Validate();
5700 } // Next CD;
5701 } // Next AB;
5702 DisplayTerritory();
5703 Influence = 0;
5705 if(Tilde == 1 ) SeeMove = OldSeeMove;
5710 void TestAhead ()
5712 INT BB, VX, YZ, TU;
5713 // Find Legal Moves;
5715 for(AA = 1; AA <= BoardSizeY; AA++) {
5716 for(BB = 1; BB <= BoardSizeX; BB++) {
5717 Squares[BB][AA] = Comp[BB][AA];
5718 } // Next BB;
5719 } // Next AA;
5720 CompMove = 1; LegalMoves = 0;
5721 for(YZ = 1; YZ <= BoardSizeY; YZ++) {
5722 for(VX = 1; VX <= BoardSizeX; VX++) {
5723 if(!strcmp(Turn, "White") ) {
5724 if(Squares[VX][YZ] < 0 ) {
5725 InitFile = VX; InitRank = YZ;
5726 I = Grafix[VX][YZ];
5727 Validate();
5729 } else {
5730 if(Squares[VX][YZ] > 0 ) {
5731 InitFile = VX; InitRank = YZ;
5732 I = Grafix[VX][YZ];
5733 Validate();
5736 } // Next VX;
5737 DoEvents();
5738 } // Next YZ;
5740 // Find Legal Drops;
5742 if(Drop == 1 ) {
5743 if((!strcmp(Turn, "Black") && Reverse == 0) || (!strcmp(Turn, "White") && Reverse == 1) ) {
5744 for(TU = 1; TU <= Capture; TU++) {
5745 ResetLegal();
5746 if(InHand[TU] > 0 ) {
5747 I = TU; InitFile = 0; InitRank = 0;
5748 HeldValid();
5749 DoEvents();
5751 } // Next TU;
5752 } else {
5753 for(TU = Capture + 1; TU <= Capture * 2; TU++) {
5754 if(InHand[TU] > 0 ) {
5755 ResetLegal();
5756 I = TU; InitFile = 0; InitRank = 0;
5757 HeldValid();
5758 DoEvents();
5760 } // Next TU;
5763 ConsiderMove();
5764 Evaluate = 0; CompMove = 0; Influence = 0; EndMove = 0;
5767 void TestDrop ()
5769 INT DD;
5770 for(DD = 1; DD <= Capture * 2; DD++) {
5771 if(CompLegal[BestMove].StartPiece == CapRef[DD] ) I = DD;
5772 } // Next DD;
5773 Legal[CompLegal[BestMove].EndFile][CompLegal[BestMove].EndRank] = 1;
5776 void TestOther ()
5778 STRING ASTR;
5779 INT Location;
5780 strcpy(ASTR, Pieces[abs(Score[TurnCount].IDStart)].Name);
5781 if(strcmp(ASTR, "Pawn") && strcmp(ASTR, "Sparrow") && strcmp(ASTR, "Sparrow Pawn") && strcmp(ASTR, "Swallow") && strcmp(ASTR, "Dolphin") ) {
5782 OriginalRank = Rank; OriginalFile = File;
5783 OldSeeMove = SeeMove; SeeMove = 0;
5784 OriginalPiece = Squares[File][Rank]; Squares[File][Rank] = 0;
5785 Location = Score[TurnCount].PosStart;
5786 InitRank = Int(Location / (BoardSizeX + 1));
5787 InitFile = Location - (InitRank * (BoardSizeX + 1));
5788 Squares[InitFile][InitRank] = Score[TurnCount].IDStart;
5789 InitFile = FirstFile; InitRank = FirstRank;
5790 Validate();
5791 Rank = OriginalRank; File = OriginalFile;
5792 Location = Score[TurnCount].PosStart;
5793 InitRank = Int(Location / (BoardSizeX + 1));
5794 InitFile = Location - (InitRank * (BoardSizeX + 1));
5795 Squares[InitFile][InitRank] = 0; Squares[File][Rank] = OriginalPiece;
5796 SeeMove = OldSeeMove;
5797 if(Legal[File][Rank] > 0 ) Testing123 = 1; else Testing123 = 0;
5801 void TestStrength ()
5803 Weaker = 0;
5804 if(Pieces[abs(Squares[NewFile][NewRank])].special == 'G' || Pieces[abs(Squares[NewFile][NewRank])].special == 'C' ) {
5805 if(Pieces[abs(Squares[InitFile][InitRank])].Value <= Pieces[abs(Squares[NewFile][NewRank])].Value || !strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Rook General") ) {
5806 Weaker = 1;
5811 void Tetrarchs ()
5813 if(InitFile < BoardSizeX ) {
5814 if(FileInc == 1 && RankInc == 0 && M == 3 && Legal[InitFile + 1][InitRank] == 4 ) Blocked = 1;
5816 if(InitFile > 1 ) {
5817 if(FileInc == -1 && RankInc == 0 && M == 3 && Legal[InitFile - 1][InitRank] == 4 ) Blocked = 1;
5821 void TextScore ()
5822 { // Menu function.
5823 INT K, W;
5824 FILE *f3;
5825 // TODO: On Error Resume Next;
5826 strcpy(Board.CMDiagram.DialogTitle, "Create Text Score");
5827 Board.CMDiagram.Flags = 0x400L | 0x800L | 0x4L;
5828 Board.CMDiagram.Action = 2;
5829 if(Err == 32755 ) return; // TODO
5830 strcpy(SavedSTR, Board.CMDiagram.Filename);
5832 f3 = fopen(SavedSTR, "w");
5833 if(strcmp(GameName, "") ) {
5834 fprintf(f3, "%s Shogi", GameName);
5835 for(I = 1; I <= strlen(GameName) + 6; I++) {
5836 fprintf(f3, "=");
5837 } // Next I;
5838 fprintf(f3, "\n");
5840 fprintf(f3, "%s\n", SaveTitleSTR);
5841 K = 0;
5842 for(W = 1; W <= TurnCount; W += 2) {
5843 K = K + 1;
5844 strcpy(FirstScore, Score[W].Caption);
5845 strcpy(SecondScore, Score[W + 1].Caption);
5846 strcpy(Board.Caption, strstr(FirstScore, " "));
5847 if(strchr(FirstScore, '\n') ) TenjikuScore1(); // FIXME: is this OK?
5848 if(strchr(SecondScore, '\n') ) TenjikuScore2();
5849 if(HandGame == 1 && W == 1 ) {
5850 fprintf(f3, "1. - %s ", SecondScore);
5851 } else {
5852 fprintf(f3, "%d.%s %s ", K, FirstScore, SecondScore);
5854 } // Next W;
5855 fclose(f3);
5856 sprintf(Board.Caption, "Score text file %s created.", Board.CMDiagram.Filename); Notice = 1;
5859 void TooSmall ()
5861 int Response; // write-only?
5862 Response = MsgBox("A screen size of at least 800x600 is required to play this variant. You should use Windows 'Setup' to change your screen size before attempting to play Tai Shogi.", 0, "Tai Shogi (Grand Shogi)");
5863 Start.Game[10].Enabled = False;
5864 Start.Game[10].Value = False;
5865 Start.Game[0].Value = True;
5866 Start.MousePointer = 0;
5869 void TwoKings ()
5871 INT K, L;
5872 int Response; // write-only?
5873 for(K = Rank - 1; K <= Rank + 1; K++) {
5874 for(L = File - 1; L <= File + 1; L++) {
5875 if(L > 0 && L <= BoardSizeX && K > 0 && K <= BoardSizeY ) {
5876 if((K != Rank || L != File) ) {
5877 if(abs(Squares[L][K]) == 1 ) {
5878 if(Squares[L][K] == 1 ) strcpy(Turn2, "White"); else strcpy(Turn2, "Black");
5879 Response = MsgBox((sprintf(StringTmp, "You can't leave your %s in Check! ", Pieces[abs(Squares[File][Rank])].Name), StringTmp), 0, Turn2);
5880 Checked = 2;
5884 } // Next L;
5885 } // Next K;
5888 void UnPromote ()
5889 { // DblClick handler on piece. I is piece number
5890 INT K, L, Location, DoubleProm;
5891 if(strcmp(Computer, Turn) && strcmp(Computer, "Both") ) {
5892 DoubleProm = 0;
5893 if(AutoPromote == 1 && ForceProm != 1 ) {
5894 if((Score[TurnCount - 1].IDStart != Score[TurnCount - 1].IDEnd) && (Score[TurnCount - 1].IDEnd != 0) ) {
5895 for(K = 1; K <= BoardSizeY; K++) {
5896 for(L = 1; L <= BoardSizeX; L++) {
5897 if(Grafix[L][K] == I ) {
5898 Location = Score[TurnCount - 1].PosEnd;
5899 Rank = Int(Location / (BoardSizeX + 1));
5900 File = Location - (Rank * (BoardSizeX + 1));
5901 if(L == File && K == Rank ) {
5902 DoubleProm = 1;
5903 Squares[L][K] = Score[TurnCount - 1].IDStart;
5904 Score[TurnCount - 1].IDEnd = Score[TurnCount - 1].IDStart;
5905 Graphnum = Pieces[abs(Squares[L][K])].Graphic;
5906 if((Squares[L][K] < 0 && Reverse == 0) || (Squares[L][K] > 0 && Reverse == 1) ) Graphnum = Graphnum + (TotGraph / 2);
5907 /* [HGM] all from file. if(!strcmp(Choice, "Tai") ) Board.showpic[I] = TaiPieces.Pix[Graphnum - 1]; else */ Board.showpic[I] = Board.Pix[Graphnum - 1];
5908 Score[TurnCount].Caption[strlen(Score[TurnCount].Caption) - 1] = '=';
5909 strcpy(ShortScore[TurnCount], Score[TurnCount].Caption);
5910 sprintf(Board.LastMove.Caption, "%d. %s", MoveCount, ShortScore[TurnCount]);
5913 } // Next L;
5914 } // Next K;
5917 if(DoubleProm == 0 ) LionIgui();
5921 void Validate ()
5923 char SpecPowerCHR;
5924 if(Squares[InitFile][InitRank] != 0 ) {
5925 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Dolphin") ) DolphinMove();
5926 SpecPowerCHR = Pieces[abs(Squares[InitFile][InitRank])].special;
5927 if(SpecPowerCHR == 'F' ) Demon = 1; else Demon = 0;
5928 if(SpecPowerCHR != '0' && SpecPowerCHR != 'L' ) SpecialMove();
5929 if(SpecPowerCHR != 'L' && D != 0 && LionPiece == I && strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Teaching King") ) {
5930 LionPower2();
5931 } else {
5932 if(LionPiece != I ) {
5933 for(N = 1; N <= 8; N++) {
5934 switch(N) {
5935 case 1: FileInc = 0; RankInc = -1; break;
5936 case 2: FileInc = 0; RankInc = 1; break;
5937 case 3: FileInc = -1; RankInc = 0; break;
5938 case 4: FileInc = 1; RankInc = 0; break;
5939 case 5: FileInc = -1; RankInc = -1; break;
5940 case 6: FileInc = 1; RankInc = -1; break;
5941 case 7: FileInc = -1; RankInc = 1; break;
5942 case 8: FileInc = 1; RankInc = 1; break;
5944 if(Squares[InitFile][InitRank] < 0 ) {
5945 FileInc = 0 - FileInc;
5946 RankInc = 0 - RankInc;
5948 MoveData = Pieces[abs(Squares[InitFile][InitRank])].Moves[N];
5949 MoveTest = ((MoveData / 128.) - Int(MoveData / 128)) * 128;
5950 if(MoveTest > 0 ) SingleStep();
5951 MoveTest = ((MoveData / 256.) - Int(MoveData / 256)) * 256;
5952 if(MoveTest >= 128 ) Jumping();
5953 MoveTest = ((MoveData / 512.) - Int(MoveData / 512)) * 512;
5954 if(MoveTest >= 256 ) RangeJump();
5955 MoveTest = ((MoveData / 1024.) - Int(MoveData / 1024)) * 1024;
5956 if(MoveTest >= 512 ) LionPower();
5957 MoveTest = ((MoveData / 2048.) - Int(MoveData / 2048)) * 2048;
5958 if(MoveTest >= 1024 ) KnightJump();
5959 if(MoveData >= 2048 ) {
5960 Hook = 1;
5961 MoveTest = 64;
5962 SingleStep();
5964 } // Next N;
5967 if(GameOver == 1 || Checked > 0 ) return;
5968 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Dolphin") ) {
5969 Pieces[abs(Squares[InitFile][InitRank])].Moves[7] = 0;
5970 Pieces[abs(Squares[InitFile][InitRank])].Moves[8] = 0;
5972 if(SpecPowerCHR == 'L' ) SpecialMove();
5973 if(!strcmp(Pieces[abs(Squares[InitFile][InitRank])].Name, "Teaching King") && TeachVer == 2 ) {
5974 if(LionPiece == I ) Lion(); else TeachingKing();
5979 void WaDrop ()
5981 int Response;
5982 Response = MsgBox("Play Game with Drops?", 36, "Wa Shogi");
5983 if(Response == 6 ) {
5984 Drop = 1;
5985 strcpy(Boardbmp, "Waboard2.bmp");