TweetFollow Us on Twitter

Aug 95 Challenge
Volume Number:11
Issue Number:8
Column Tag:Programmer’s Challenge

Programmer’s Challenge

By Bob Boonstra, Westford, Massachusetts

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Diff-Warrior

Authors frequently use a software tool to compare different versions of the same document and identify what changes have been made between versions. Something like the well-known diff utility for programmers, but operating on a words instead of a lines. This month your Challenge is to write a simplified version of such a file comparison tool.

The prototype of the code you should write is:

#define ulong unsigned long

typedef enum { 
/* describes type of text change between old and new versions of text */
  deletedText=0, insertedText, movedText } DiffType;

typedef struct {
DiffType type;
/* The meaning of the remaining fields depends on type.
    For type == deletedText:
    rangeStart -   offset in oldText of first char deleted
    rangeEnd -     offset in oldText of last char deleted
    position -  offset in newText before which text would be inserted to convert 
    newText into oldText
    For type == insertedText:
    rangeStart -   offset in newText of first char inserted
    rangeEnd -     offset in newText of last char inserted
    position -  offset in oldText before which text would be inserted to convert 
    oldText into newText
    For type == movedText:
    rangeStart-    offset in oldText of first char moved
    rangeEnd-      offset in oldText of last char moved
     position-  offset in oldText before which text would be inserted to convert 
    oldText into newText
*/
ulong rangeStart; 
ulong rangeEnd;
ulong position; 
} DiffRec;

short /* numDiffsFound */ FindWordDifferences (
char *oldText,     /* pointer to old version of text */
char *newText,     /* pointer to new version of text */
ulong numOldChars, /* number of characters in oldText */
ulong numNewChars, /* number of characters in newText */
DiffRec diffs[],   /* pointer to preallocated array where text differences are to 
  be stored */
ulong maxDiffRecs  /* number of DiffRecs preallocated */
);

FindWordDifferences should store a DiffRec in the diffs array for each sequence of words that were deleted or moved from oldText, and for each sequence inserted into newText. So, for example, if newText and oldText contained the following characters

oldText->The quick brown fox jumps over the lazy dog.
newText->The brown and white lazy fawn jumps over the dog.

you would return the value 5 and store the following into the diffs array:

diffs[0]={deletedText,  4, 9, 4}  (deleted "quick ")
diffs[1]={insertedText,10,19,16}  (inserted "and white ")
diffs[2]={movedText,   35,39,16}  (moved "lazy ")
diffs[3]={deletedText, 16,18,25}  (deleted "fox")
diffs[4]={insertedText,25,28,16}  (inserted "fawn")

The solution to this problem is clearly not unique. For example, each problem has a trivial solution where all of the oldText is deleted, and all of the newText is inserted. To encourage nontrivial and optimal solutions, selection of the winner will be based on the quality of the FindWordDifferences job you do, as well as how quickly you find a solution. Quality will be measured first by the number of characters deleted, inserted, and moved (the sum of the (rangeEnd-rangeStart+1) values in your DiffRec array), and next on the number of differences found (numDiffsFound), with smaller being better in both cases. The fastest solution within 10% of the best quality score (both parameters) will be declared the winner. These criteria place a premium on finding movedText (as opposed to deletedText / insertedText pairs) and on finding larger contiguous sections of inserted / deleted text (as opposed to sequences of smaller changes).

Now for the fine print. Notice that the comparison is based on words, not just on characters (look at “fox” and “fawn” above), so be careful when calculating offsets. Words are delimited by white space (spaces, CR, NL, tabs), or punctuation. Extra/missing white space and/or punctuation should also result in a DiffRec. Your solution should be case sensitive (i.e., “The” is different from “the”). You may not change the input text pointed to by newText and oldText. The DiffRec offsets calculated by your program should apply to the unchanged input oldText and newText (i.e., they should be independent of changes implied by any other DiffRecs). Correctness will be determined by using the DiffRecs you produce to convert the oldText into the newText, and vice versa (ignoring CRs and NLs). In doing the conversions, the DiffRecs will be applied in order of decreasing position / rangeStart value, and (in case of duplicates) in reverse order of the DiffRec array. Testing will use text files averaging 5-20K characters in size, and at least one test case will exceed 64K.

Thanks to the generosity of Metrowerks, who provided a copy of CodeWarrior for use in the Challenge, and in response to requests from several readers, this Challenge will be scored using the CodeWarrior compiler. The target instruction set is the 680x0 family; I’ll be testing on a 68040. (We’ll have a PowerPC Challenge in a couple of months.)

Finally, I want to express the gratitude that all Challenge participants feel toward Mike Scanlin for his excellent work writing this column. I am honored to have the opportunity to take over and hope to maintain the high standard Mike set. If any of you have suggestions on how to make the column and the Challenge even better, please send them to me at one of the Programmer’s Challenge e-mail addresses, or directly to boonstra@ultranet.com.

Two Months Ago Winner

Apparently there are at least a few chess players among MacTech Challenge readers. Of the six entries I received for the Check Checkmate Challenge, four worked correctly. Congratulations to Gary Beith (Largo, FL) for his efficient and instructive solution. Gary’s win is especially notable because this is his first entry in the Programmer’s Challenge.

Here are the times and code sizes for the entries that worked correctly. Numbers in parens after a person’s name indicate that person’s cumulative point total for all previous Challenges, not including this one:

Name time code

Gary Beith 188 4282

Ernst Munter (60) 260 19810

Xan Gregg (24) 639 4242

David Rees 2919 2604

Gary’s solution demonstrates several features associated with efficient solutions. He employs an appropriate representation of the problem data, including a chessboard representation that includes a border area, allowing efficient computation of chess moves with a minimum of special code for board boundaries. Gary takes maximal advantage of the untimed initialization routine, setting up move tables for each type of chesspiece. The problem statement provides opportunities for optimization; in this case, the problem is a legal chess position, and Gary uses that to determine whether a move places the opponent’s king in check. He applies knowledge of the problem domain to limit the number of possibilities his code examines, for example, by identifying which pieces are pinned and which axes of movement need not be considered, and in constraining the possible moves for the case of a king in check. Gary’s solution is not only an excellent one for the specific problem posed, but offers an instructive approach to Challenges in general. Nice job!

Top 20 Contestants of All Time

Here are the Top 20 Contestants for the 36 Programmer’s Challenges to date. The numbers below include points awarded for this month’s entrants. (Note: ties are listed alphabetically by last name - there are 25 people listed this month because 6 people have 20 points each.)

1. [Name deleted] 176

2. Karsh, Bill 71

3. Munter, Ernst 70

4. Stenger, Allen 65

5. Larsson, Gustav 60

6. Riha, Stepan 51

7. Goebel, James 49

8. Nepsund, Ronald 47

9. Cutts, Kevin 46

10. Mallett, Jeff 44

11. Kasparian, Raffi 42

12. Vineyard, Jeremy 40

13. Darrah, Dave 31

14. Gregg, Xan 31

15. Landry, Larry 29

16. Elwertowski, Tom 24

17. Lee, Johnny 22

18. Noll, Robert 22

19. Anderson, Troy 20

20. Beith, Gary 20

21. Burgoyne, Nick 20

22. Galway, Will 20

23. Israelson, Steve 20

24. Landweber, Greg 20

25. Pinkerton, Tom 20

There are three ways to earn points: (1) scoring in the top 5 of any Challenge, (2) being the first person to find a bug in a published winning solution or, (3) being the first person to suggest a Challenge that I use. The points you can win are:

1st place 20 points

2nd place 10 points

3rd place 7 points

4th place 4 points

5th place 2 points

finding bug 2 points

suggesting Challenge 2 points

Here is Gary’s winning solution:


ChessMoveEnumerator.c

Copyright ©1995 Gary Beith

/* =========================================================
Objective: To determine all legal moves (excluding castling and en passant captures) available for a given 
chess position.  It is NOT required to single out intelligent moves!
========================================================= */

/* ---------------------------------------------------------
    Items required by the problem statement
--------------------------------------------------------- */

#pragma options ( mc68020, !mc68881, require_protos )
#pragma options ( pack_enums, align_arrays )

typedef enum { rowA = 0, rowB, rowC, rowD, rowE, rowF, rowG, 
    rowH } Row;
typedef enum { col1 = 0, col2, col3, col4, col5, col6, col7,
    col8 } Col;
typedef enum { whiteSide = 0, blackSide } Side;
typedef enum { king = 0, queen, rook, bishop, knight, pawn }
    ChessPiece;

typedef struct Square {
 Row    row;
 Col    col;
} Square;

typedef struct PiecePosition {
 Square sq;
 Side   side;
 ChessPiece piece;
} PiecePosition;

typedef struct ChessMove {
 Square fromSq;
 Square toSq;
 BooleanmoveIsCapture;
 BooleanopponentPlacedInCheck;
} ChessMove;

short /* numberOfMoves */ LegalChessMoves(
 PiecePosition piecePositionArray[],
 short  numberOfPieces,
 Side   sideToMove,
 ChessMovelegalMoveArray[],
 void   *privateDataPtr
);

void InitChess(void *privateDataPtr);


/* =========================================================
    From here on, I’m on my own :-)
========================================================= */

#define kMaxChessPiece    pawn

typedef Square *SquarePtr;
typedef PiecePosition *PiecePosPtr;
typedef ChessMove *ChessMovePtr;

typedef enum {
 stmPawnSq0 = 0, stmPawnSq1, stmPieceSq0, stmPieceSq1,
 offBoardSq0, offBoardSq1, emptySq0, emptySq1,
 oppPieceSq0, oppPieceSq1, oppPawnSq0, oppPawnSq1
} MySquare, *MySquarePtr;

/* 
The attack flag is used to denote squares near the King known to be under attack, thus preventing the King 
from moving to them.  State “0” for each square type represents attack flag not set, state “1” represents 
flag set.  The attack mask is used to clear the flag when testing for empty squares.
 */
#define kAttackFlag0x01
#define kAttackMask0x0e

typedef char MySquareIncr, *MySqIncrPtr;
typedef unsigned char MyAxis, *MyAxisPtr;
typedef short MySquareDiff, *MySqDiffPtr;

typedef struct {
 MySqIncrPtrsqIncrArrayPtr;
 MyAxisPtraxisArrayPtr;
 short  numberOfAxes;
} MyPieceTable;

typedef struct {
 MySquarePtrsqPtr;
 MyPieceTable    pcTable;
 Square fromSq;
 MyAxis discAxis, pinAxis;
} MyPiece, *MyPiecePtr, **MyPieceHandle;

typedef struct {
 MyPieceHandle   pcHandle;
 MyPieceTable    pcTable;
 MySquare sqType;
} MyPieceInfo, *MyPcInfoPtr;

/* 
    My internal square numbering scheme:
  ** Opponent **
 [175] -   -   - .... -   - [185]
   -   -   -   - .... -   -   -   -   -   -   - [174]
   -   - (145) - .... - (152) -   -   -   -   -   -
  < six more rows here >
   -   - ( 33) - .... - ( 40) -   -   -   -   -   -
 [ 15] -   -   - .... -   -   -   -   -   -   -   -
     [  0] -   - .... -   -   -   -   -   -   - [ 14]
  ** Side to move **

Numbers in parentheses indicate corners of the actual chess board.  Some reasons for choosing this scheme:
1.A border of at least two off-board squares is provided around the board to facilitate the determination of 
valid Knight moves.
2.Adjacent squares in a column have an absolute index difference of 16 (efficient power of 2).  A difference 
of at least 15 was required so that index values for squares in the same row would always differ by less than 
those for squares in different rows.
3.The perspective of the side to move is used rather than that of either White or Black exclusively.  This 
enables the identical move enumeration algorithm to be used for either side - differences such as pawn movement 
direction are accounted for when converting from and to the problem statement’s board format.
*/
#define kLowerLeftSqIndex 33
#define kMin4thRankSqIndex81
#define kMin5thRankSqIndex97
#define kMin8thRankSqIndex145
#define kUpperRightSqIndex152
#define kMaxSqIndex185

/* Maximum square index differential on the board = kUpperRightSqIndex - kLowerLeftSqIndex */
#define kMaxSqDiff 119

/* 
For purposes of this program, “long move” pieces are defined as consisting of Queens, Rooks, and Bishops. 
 These pieces may move as many unobstructed spaces in each of their permitted directions as are available 
on the board.  The maximum counts given for long move pieces and Knights allow for the potential for all 
eight Pawns to romote to such pieces.
*/
#define kMaxLongMovePieces13
#define kMaxKnights10
#define kMaxPawns8
 
typedef struct {
 MyPiecePtr endSTMKingPtr, endOppKingPtr,
 endSTMLMPiecePtr, endOppLMPiecePtr,
 endSTMKnightPtr, endOppKnightPtr,
 endSTMPawnPtr;
 MySquare sqArray[kMaxSqIndex + 1];
} MyChessBoard;

typedef struct {
 MyChessBoard  chessBoard, emptyBoard;
 MyPiecestmKing, oppKing,
 stmLMPieceArray[kMaxLongMovePieces],
 oppLMPieceArray[kMaxLongMovePieces],
 stmKnightArray[kMaxKnights],
 oppKnightArray[kMaxKnights],
 stmPawnArray[kMaxPawns];
 MyPiecePtr pcPtrArray[kMaxSqIndex + 1];
 Square whiteSqArray[kMaxSqIndex + 1],
 blackSqArray[kMaxSqIndex + 1];
 SquarePtrstmSqArrayPtr;
 MyPieceInfostmPcInfoArray[kMaxChessPiece + 1],
 oppPcInfoArray[kMaxChessPiece + 1];
 MySquareIncr  queenSqIncrArray[2 * kMaxSqDiff + 1],
 rookSqIncrArray[2 * kMaxSqDiff + 1],
 bishopSqIncrArray[2 * kMaxSqDiff + 1];
 BooleanknightMoveArray[2 * kMaxSqDiff + 1];
 MyAxis queenAxisArray[4], rookAxisArray[2],
 bishopAxisArray[2];
 MySquareDiff  knightSqDiffArray[8],
 kingSqDiffArray[8];
} MyData, *MyDataPtr;

Local function prototypes

void SetUpMyChessBoard(MyDataPtr dataPtr,
  PiecePosition piecePositionArray[],
  short numberOfPieces,
  Side sideToMove);

short FindChecksAndPins(MyDataPtr dataPtr,
 MySquarePtr *checkSqHandle,
 MySquareIncr *checkSqIncrPtr);

void EnumerateNonKingMoves(MyDataPtr dataPtr,
 ChessMovePtr *moveHandle);

void EnumerateNonKingCapturesOfCheckingPiece(      
 MyDataPtr dataPtr,
 MySquarePtr checkSqPtr,
 ChessMovePtr *moveHandle);

void EnumerateInterpositionMoves(MyDataPtr dataPtr,
 MySquarePtr checkSqPtr,
   MySquareIncr checkSqIncr,
   ChessMovePtr *moveHandle);

void EnumerateKingMoves(MyDataPtr dataPtr,
 ChessMovePtr *moveHandle);


LegalChessMoves

/* =========================================================
    Timed legal move enumeration routine
========================================================= */

short LegalChessMoves(PiecePosition piecePositionArray[],
 short numberOfPieces,
 Side sideToMove,
 ChessMove legalMoveArray[],
 void *privateDataPtr)
{
 MyDataPtrdataPtr = privateDataPtr;
 short  numberOfChecks;
 MySquarePtrcheckSqPtr;
 MySquareIncr    checkSqIncr;
 ChessMovePtr    movePtr = legalMoveArray;

 SetUpMyChessBoard(dataPtr, piecePositionArray,
 numberOfPieces, sideToMove);

 numberOfChecks = FindChecksAndPins(dataPtr, &checkSqPtr,
  &checkSqIncr);


 if (numberOfChecks == 0)
 {
 EnumerateNonKingMoves(dataPtr, &movePtr);
 }
 else if (numberOfChecks == 1)
 {
 EnumerateNonKingCapturesOfCheckingPiece(dataPtr,              
 checkSqPtr,
 &movePtr);
 if (checkSqIncr)
 {
 EnumerateInterpositionMoves(dataPtr, checkSqPtr,
 checkSqIncr, &movePtr);
 }
 }
    /* else if (numberOfChecks == 2)
     Only King moves are possible (if any exist). */

 EnumerateKingMoves(dataPtr, &movePtr);

 return (movePtr - legalMoveArray); /* Number of moves */
}


SetUpMyChessBoard

void SetUpMyChessBoard(MyDataPtr dataPtr,
  PiecePosition piecePositionArray[],
  short numberOfPieces,
  Side sideToMove)
{
 PiecePosPtrposPtr, endPosPtr;
 short  sqIndex;
 MyPcInfoPtrpcInfoPtr;
 MySquarePtrsqPtr;
 MyPiecePtr pcPtr;

 dataPtr->chessBoard = dataPtr->emptyBoard;

 posPtr = piecePositionArray;
 endPosPtr = posPtr + numberOfPieces;


 if (sideToMove) /* == blackSide */
 {
 dataPtr->stmSqArrayPtr = dataPtr->blackSqArray;
 do
 {
 sqIndex = kUpperRightSqIndex -
 ((posPtr->sq.row << 4) + posPtr->sq.col);

 pcInfoPtr = (posPtr->side) ?
 dataPtr->stmPcInfoArray + posPtr->piece :
 dataPtr->oppPcInfoArray + posPtr->piece;

 sqPtr  = dataPtr->chessBoard.sqArray + sqIndex;
 if ((*sqPtr = pcInfoPtr->sqType) != oppPawnSq0)
 {
 dataPtr->pcPtrArray[sqIndex] =
 pcPtr = (*pcInfoPtr->pcHandle)++;

 pcPtr->sqPtr = sqPtr;
 pcPtr->pcTable = pcInfoPtr->pcTable;
 pcPtr->fromSq = posPtr->sq;
 pcPtr->discAxis = pcPtr->pinAxis = 0;
 }
 }
 while (++posPtr != endPosPtr);
 }
 else
 {
 dataPtr->stmSqArrayPtr = dataPtr->whiteSqArray;
 do
 {
 sqIndex = kLowerLeftSqIndex +
 ((posPtr->sq.row << 4) + posPtr->sq.col);

 pcInfoPtr = (posPtr->side) ?
 dataPtr->oppPcInfoArray + posPtr->piece :
 dataPtr->stmPcInfoArray + posPtr->piece;

 sqPtr  = dataPtr->chessBoard.sqArray + sqIndex;
 if ((*sqPtr = pcInfoPtr->sqType) != oppPawnSq0)
 {
 dataPtr->pcPtrArray[sqIndex] =
 pcPtr = (*pcInfoPtr->pcHandle)++;

 pcPtr->sqPtr = sqPtr;
 pcPtr->pcTable = pcInfoPtr->pcTable;
 pcPtr->fromSq = posPtr->sq;
 pcPtr->discAxis = pcPtr->pinAxis = 0;
 }
 }
 while (++posPtr != endPosPtr);
 }
}


FindChecksAndPins

short FindChecksAndPins(MyDataPtr dataPtr,
 MySquarePtr *checkSqHandle,
 MySquareIncr *checkSqIncrPtr)
{
 MySquarePtrkingSqPtr, sqPtr;
 MyPiecePtr endPcPtr, pcPtr;
 short  sqIncr, stmPcSqIndex, numberOfChecks = 0;

/* 
Since I must report all moves which place the opponent in check, I first scan for possible discovered checks. 
 These occur when only one piece (which must belong to the side to move) stands between one of the mover’s 
long move pieces and the enemy King, and that piece is moved off of the line of attack.  Because I am only 
required to analyze legal positions, I know that at least one piece will exist on any such line of attack.
*/
 kingSqPtr = dataPtr->oppKing.sqPtr;

 endPcPtr = dataPtr->chessBoard.endSTMLMPiecePtr;
 for (pcPtr = dataPtr->stmLMPieceArray;
  pcPtr < endPcPtr; pcPtr++)
 {
 sqPtr = pcPtr->sqPtr;
 sqIncr = pcPtr->pcTable.sqIncrArrayPtr
  [kingSqPtr - sqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 continue;/* King not “in line” with this piece */

 sqPtr += sqIncr;
 stmPcSqIndex = 0;
 while (*sqPtr <= emptySq1) /* Not opponent’s piece */
 {
 if (*sqPtr < emptySq0)   /* Is mover’s piece */
 {
 if (stmPcSqIndex)
 break; /* More than one piece in its path */

 stmPcSqIndex = sqPtr - dataPtr->chessBoard.sqArray;
 }

 if ((sqPtr += sqIncr) == kingSqPtr)
 {
    /* Record line of attack for future reference */
 dataPtr->pcPtrArray[stmPcSqIndex]->discAxis =
 (sqIncr < 0) ? -sqIncr : +sqIncr;
 break;
 }
 }
 }

/* 
A similar analysis determines if any pieces are“pinned," i.e., they stand in the way of an attack on the mover’s 
King by an enemy piece.  A pinned piece can move only along the line of attack (if such a move is permitted 
for the piece; in particular, a pinned Knight is never able to move).
*/
 kingSqPtr = dataPtr->stmKing.sqPtr;

 endPcPtr = dataPtr->chessBoard.endOppLMPiecePtr;
 for (pcPtr = dataPtr->oppLMPieceArray;
  pcPtr < endPcPtr; pcPtr++)
 {
 sqPtr = pcPtr->sqPtr;
 sqIncr = pcPtr->pcTable.sqIncrArrayPtr
  [kingSqPtr - sqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 continue;

 if ((sqPtr += sqIncr) == kingSqPtr)
 {
/* 
Piece is adjacent to King.  The King may capture it if it is not protected by another piece.  However, no interposition 
moves are possible.
*/
 sqPtr[+sqIncr] |= kAttackFlag;
 *checkSqHandle = pcPtr->sqPtr;
 *checkSqIncrPtr = 0;
 numberOfChecks++;
 continue;
 }

 stmPcSqIndex = 0;
 while (*sqPtr <= emptySq1)
 {
 if (*sqPtr < emptySq0)
 {
 if (stmPcSqIndex)
 break;

 stmPcSqIndex = sqPtr - dataPtr->chessBoard.sqArray;
 }

 if ((sqPtr += sqIncr) == kingSqPtr)
 {
 if (stmPcSqIndex) /* Pinned piece was found */
 {
 dataPtr->pcPtrArray[stmPcSqIndex]->pinAxis =
 (sqIncr < 0) ? -sqIncr : +sqIncr;
 }
 else
 {
/* 
King is in check “from a distance.”  If the King moves, it must leave the line of attack, which is recorded so 
that interposition moves can be determined later on.
*/
 sqPtr[+sqIncr] |= kAttackFlag;
 sqPtr[-sqIncr] |= kAttackFlag;
 *checkSqHandle = pcPtr->sqPtr;
 *checkSqIncrPtr = sqIncr;
 numberOfChecks++;
 }

 break;
 }
 }
 }

/* 
The maximum number of checks possible is two, only one of which can come from a Pawn or Knight.
*/
 if (numberOfChecks < 2)
 {
/* 
Per ANSI standard, a sequence point occurs after the evaluation of each operand of the Logical Or and Logical 
And operators.  Therefore, I can validly rely on the value of sqPtr being set in exactly the order specified 
in the next expression (and others like it). That is not generally true of most other operators.
*/
 if ((*(sqPtr = kingSqPtr + 15) >= oppPawnSq0) ||
 (*(sqPtr += 2) >= oppPawnSq0))
 {
 *checkSqHandle = sqPtr;
 *checkSqIncrPtr = 0;
 numberOfChecks++;
 }
 else
 {
 endPcPtr = dataPtr->chessBoard.endOppKnightPtr;
 for (pcPtr = dataPtr->oppKnightArray;
  pcPtr < endPcPtr; pcPtr++)
 {
 sqPtr = pcPtr->sqPtr;
 if (dataPtr->knightMoveArray
 [kingSqPtr - sqPtr + kMaxSqDiff])
 {
 *checkSqHandle = sqPtr;
 *checkSqIncrPtr = 0;
 numberOfChecks++;
 break;
 }
 }
 }
 }

 return numberOfChecks;
}


EnumerateNonKingMoves

void EnumerateNonKingMoves(MyDataPtr dataPtr,
  ChessMovePtr *moveHandle)
{
 MySquarePtroppKingSqPtr, toSqPtr, sqPtr;
 MyPiecePtr endPcPtr, pcPtr;
 MyAxisPtraxisPtr, endAxisPtr;
 short  toSqIncr, sqIncr, toSqIndex;
 ChessMovePtr    movePtr = *moveHandle;
 MySqDiffPtrsqDiffPtr, endSqDiffPtr;

 oppKingSqPtr = dataPtr->oppKing.sqPtr;

 endPcPtr = dataPtr->chessBoard.endSTMLMPiecePtr;
 for (pcPtr = dataPtr->stmLMPieceArray;
  pcPtr < endPcPtr; pcPtr++)
 {
/* 
The move table for long move pieces consists of a set of axes of movement for the particular type of piece 
(i.e., Queen, Rook, or Bishop).  The positive and negative values of each axis are used as square increments, 
beginning at the piece’s current square pointer, and continuing until further movement is blocked by another 
piece or by the end ofthe board. In the event the blockage is caused by an oppenent’s piece, one additional 
move results; that of capturing the piece by moving onto its square.
*/
 axisPtr = pcPtr->pcTable.axisArrayPtr;
 endAxisPtr = axisPtr + pcPtr->pcTable.numberOfAxes;
 do
 {
 if (pcPtr->pinAxis && (pcPtr->pinAxis != *axisPtr))
 continue; /* Piece is pinned on some other axis */

 toSqIncr = *axisPtr;
 do
 {
 toSqPtr = pcPtr->sqPtr;
 do
 {
 if (*(toSqPtr += toSqIncr) < emptySq0)
 break; /* Square off-board or holds own piece */

 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq =
 dataPtr->stmSqArrayPtr
 [toSqPtr - dataPtr->chessBoard.sqArray];
 movePtr->moveIsCapture = (*toSqPtr > emptySq1);

/* 
If a long move piece has a discovered check axis, it is not able to move along that axis.  Otherwise, it would 
be checking the enemy King, and the position would not be legal with this side to move.  Therefore, any move 
of such a piece will result in a discovered check.
*/
 if (pcPtr->discAxis)
 {
 (movePtr++)->opponentPlacedInCheck = true;
 continue;
 }

 sqIncr = pcPtr->pcTable.sqIncrArrayPtr
  [oppKingSqPtr - toSqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 {
 (movePtr++)->opponentPlacedInCheck = false;
 continue;
 }

/* 
Scan along the path to the enemy King from the target square for this move.  If the first occupied square 
is that of the King, a check will result from the move; otherwise, no check.
*/
 sqPtr = toSqPtr;
 do
 {
 sqPtr += sqIncr;
 }
 while ((*sqPtr & kAttackMask) == emptySq0);

 (movePtr++)->opponentPlacedInCheck =
 (sqPtr == oppKingSqPtr);
 }
 while (*toSqPtr <= emptySq1);
 }
 while ((toSqIncr = -toSqIncr) < 0);
 }
 while (++axisPtr != endAxisPtr);
 }

 endPcPtr = dataPtr->chessBoard.endSTMKnightPtr;
 for (pcPtr = dataPtr->stmKnightArray;
  pcPtr < endPcPtr; pcPtr++)
 {
 if (pcPtr->pinAxis)
 continue;

 toSqPtr = pcPtr->sqPtr;

/* 
Unlike long move pieces, each move of a Knight may be evaluated independently from all of its other moves. 
 Thus, the move table consists of a set of relative square differentials, each added in turn to the previous 
move’s square pointer, rather than basing all of the moves on the Knight’s current square pointer.
*/
 sqDiffPtr = dataPtr->knightSqDiffArray;
 endSqDiffPtr = sqDiffPtr + 8;
 do
 {
 if (*(toSqPtr += *sqDiffPtr) >= emptySq0)
 {
 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq =
 dataPtr->stmSqArrayPtr
 [toSqPtr - dataPtr->chessBoard.sqArray];
 movePtr->moveIsCapture = (*toSqPtr > emptySq1);
 (movePtr++)->opponentPlacedInCheck =
 (pcPtr->discAxis ||
  dataPtr->knightMoveArray
  [oppKingSqPtr - toSqPtr + kMaxSqDiff]);
 }
 }
 while (++sqDiffPtr != endSqDiffPtr);
 }

 endPcPtr = dataPtr->chessBoard.endSTMPawnPtr;
 for (pcPtr = dataPtr->stmPawnArray;
  pcPtr < endPcPtr; pcPtr++)
 {
/* 
Pawns require two different move evaluations; one for captures, and a different one for non-capture moves.
*/
 for (toSqIncr = 15; toSqIncr <= 17; toSqIncr += 2)
 {
 if ((pcPtr->pinAxis &&
  (pcPtr->pinAxis != toSqIncr)) ||
 (*(toSqPtr = pcPtr->sqPtr + toSqIncr) <=
  emptySq1))
 {
 continue; /* Pawn pinned or no capture available */
 }

 toSqIndex = toSqPtr - dataPtr->chessBoard.sqArray;

 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq = dataPtr->stmSqArrayPtr[toSqIndex];
 movePtr->moveIsCapture = true;

 if (pcPtr->discAxis)
 {
 (movePtr++)->opponentPlacedInCheck = true;
 continue;
 }

 if (toSqIndex < kMin8thRankSqIndex)
 {
 (movePtr++)->opponentPlacedInCheck =
 (((toSqPtr + 15) == oppKingSqPtr) ||
  ((toSqPtr + 17) == oppKingSqPtr));
 continue;
 }

/* 
Pawn promotion brings up two interesting points.  One, the value of “opponentPlacedInCheck” becomes 
ambiguous, since the Pawn can promote to a Queen, Rook, Bishop, or Knight, and the squares that it attacks 
will vary accordingly.  Since a Pawn most often promotes to a Queen, I have chosen to set “opponentPlacedInCheck” 
on that basis.  The second point concerns the “ghost image” of the Pawn after it moves.  In other cases, 
it does not matter that the piece being moved is still recorded as being on its original square, since a line 
of attack to the enemy King which goes through that square must be blocked anyway; otherwise, the piece 
would have checked the King from its original square, and the position would be illegal.  In the case of a promoted 
Pawn, however, this assumption does not hold true.  Therefore, I compare the square pointer with the Pawn’s 
original position; if they match, I treat the square as though it were empty.
*/
 sqIncr = dataPtr->queenSqIncrArray
  [oppKingSqPtr - toSqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 {
 (movePtr++)->opponentPlacedInCheck = false;
 continue;
 }

 sqPtr = toSqPtr;
 do
 {
 sqPtr += sqIncr;
 }
 while (((*sqPtr & kAttackMask) == emptySq0) ||
  (sqPtr == pcPtr->sqPtr));

 (movePtr++)->opponentPlacedInCheck =
 (sqPtr == oppKingSqPtr);
 }

 if (pcPtr->pinAxis & 0x0f) /* i.e., axis not 0 or 16 */
 continue;

/* 
Ordinarily, the Pawn advances only one square, but it may continue to a second square if it is not blocked 
and has not yet reached the fourth rank.
*/
 toSqPtr = pcPtr->sqPtr;
 do
 {
 if ((*(toSqPtr += 16) & kAttackMask) != emptySq0)
 break;

 toSqIndex = toSqPtr - dataPtr->chessBoard.sqArray;

 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq = dataPtr->stmSqArrayPtr[toSqIndex];
 movePtr->moveIsCapture = false;

 if (pcPtr->discAxis & 0x0f)
 {
 (movePtr++)->opponentPlacedInCheck = true;
 continue;
 }

 if (toSqIndex < kMin8thRankSqIndex)
 {
 (movePtr++)->opponentPlacedInCheck =
 (((toSqPtr + 15) == oppKingSqPtr) ||
  ((toSqPtr + 17) == oppKingSqPtr));
 continue;
 }

 sqIncr = dataPtr->queenSqIncrArray
  [oppKingSqPtr - toSqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 {
 (movePtr++)->opponentPlacedInCheck = false;
 break;
 }

 sqPtr = toSqPtr;
 do
 {
 sqPtr += sqIncr;
 }
 while (((*sqPtr & kAttackMask) == emptySq0) ||
  (sqPtr == pcPtr->sqPtr));

 (movePtr++)->opponentPlacedInCheck =
 (sqPtr == oppKingSqPtr);
 break;
 }
 while (toSqIndex < kMin4thRankSqIndex);
 }

 *moveHandle = movePtr;
}


EnumerateNonKingCapturesOfCheckingPiece

void EnumerateNonKingCapturesOfCheckingPiece
  (MyDataPtr dataPtr,
   MySquarePtr checkSqPtr,
 ChessMovePtr *moveHandle)
{
 MySquarePtroppKingSqPtr, sqPtr;
 short  checkSqIndex, sqIncr, fromSqIncr;
 Square checkSq;
 MyPiecePtr endPcPtr, pcPtr;
 ChessMovePtr    movePtr = *moveHandle;

 oppKingSqPtr = dataPtr->oppKing.sqPtr;

 checkSqIndex = checkSqPtr - dataPtr->chessBoard.sqArray;
 checkSq = dataPtr->stmSqArrayPtr[checkSqIndex];

 endPcPtr = dataPtr->chessBoard.endSTMLMPiecePtr;
 for (pcPtr = dataPtr->stmLMPieceArray;
  pcPtr < endPcPtr; pcPtr++)
 {
 if (pcPtr->pinAxis)
 continue;

 sqPtr = pcPtr->sqPtr;
 sqIncr = pcPtr->pcTable.sqIncrArrayPtr
  [checkSqPtr - sqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 continue;

 do
 {
 sqPtr += sqIncr;
 }
 while((*sqPtr & kAttackMask) == emptySq0);

 if (sqPtr != checkSqPtr)
 continue;

 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq = checkSq;
 movePtr->moveIsCapture = true;

 if (pcPtr->discAxis)
 {
 (movePtr++)->opponentPlacedInCheck = true;
 continue;
 }

 sqIncr = pcPtr->pcTable.sqIncrArrayPtr
  [oppKingSqPtr - sqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 {
 (movePtr++)->opponentPlacedInCheck = false;
 continue;
 }

 do
 {
 sqPtr += sqIncr;
 }
 while ((*sqPtr & kAttackMask) == emptySq0);

 (movePtr++)->opponentPlacedInCheck =
 (sqPtr == oppKingSqPtr);
 }

 endPcPtr = dataPtr->chessBoard.endSTMKnightPtr;
 for (pcPtr = dataPtr->stmKnightArray;
  pcPtr < endPcPtr; pcPtr++)
 {
 if (pcPtr->pinAxis == 0)
 {
 if (dataPtr->knightMoveArray
 [checkSqPtr - pcPtr->sqPtr + kMaxSqDiff])
 {
 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq = checkSq;
 movePtr->moveIsCapture = true;
 (movePtr++)->opponentPlacedInCheck =
 (pcPtr->discAxis ||
  dataPtr->knightMoveArray
  [oppKingSqPtr - checkSqPtr + kMaxSqDiff]);
 }
 }
 }

 for (fromSqIncr = 15; fromSqIncr <= 17; fromSqIncr += 2)
 {
 if (*(sqPtr = checkSqPtr - fromSqIncr) > stmPawnSq1)
 continue; /* Square does not contain mover’s Pawn */

 pcPtr = dataPtr->pcPtrArray
 [sqPtr - dataPtr->chessBoard.sqArray];
 if (pcPtr->pinAxis)
 continue;

 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq = checkSq;
 movePtr->moveIsCapture = true;

 if (pcPtr->discAxis)
 {
 (movePtr++)->opponentPlacedInCheck = true;
 continue;
 }

 sqPtr = checkSqPtr;
 if (checkSqIndex < kMin8thRankSqIndex)
 {
 (movePtr++)->opponentPlacedInCheck =
 (((sqPtr + 15) == oppKingSqPtr) ||
  ((sqPtr + 17) == oppKingSqPtr));
 continue;
 }

 sqIncr = dataPtr->queenSqIncrArray
  [oppKingSqPtr - sqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 {
 (movePtr++)->opponentPlacedInCheck = false;
 continue;
 }

 do
 {
 sqPtr += sqIncr;
 }
 while (((*sqPtr & kAttackMask) == emptySq0) ||
  (sqPtr == pcPtr->sqPtr));

 (movePtr++)->opponentPlacedInCheck =
 (sqPtr == oppKingSqPtr);
 }

 *moveHandle = movePtr;
}


EnumerateInterpositionMoves

void EnumerateInterpositionMoves(MyDataPtr dataPtr,
  MySquarePtr checkSqPtr,
  MySquareIncr checkSqIncr,
  ChessMovePtr *moveHandle)
{
 MySquarePtroppKingSqPtr, toSqPtr, sqPtr;
 short  toSqIndex, sqIncr;
 Square toSq;
 MyPiecePtr endPcPtr, pcPtr;
 ChessMovePtr    movePtr = *moveHandle;

 oppKingSqPtr = dataPtr->oppKing.sqPtr;

/* 
This “monster” do-loop repeats for each square which lies between the checking piece and the mover’s King.
*/
 toSqPtr = checkSqPtr + checkSqIncr;
 do
 {
 toSqIndex = toSqPtr - dataPtr->chessBoard.sqArray;
 toSq = dataPtr->stmSqArrayPtr[toSqIndex];

 endPcPtr = dataPtr->chessBoard.endSTMLMPiecePtr;
 for (pcPtr = dataPtr->stmLMPieceArray;
  pcPtr < endPcPtr; pcPtr++)
 {
 if (pcPtr->pinAxis)
 continue;

 sqPtr = pcPtr->sqPtr;
 sqIncr = pcPtr->pcTable.sqIncrArrayPtr
  [toSqPtr - sqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 continue;

 while ((sqPtr += sqIncr) != toSqPtr)
 {
 if ((*sqPtr & kAttackMask) != emptySq0)
 goto NextLMPiece; /* Break while, continue for */
 }

 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq = toSq;
 movePtr->moveIsCapture = false;
 
 if (pcPtr->discAxis)
 {
 (movePtr++)->opponentPlacedInCheck = true;
 continue;
 }
 
 sqIncr = pcPtr->pcTable.sqIncrArrayPtr
  [oppKingSqPtr - sqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 {
 (movePtr++)->opponentPlacedInCheck = false;
 continue;
 }
 
 do
 {
 sqPtr += sqIncr;
 }
 while ((*sqPtr & kAttackMask) == emptySq0);
 
 (movePtr++)->opponentPlacedInCheck =
 (sqPtr == oppKingSqPtr);

 NextLMPiece:
 ;
 }
 
 endPcPtr = dataPtr->chessBoard.endSTMKnightPtr;
 for (pcPtr = dataPtr->stmKnightArray;
  pcPtr < endPcPtr; pcPtr++)
 {
 if (pcPtr->pinAxis == 0)
 {
 if (dataPtr->knightMoveArray
 [toSqPtr - pcPtr->sqPtr + kMaxSqDiff])
 {
 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq = toSq;
 movePtr->moveIsCapture = false;
 (movePtr++)->opponentPlacedInCheck =
 (pcPtr->discAxis ||
  dataPtr->knightMoveArray
  [oppKingSqPtr - toSqPtr + kMaxSqDiff]);
 }
 }
 }

/* 
Pawn interposition is not possible if the square in the same column in the previous row does not contain a 
mover’s Pawn, AND any one of the following is true:
1.The square where interposition is to take place is not on the fourth rank,
2.The square in the same column on the third rank is not empty,
3.The square in the same column on the second rank does not contain a mover’s Pawn.
*/
 if ((*(sqPtr = toSqPtr - 16) > stmPawnSq1) &&
 ((toSqIndex >= kMin5thRankSqIndex) ||
  (toSqIndex < kMin4thRankSqIndex) ||
  ((*sqPtr & kAttackMask) != emptySq0) ||
  (*(sqPtr -= 16) > stmPawnSq1)))
 {
 continue;
 }

 pcPtr = dataPtr->pcPtrArray
 [sqPtr - dataPtr->chessBoard.sqArray];
 if (pcPtr->pinAxis)
 continue;

 movePtr->fromSq = pcPtr->fromSq;
 movePtr->toSq = toSq;
 movePtr->moveIsCapture = false;

 if (pcPtr->discAxis & 0x0f)
 {
 (movePtr++)->opponentPlacedInCheck = true;
 continue;
 }

 sqPtr = toSqPtr;
 if (toSqIndex < kMin8thRankSqIndex)
 {
 (movePtr++)->opponentPlacedInCheck =
 (((sqPtr + 15) == oppKingSqPtr) ||
  ((sqPtr + 17) == oppKingSqPtr));
 continue;
 }

 sqIncr = dataPtr->queenSqIncrArray
  [oppKingSqPtr - sqPtr + kMaxSqDiff];
 if (sqIncr == 0)
 {
 (movePtr++)->opponentPlacedInCheck = false;
 continue;
 }

 do
 {
 sqPtr += sqIncr;
 }
 while (((*sqPtr & kAttackMask) == emptySq0) ||
  (sqPtr == pcPtr->sqPtr));

 (movePtr++)->opponentPlacedInCheck =
 (sqPtr == oppKingSqPtr);
 }
 while (*(toSqPtr += checkSqIncr) >= emptySq0);

 *moveHandle = movePtr;
}


EnumerateKingMoves

void EnumerateKingMoves(MyDataPtr dataPtr,
 ChessMovePtr *moveHandle)
{
 MySquarePtrstmKingSqPtr, sqPtr, toSqPtr;
 short  discAxis, sqIncr;
 MySqDiffPtrsqDiffPtr, endSqDiffPtr;
 MyPiecePtr endPcPtr, pcPtr;
 ChessMovePtr    movePtr = *moveHandle;

 stmKingSqPtr = dataPtr->stmKing.sqPtr;
 discAxis = dataPtr->stmKing.discAxis;

 sqPtr = dataPtr->oppKing.sqPtr;
 sqIncr = stmKingSqPtr - sqPtr;
 if ((sqIncr >= -34) && (sqIncr <= +34))
 {
/* 
The opposing King might be within range of squares to which this King could move, so set the attack flag 
for all squares the opposing King attacks.  This will include some squares to which this King cannot move 
- it did not seem worth the trouble to code a fancy algorithm which ensures that only     squares to which this 
King can move have the attack flag set.  In most normal chess positions (excluding the endgame), the two 
Kings are at opposite ends of the board, so this code won’t be executed very often anyway.
*/
 sqDiffPtr = dataPtr->kingSqDiffArray;
 endSqDiffPtr = sqDiffPtr + 8;
 do
 {
 *(sqPtr += *sqDiffPtr) |= kAttackFlag;
 }
 while (++sqDiffPtr != endSqDiffPtr);
 }

 toSqPtr = stmKingSqPtr;

 sqDiffPtr = dataPtr->kingSqDiffArray;
 endSqDiffPtr = sqDiffPtr + 8;
 do
 {
/* 
The King cannot move to this square if:
1.It is off-board or occupied by mover’s own piece,
2.It is flagged as known to be under attack,
3.It is within capture range of an enemy Pawn.
*/
 if ((*(toSqPtr += *sqDiffPtr) < emptySq0) ||
 (*toSqPtr & kAttackFlag) ||
 (*(sqPtr = toSqPtr + 15) >= oppPawnSq0) ||
 (*(sqPtr += 2) >= oppPawnSq0))
 {
 continue;
 }

    /* 
    The square is also blocked if a long move piece or Knight attacks the square.
    */
 endPcPtr = dataPtr->chessBoard.endOppLMPiecePtr;
 for (pcPtr = dataPtr->oppLMPieceArray;
    pcPtr < endPcPtr; pcPtr++)
 {
 sqPtr = pcPtr->sqPtr;
 sqIncr = pcPtr->pcTable.sqIncrArrayPtr
  [toSqPtr - sqPtr + kMaxSqDiff];
 if (sqIncr)
 {
 do
 {
 if ((sqPtr += sqIncr) == toSqPtr)
 goto NextKingMove;

/* 
Set an “audit trail” of attacked squares for this piece.  Most of these attack flags will be useless, but they 
cost very little to set, and they make the test for empty squares easier.  If one does happen to fall in a square 
next to the mover’s King, it will save time by removing that square from consideration immediately.
*/
 *sqPtr |= kAttackFlag;
 }
 while (*sqPtr == emptySq1);
 }
 }

 endPcPtr = dataPtr->chessBoard.endOppKnightPtr;
 for (pcPtr = dataPtr->oppKnightArray;
    pcPtr < endPcPtr; pcPtr++)
 {
 if (dataPtr->knightMoveArray
 [toSqPtr - pcPtr->sqPtr + kMaxSqDiff])
 {
 goto NextKingMove;
 }
 }

 movePtr->fromSq = dataPtr->stmKing.fromSq;
 movePtr->toSq =
 dataPtr->stmSqArrayPtr
 [toSqPtr - dataPtr->chessBoard.sqArray];
 movePtr->moveIsCapture = (*toSqPtr > emptySq1);

    /* 
    The only checks which can result from a King move are checks.
    */
 if (discAxis == 0)
 {
 (movePtr++)->opponentPlacedInCheck = false;
 }
 else
 {
 sqIncr = toSqPtr - stmKingSqPtr;
 (movePtr++)->opponentPlacedInCheck =
 ((discAxis != sqIncr) && (discAxis != -sqIncr));
 }

 NextKingMove:
 ;
 }
 while (++sqDiffPtr != endSqDiffPtr);

 *moveHandle = movePtr;
}


InitChess

/* =========================================================
    Untimed initialization routine
========================================================= */

void InitChess(void *privateDataPtr)
{
 MyDataPtrdataPtr = privateDataPtr;
 MySquarePtrsqPtr;
 int    index, sqRow, sqCol;
 SquarePt whiteSqPtr, blackSqPtr;
 MySqIncrPtrposQueenSqIncrPtr, negQueenSqIncrPtr,
 posRookSqIncrPtr, negRookSqIncrPtr,
 posBishopSqIncrPtr, negBishopSqIncrPtr;
 Boolean*posKnightMovePtr, *negKnightMovePtr;

/* 
Quoting from the problem statement: “The privateDataPtr parameter will be the same pointer provided to 
InitChess."  Therefore, I can set pointers based on its value in my private data structure.  This would not 
be possible if the parameter were guaranteed only to point to a copy of the same data, but not necessarily 
to have the same value.
*/
 dataPtr->emptyBoard.endSTMKingPtr = &dataPtr->stmKing;
 dataPtr->emptyBoard.endOppKingPtr = &dataPtr->oppKing;
 dataPtr->emptyBoard.endSTMLMPiecePtr =
 dataPtr->stmLMPieceArray;
 dataPtr->emptyBoard.endOppLMPiecePtr =
 dataPtr->oppLMPieceArray;
 dataPtr->emptyBoard.endSTMKnightPtr =
 dataPtr->stmKnightArray;
 dataPtr->emptyBoard.endOppKnightPtr =
 dataPtr->oppKnightArray;
 dataPtr->emptyBoard.endSTMPawnPtr =
 dataPtr->stmPawnArray;

    /* 
    Initialize the empty chess board structure and the square coordinate arrays.
    */
 sqPtr = dataPtr->emptyBoard.sqArray;
 for (index = 0; index <= kMaxSqIndex; index++)
 {
 *sqPtr++ = offBoardSq0;
 }

 sqPtr = dataPtr->emptyBoard.sqArray + kLowerLeftSqIndex;
 whiteSqPtr = dataPtr->whiteSqArray + kLowerLeftSqIndex;
 blackSqPtr = dataPtr->blackSqArray + kUpperRightSqIndex;
 for (sqRow = 0; sqRow < 8; sqRow++)
 {
 for (sqCol = 0; sqCol < 8; sqCol++)
 {
 *sqPtr++ = emptySq0;
 whiteSqPtr->row = sqRow;
 blackSqPtr->row = sqRow;
 (whiteSqPtr++)->col = sqCol;
 (blackSqPtr--)->col = sqCol;
 }
 sqPtr += 8; whiteSqPtr += 8; blackSqPtr -= 8;
 }

    /* 
    Initialize the piece information arrays.
    */
 dataPtr->stmPcInfoArray[king].pcHandle =
 &dataPtr->chessBoard.endSTMKingPtr;
 dataPtr->stmPcInfoArray[king].sqType = stmPieceSq0;

 dataPtr->stmPcInfoArray[queen].pcHandle =
 &dataPtr->chessBoard.endSTMLMPiecePtr;
 dataPtr->stmPcInfoArray[queen].pcTable.sqIncrArrayPtr =
 dataPtr->queenSqIncrArray;
 dataPtr->stmPcInfoArray[queen].pcTable.axisArrayPtr =
 dataPtr->queenAxisArray;
 dataPtr->stmPcInfoArray[queen].pcTable.numberOfAxes = 4;
 dataPtr->stmPcInfoArray[queen].sqType = stmPieceSq0;

 dataPtr->stmPcInfoArray[rook].pcHandle =
 &dataPtr->chessBoard.endSTMLMPiecePtr;
 dataPtr->stmPcInfoArray[rook].pcTable.sqIncrArrayPtr =
 dataPtr->rookSqIncrArray;
 dataPtr->stmPcInfoArray[rook].pcTable.axisArrayPtr =
 dataPtr->rookAxisArray;
 dataPtr->stmPcInfoArray[rook].pcTable.numberOfAxes = 2;
 dataPtr->stmPcInfoArray[rook].sqType = stmPieceSq0;

 dataPtr->stmPcInfoArray[bishop].pcHandle =
 &dataPtr->chessBoard.endSTMLMPiecePtr;
 dataPtr->stmPcInfoArray[bishop].pcTable.sqIncrArrayPtr =
 dataPtr->bishopSqIncrArray;
 dataPtr->stmPcInfoArray[bishop].pcTable.axisArrayPtr =
 dataPtr->bishopAxisArray;
 dataPtr->stmPcInfoArray[bishop].pcTable.numberOfAxes = 2;
 dataPtr->stmPcInfoArray[bishop].sqType = stmPieceSq0;

 dataPtr->stmPcInfoArray[knight].sqType = stmPieceSq0;
 dataPtr->stmPcInfoArray[knight].pcHandle =
 &dataPtr->chessBoard.endSTMKnightPtr;

 dataPtr->stmPcInfoArray[pawn].pcHandle =
 &dataPtr->chessBoard.endSTMPawnPtr;
 dataPtr->stmPcInfoArray[pawn].sqType = stmPawnSq0;

 dataPtr->oppPcInfoArray[king].pcHandle =
 &dataPtr->chessBoard.endOppKingPtr;
 dataPtr->oppPcInfoArray[king].sqType = oppPieceSq0;

 dataPtr->oppPcInfoArray[queen].pcHandle =
 &dataPtr->chessBoard.endOppLMPiecePtr;
 dataPtr->oppPcInfoArray[queen].pcTable.sqIncrArrayPtr =
 dataPtr->queenSqIncrArray;
 dataPtr->oppPcInfoArray[queen].pcTable.axisArrayPtr =
 dataPtr->queenAxisArray;
 dataPtr->oppPcInfoArray[queen].pcTable.numberOfAxes = 4;
 dataPtr->oppPcInfoArray[queen].sqType = oppPieceSq0;

 dataPtr->oppPcInfoArray[rook].pcHandle =
 &dataPtr->chessBoard.endOppLMPiecePtr;
 dataPtr->oppPcInfoArray[rook].pcTable.sqIncrArrayPtr =
 dataPtr->rookSqIncrArray;
 dataPtr->oppPcInfoArray[rook].pcTable.axisArrayPtr =
 dataPtr->rookAxisArray;
 dataPtr->oppPcInfoArray[rook].pcTable.numberOfAxes = 2;
 dataPtr->oppPcInfoArray[rook].sqType = oppPieceSq0;

 dataPtr->oppPcInfoArray[bishop].pcHandle =
 &dataPtr->chessBoard.endOppLMPiecePtr;
 dataPtr->oppPcInfoArray[bishop].pcTable.sqIncrArrayPtr =
 dataPtr->bishopSqIncrArray;
 dataPtr->oppPcInfoArray[bishop].pcTable.axisArrayPtr =
 dataPtr->bishopAxisArray;
 dataPtr->oppPcInfoArray[bishop].pcTable.numberOfAxes = 2;
 dataPtr->oppPcInfoArray[bishop].sqType = oppPieceSq0;

 dataPtr->oppPcInfoArray[knight].pcHandle =
 &dataPtr->chessBoard.endOppKnightPtr;
 dataPtr->oppPcInfoArray[knight].sqType = oppPieceSq0;

 dataPtr->oppPcInfoArray[pawn].sqType = oppPawnSq0;

    /* 
    Initialize the piece movement look-up tables.
    */
 posQueenSqIncrPtr = negQueenSqIncrPtr =
 dataPtr->queenSqIncrArray + kMaxSqDiff;
 posRookSqIncrPtr = negRookSqIncrPtr =
 dataPtr->rookSqIncrArray + kMaxSqDiff;
 posBishopSqIncrPtr = negBishopSqIncrPtr =
 dataPtr->bishopSqIncrArray + kMaxSqDiff;
 posKnightMovePtr = negKnightMovePtr =
 dataPtr->knightMoveArray + kMaxSqDiff;

 for (sqRow = 0; sqRow < 8; sqRow++)
 {
 *posQueenSqIncrPtr++= 0;
 *negQueenSqIncrPtr--= 0;
 *posRookSqIncrPtr++ = 0;
 *negRookSqIncrPtr-- = 0;
 *posBishopSqIncrPtr++  = 0;
 *negBishopSqIncrPtr--  = 0;
 *posKnightMovePtr++ = false;
 *negKnightMovePtr-- = false;

 for (sqCol = sqRow ? -7 : +1; sqCol < 8; sqCol++)
 {
 if (sqRow == 0)
 {
 *posQueenSqIncrPtr++= + 1;
 *negQueenSqIncrPtr--= - 1;
 *posRookSqIncrPtr++ = + 1;
 *negRookSqIncrPtr-- = - 1;
 *posBishopSqIncrPtr++  =   0;
 *negBishopSqIncrPtr--  =   0;
 *posKnightMovePtr++ = false;
 *negKnightMovePtr-- = false;
 }
 else if (sqRow + sqCol == 0)
 {
 *posQueenSqIncrPtr++= +15;
 *negQueenSqIncrPtr--= -15;
 *posRookSqIncrPtr++ =   0;
 *negRookSqIncrPtr-- =   0;
 *posBishopSqIncrPtr++  = +15;
 *negBishopSqIncrPtr--  = -15;
 *posKnightMovePtr++ = false;
 *negKnightMovePtr-- = false;
 }
 else if (sqCol == 0)
 {
 *posQueenSqIncrPtr++= +16;
 *negQueenSqIncrPtr--= -16;
 *posRookSqIncrPtr++ = +16;
 *negRookSqIncrPtr-- = -16;
 *posBishopSqIncrPtr++  =   0;
 *negBishopSqIncrPtr--  =   0;
 *posKnightMovePtr++ = false;
 *negKnightMovePtr-- = false;
 }
 else if (sqRow == sqCol)
 {
 *posQueenSqIncrPtr++= +17;
 *negQueenSqIncrPtr--= -17;
 *posRookSqIncrPtr++ =   0;
 *negRookSqIncrPtr-- =   0;
 *posBishopSqIncrPtr++  = +17;
 *negBishopSqIncrPtr--  = -17;
 *posKnightMovePtr++ = false;
 *negKnightMovePtr-- = false;
 }
 else
 {
 *posQueenSqIncrPtr++= 0;
 *negQueenSqIncrPtr--= 0;
 *posRookSqIncrPtr++ = 0;
 *negRookSqIncrPtr-- = 0;
 *posBishopSqIncrPtr++  = 0;
 *negBishopSqIncrPtr--  = 0;

/* A Knight moves only to those squares within two rows and columns that a Queen cannot reach. */
 if ((sqRow < 3) &&
 (sqCol > -3) && (sqCol < 3))
 {
 *posKnightMovePtr++ = true;
 *negKnightMovePtr-- = true;
 }
 else
 {
 *posKnightMovePtr++ = false;
 *negKnightMovePtr-- = false;
 }
 }
 }
 }

 dataPtr->queenAxisArray[0] =  1;
 dataPtr->queenAxisArray[1] = 15;
 dataPtr->queenAxisArray[2] = 16;
 dataPtr->queenAxisArray[3] = 17;

 dataPtr->rookAxisArray[0]=  1;
 dataPtr->rookAxisArray[1]= 16;

 dataPtr->bishopAxisArray[0]= 15;
 dataPtr->bishopAxisArray[1]= 17;
 
 dataPtr->knightSqDiffArray[0]= -33;
 dataPtr->knightSqDiffArray[1]= + 2;
 dataPtr->knightSqDiffArray[2]= +13;
 dataPtr->knightSqDiffArray[3]= + 4;
 dataPtr->knightSqDiffArray[4]= +28;
 dataPtr->knightSqDiffArray[5]= + 4;
 dataPtr->knightSqDiffArray[6]= +13;
 dataPtr->knightSqDiffArray[7]= + 2;

 dataPtr->kingSqDiffArray[0]= -17;
 dataPtr->kingSqDiffArray[1]= + 1;
 dataPtr->kingSqDiffArray[2]= + 1;
 dataPtr->kingSqDiffArray[3]= +14;
 dataPtr->kingSqDiffArray[4]= + 2;
 dataPtr->kingSqDiffArray[5]= +14;
 dataPtr->kingSqDiffArray[6]= + 1;
 dataPtr->kingSqDiffArray[7]= + 1;
}

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Duplicate Annihilator 5.7.5 - Find and d...
Duplicate Annihilator takes on the time-consuming task of comparing the images in your iPhoto library using effective algorithms to make sure that no duplicate escapes. Duplicate Annihilator... Read more
BusyContacts 1.0.2 - Fast, efficient con...
BusyContacts is a contact manager for OS X that makes creating, finding, and managing contacts faster and more efficient. It brings to contact management the same power, flexibility, and sharing... Read more
Capture One Pro 8.2.0.82 - RAW workflow...
Capture One Pro 8 is a professional RAW converter offering you ultimate image quality with accurate colors and incredible detail from more than 300 high-end cameras -- straight out of the box. It... Read more
Backblaze 4.0.0.872 - Online backup serv...
Backblaze is an online backup service designed from the ground-up for the Mac.With unlimited storage available for $5 per month, as well as a free 15-day trial, peace of mind is within reach with... Read more
Little Snitch 3.5.2 - Alerts you about o...
Little Snitch gives you control over your private outgoing data. Track background activity As soon as your computer connects to the Internet, applications often have permission to send any... Read more
Monolingual 1.6.4 - Remove unwanted OS X...
Monolingual is a program for removing unnecesary language resources from OS X, in order to reclaim several hundred megabytes of disk space. If you use your computer in only one (human) language, you... Read more
CleanApp 5.0 - Application deinstaller a...
CleanApp is an application deinstaller and archiver.... Your hard drive gets fuller day by day, but do you know why? CleanApp 5 provides you with insights how to reclaim disk space. There are... Read more
Fantastical 2.0 - Create calendar events...
Fantastical is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event details... Read more
Cocktail 8.2 - General maintenance and o...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
Direct Mail 4.0.4 - Create and send grea...
Direct Mail is an easy-to-use, fully-featured email marketing app purpose-built for OS X. It lets you create and send great looking email campaigns. Start your newsletter by selecting from a gallery... Read more

Appy to Have Known You - Lee Hamlet Look...
Being at 148Apps these past 2 years has been an awesome experience that has taught me a great deal, and working with such a great team has been a privilege. Thank you to Rob Rich, and to both Rob LeFebvre and Jeff Scott before him, for helping me... | Read more »
MLB Manager 2015 (Games)
MLB Manager 2015 5.0.14 Device: iOS Universal Category: Games Price: $4.99, Version: 5.0.14 (iTunes) Description: Guide your favorite MLB franchise to glory! MLB Manager 2015, officially licensed by MLB.com and based on the award-... | Read more »
Breath of Light (Games)
Breath of Light 1.0.1421 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0.1421 (iTunes) Description: Hold a quiet moment. Breath of Light is a meditative and beautiful puzzle game with a hypnotic soundtrack by... | Read more »
WWE WrestleMania Tags into the App Store
Are You ready to rumble? The official WWE WrestleMania app, by World Wrestling Entertainment, is now available. Now you can get all your WrestleMania info in one place before anyone else. The app offers details on superstar signings, interactive... | Read more »
Bio Inc's New Expansion is Infectin...
Bio Inc., by DryGin Studios, is the real time strategy game where you infect a human body with the worst virus your evil brain can design. Recently, the game was updated to add a whole lot of new features. Now you can play the new “Lethal”... | Read more »
The Monocular Minion is Here! Despicable...
Despicable Me: Minion Rush, by Gameloft, is introducing a new runner to the mix in their latest update. Now you can play as Carl, the prankster minion. Carl has a few new abilities to play with, including running at a higher speed from the start.... | Read more »
Dungeon of Madness (Games)
Dungeon of Madness 1.0.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0.0 (iTunes) Description: Dungeon of Madness is an action game where you rotate tiles to create our own route. Help the hero by connecting the... | Read more »
Filters for iPhone (Photography)
Filters for iPhone 1.0 Device: iOS iPhone Category: Photography Price: $.99, Version: 1.0 (iTunes) Description: | Read more »
Jump'N'Shoot Attack (Games)
Jump'N'Shoot Attack 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: A mobile game for gamers! Join Louise Lightfoot, the legendary "Master of Jumping and Shooting", on her mission to save... | Read more »
Space Bounties Inc. (Games)
Space Bounties Inc. 1.4 Device: iOS Universal Category: Games Price: $1.99, Version: 1.4 (iTunes) Description: SuperGameDroid: 4/5 "Satisfying futuristic RPG combat, high replay value, and a heavy dose of nostalgia make Space... | Read more »

Price Scanner via MacPrices.net

13-inch 2.5GHz MacBook Pro (refurbished) avai...
The Apple Store has Apple Certified Refurbished 13″ 2.5GHz MacBook Pros available for $829, or $270 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free: - 13″ 2.... Read more
Save up to $80 on iPad Air 2s, NY tax only, f...
 B&H Photo has iPad Air 2s on sale for $80 off MSRP including free shipping plus NY sales tax only: - 16GB iPad Air 2 WiFi: $469.99 $30 off - 64GB iPad Air 2 WiFi: $549.99 $50 off - 128GB iPad... Read more
iMacs on sale for up to $205 off MSRP
B&H Photo has 21″ and 27″ iMacs on sale for up to $205 off MSRP including free shipping plus NY sales tax only: - 21″ 1.4GHz iMac: $1019 $80 off - 21″ 2.7GHz iMac: $1189 $110 off - 21″ 2.9GHz... Read more
Färbe Technik Offers iPhone Battery Charge LI...
Färbe Technik, which manufactures and markets of mobile accessories for Apple, Blackberry and Samsung mobile devices, is offering tips on how to keep your iPhone charged while in the field: •... Read more
Electronic Recyclers International CEO Urges...
Citing a recent story on CNBC about concerns some security professionals have about the forthcoming Apple Watch, John Shegerian, Chairman and CEO of Electronic Recyclers International (ERI), the... Read more
Save up to $380 with Apple refurbished iMacs
The Apple Store has Apple Certified Refurbished iMacs available for up to $380 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free: - 27″ 3.5GHz 5K iMac – $2119 $... Read more
Mac minis on sale for up to $75 off, starting...
MacMall has Mac minis on sale for up to $75 off MSRP including free shipping. Their prices are the lowest available for these models from any reseller: - 1.4GHz Mac mini: $459.99 $40 off - 2.6GHz Mac... Read more
College Student Deals: Additional $50 off Mac...
Take an additional $50 off all MacBooks and iMacs at Best Buy Online with their College Students Deals Savings, valid through April 11, 2015. Anyone with a valid .EDU email address can take advantage... Read more
Mac Pros on sale for up to $260 off MSRP
B&H Photo has Mac Pros on sale for up to $260 off MSRP. Shipping is free, and B&H charges sales tax in NY only: - 3.7GHz 4-core Mac Pro: $2799, $200 off MSRP - 3.5GHz 6-core Mac Pro: $3719.99... Read more
13-inch 2.5GHz MacBook Pro on sale for $100 o...
B&H Photo has the 13″ 2.5GHz MacBook Pro on sale for $999 including free shipping plus NY sales tax only. Their price is $100 off MSRP. Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Sr. Technical Services Consultant, *Apple*...
**Job Summary** Apple Professional Services (APS) has an opening for a senior technical position that contributes to Apple 's efforts for strategic and transactional Read more
Lead *Apple* Solutions Consultant - Retail...
**Job Summary** Job Summary The Lead ASC is an Apple employee who serves as the Apple business manager and influencer in a hyper-business critical Reseller's store Read more
*Apple* Pay - Site Reliability Engineer - Ap...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
*Apple* Solutions Consultant - Retail Sales...
**Job Summary** As an Apple Solutions Consultant (ASC) you are the link between our customers and our products. Your role is to drive the Apple business in a retail Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.