3dchess-0.8.1.orig/ 40755 0 17 0 6132224122 11765 5ustar rootkmem3dchess-0.8.1.orig/src/ 40755 0 17 0 6133212663 12564 5ustar rootkmem3dchess-0.8.1.orig/src/piece.c100644 0 17 54152 6125621756 14151 0ustar rootkmem/* * piece.c * * Rules for all pieces. */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #include #include "machine.h" #include "3Dc.h" #define PARAMS (Piece *, File, Rank, Level) Local INLINE Boolean KingMayMove PARAMS, QueenMayMove PARAMS, BishopMayMove PARAMS, KnightMayMove PARAMS, RookMayMove PARAMS, PrinceMayMove PARAMS, PrincessMayMove PARAMS, AbbeyMayMove PARAMS, CannonMayMove PARAMS, GalleyMayMove PARAMS, PawnMayMove PARAMS; #undef PARAMS /* This function interprets the result of TraverseDir(piece...) */ Global Boolean IsMoveLegal(const Piece *piece, const Piece *dest) { if (dest == SQUARE_EMPTY) return TRUE; if (dest == SQUARE_INVALID) { n3DcErr = E3DcSIMPLE; return FALSE; } else if ( piece->bwSide == dest->bwSide ) { n3DcErr = E3DcBLOCK; return FALSE; } return TRUE; } Global Piece * PieceNew(const Title nType, const File x, const Rank y, const Level z, const Colour col) { Piece *piece; piece = (Piece *)malloc(sizeof(Piece)); if (!piece) return NULL; piece->xyzPos.xFile = x; piece->xyzPos.yRank = y; piece->xyzPos.zLevel = z; piece->bwSide = col; piece->nName = nType; piece->bVisible = TRUE; piece->bHasMoved = FALSE; return piece; } Global void PieceDelete(Piece *piece) { if (Board[piece->xyzPos.zLevel][piece->xyzPos.yRank][piece->xyzPos.xFile] == piece) Board[piece->xyzPos.zLevel][piece->xyzPos.yRank][piece->xyzPos.xFile] = NULL; /* We don't need to remove the piece from the muster, as pieceDelete * is only called when restarting, at which time init3Dc is also called, * thereby overwriting Muster's reference to the piece. The only reason * for removing the piece from Board above is so that the board may be * redrawn cleanly. */ free(piece); piece = NULL; } Global Boolean PieceMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { Boolean retval; if (!piece || !piece->bVisible) { n3DcErr = E3DcINVIS; return FALSE; } /* Do bits which are the same for all pieces first */ if (xNew == piece->xyzPos.xFile && yNew == piece->xyzPos.yRank && zNew == piece->xyzPos.zLevel) { n3DcErr = E3DcSIMPLE; return FALSE; } if ((Board[zNew][yNew][xNew] != NULL) && (Board[zNew][yNew][xNew]->bVisible == TRUE) && (Board[zNew][yNew][xNew]->bwSide == piece->bwSide)) { n3DcErr = E3DcBLOCK; return FALSE; /* Can't take a piece on your team */ } switch (piece->nName) { case king: retval = KingMayMove(piece, xNew, yNew, zNew); break; case queen: retval = QueenMayMove(piece, xNew, yNew, zNew); break; case bishop: retval = BishopMayMove(piece, xNew, yNew, zNew); break; case knight: retval = KnightMayMove(piece, xNew, yNew, zNew); break; case rook: retval = RookMayMove(piece, xNew, yNew, zNew); break; case prince: retval = PrinceMayMove(piece, xNew, yNew, zNew); break; case princess: retval = PrincessMayMove(piece, xNew, yNew, zNew); break; case abbey: retval = AbbeyMayMove(piece, xNew, yNew, zNew); break; case cannon: retval = CannonMayMove(piece, xNew, yNew, zNew); break; case galley: retval = GalleyMayMove(piece, xNew, yNew, zNew); break; case pawn: retval = PawnMayMove(piece, xNew, yNew, zNew); break; default: retval = FALSE; n3DcErr = E3DcSIMPLE; } if ( retval != FALSE ) { if ( FakeMoveAndIsKingChecked(piece, xNew, yNew, zNew) == TRUE ) { n3DcErr = E3DcCHECK; return FALSE; } } return retval; } /* * Execute the move */ Global Boolean PieceMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { Move thisMove; Boolean moveType; /* Not quite Boolean... */ if (!(moveType = PieceMayMove(piece, xNew, yNew, zNew))) return FALSE; /* * Keep record of move */ thisMove.xyzBefore.xFile = piece->xyzPos.xFile; thisMove.xyzBefore.yRank = piece->xyzPos.yRank; thisMove.xyzBefore.zLevel = piece->xyzPos.zLevel; thisMove.xyzAfter.xFile = xNew; thisMove.xyzAfter.yRank = yNew; thisMove.xyzAfter.zLevel = zNew; if (moveType == EnPASSANT) { thisMove.nHadMoved = EnPASSANT; thisMove.pVictim = Board[zNew][yNew + (piece->bwSide == WHITE ? -1 : 1)][xNew]; } else if (moveType == CASTLE) { thisMove.nHadMoved = CASTLE; thisMove.pVictim = Board[1][yNew][xNew < ((FILES-1)/2) ? 0 : FILES-1]; } else if (moveType == PROMOTE) { thisMove.nHadMoved = PROMOTE; thisMove.pVictim = Board[zNew][yNew][xNew]; } else { thisMove.nHadMoved = piece->bHasMoved; thisMove.pVictim = Board[zNew][yNew][xNew]; } StackPush(MoveStack, &thisMove); piece->bHasMoved = TRUE; PieceDisplay(piece, FALSE); Board[piece->xyzPos.zLevel][piece->xyzPos.yRank][piece->xyzPos.xFile] = NULL; if (Board[zNew][yNew][xNew]) /* Kill victim */ { PieceDisplay(Board[zNew][yNew][xNew], FALSE); Board[zNew][yNew][xNew]->bVisible = FALSE; Board[zNew][yNew][xNew] = NULL; } Board[zNew][yNew][xNew] = piece; piece->xyzPos.xFile = xNew; piece->xyzPos.yRank = yNew; piece->xyzPos.zLevel = zNew; PieceDisplay(piece, TRUE); /* Now move any special pieces */ if (moveType == CASTLE) { int xRookSrc, xRookDest; /* If xNew on right of board then move to left * else move to right */ if (xNew > (FILES/2)) { xRookSrc = FILES -1; xRookDest = xNew -1; } else { xRookSrc = 0; xRookDest = xNew +1; } PieceDisplay(Board[1][yNew][xRookSrc], FALSE); Board[1][yNew][xRookDest] = Board[1][yNew][xRookSrc]; Board[1][yNew][xRookSrc] = NULL; (Board[1][yNew][xRookDest])->xyzPos.xFile = xRookDest; (Board[1][yNew][xRookDest])->bHasMoved = TRUE; PieceDisplay(Board[1][yNew][xRookDest], TRUE); } else if (moveType == EnPASSANT) { int yPawnSrc; /* If yNew is forward of half-way then victim is back one * else it is forward one */ yPawnSrc = (yNew > (RANKS/2) ? yNew-1 : yNew+1); PieceDisplay(Board[zNew][yPawnSrc][xNew], FALSE); Board[zNew][yPawnSrc][xNew]->bVisible = FALSE; Board[zNew][yPawnSrc][xNew] = NULL; } #if 0 /* I think that this code is obsolete.. */ /* Check that the king isn't in check */ if (IsKingChecked( piece->bwSide )) { /* Oops, this move puts the king in check; * it's illegal, so undo it */ PieceUndo(); n3DcErr = E3DcCHECK; return FALSE; } #endif /* If this bit is up with EnPASSANT and CASTLE, then the * promotion dialog pops up even though the promotion is * illegal. A promotion doesn't affect whether or not * the opponent checks your king (even if you promote to * cannon or something, you're still in the same place as * the dissappearing pawn..) so it works out better all * around if we just do it here. */ if (moveType == PROMOTE) { PieceDisplay(piece, FALSE); PiecePromote(piece); /* This function asks for promotion type, etc. */ } return TRUE; } /* * Undo the move */ Global Boolean PieceUndo(void) { Move *move; Colour bwMoved, bwTaken; Coord src, dest; move = StackPop(MoveStack); if (move == NULL) return FALSE; src = move->xyzAfter; dest = move->xyzBefore; bwMoved = Board[src.zLevel][src.yRank][src.xFile]->bwSide; bwTaken = (bwMoved == WHITE ? BLACK : WHITE); /* Clear the "moved-to" square */ PieceDisplay(Board[src.zLevel][src.yRank][src.xFile], FALSE); /* Move the "moved" piece back */ Board[dest.zLevel][dest.yRank][dest.xFile] = Board[src.zLevel][src.yRank][src.xFile]; (Board[dest.zLevel][dest.yRank][dest.xFile])->xyzPos = dest; Board[src.zLevel][src.yRank][src.xFile] = NULL; switch (move->nHadMoved) { case PROMOTE: /* This piece was promoted from a pawn: demote it */ Board[dest.zLevel][dest.yRank][dest.xFile]->nName = pawn; (Board[dest.zLevel][dest.yRank][dest.xFile])->bHasMoved = TRUE; break; case CASTLE: { int xRookSrc, xRookDest; /* xRookDest is beside edge */ /* The move undone was a castle */ /* The king is back in the right place; now * fix the rook */ if (src.xFile < dest.xFile) { /* Castled to a smaller-id square (Queen's side for white, * King's side for black) */ xRookSrc = dest.xFile -1; xRookDest = 0; } else { /* Castled to a larger-id square (Queen's side for black, * King's side for white) */ xRookSrc = dest.xFile +1; xRookDest = FILES -1; } PieceDisplay(Board[1][dest.yRank][xRookSrc], FALSE); Board[1][dest.yRank][xRookDest] = Board[1][dest.yRank][xRookSrc]; Board[1][dest.yRank][xRookSrc] = NULL; (Board[1][dest.yRank][xRookDest])->xyzPos.xFile = xRookDest; (Board[1][dest.yRank][xRookDest])->xyzPos.yRank = dest.yRank; (Board[1][dest.yRank][xRookDest])->xyzPos.zLevel = 1; PieceDisplay(Board[1][dest.yRank][xRookDest], TRUE); /* And finally---reset the bHasMoved flags */ (Board[1][dest.yRank][dest.xFile])->bHasMoved = FALSE; (Board[1][dest.yRank][xRookDest])->bHasMoved = FALSE; } break; case EnPASSANT: FallThrough(); default: (Board[dest.zLevel][dest.yRank][dest.xFile])->bHasMoved = move->nHadMoved; } /* Draw the piece in its original space */ PieceDisplay(Board[dest.zLevel][dest.yRank][dest.xFile], TRUE); /* Put any taken piece back */ if (move->pVictim) { Coord srcPos; /* Don't use src as the victim's square, as it could have * been en passant */ srcPos = move->pVictim->xyzPos; Board[srcPos.zLevel][srcPos.yRank][srcPos.xFile] = move->pVictim; Board[srcPos.zLevel][srcPos.yRank][srcPos.xFile]->bVisible = TRUE; PieceDisplay(Board[srcPos.zLevel][srcPos.yRank][srcPos.xFile], TRUE); } free(move); return TRUE; } /* * Here down are the specific piece-movement functions * * These all assume that piece is of the correct type. * No check is made and things get very odd if this assumption * is contradicted, so be careful. */ Local INLINE Boolean KingMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff, xCur, xInc; Rank yDiff; Level zDiff; xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; zDiff = zNew - piece->xyzPos.zLevel; xDiff = ABS(xDiff); yDiff = ABS(yDiff); zDiff = ABS(zDiff); /* Not allowed move more than 1 except when castling */ if ( (piece->bHasMoved && (xDiff > 2)) || (yDiff > 1) || (zDiff > 1) ) { n3DcErr = E3DcDIST; return FALSE; } /* * At this stage, we have determined that, given an empty board, * the move is legal. Now take other pieces into account. */ if (FakeMoveAndIsKingChecked( piece, xNew, yNew, zNew) || ( (xDiff == 2) && FakeMoveAndIsKingChecked( piece, (xNew + piece->xyzPos.xFile)/2, yNew, zNew ) )) { n3DcErr = E3DcCHECK; return FALSE; } if (xDiff == 2) { /* Castling */ File xRook; if (yDiff || zDiff) { n3DcErr = E3DcSIMPLE; return FALSE; } /* * Determine x-pos of castling rook */ if (xNew > piece->xyzPos.xFile) xRook = FILES-1; else xRook = 0; if (piece->bHasMoved || Board[1][yNew][xRook]->bHasMoved) { n3DcErr = E3DcMOVED; return FALSE; } else if (!Board[1][yNew][xRook]) { n3DcErr = E3DcSIMPLE; return FALSE; } xInc = ( xRook == 0 ) ? -1 : 1 ; for (xCur = piece->xyzPos.xFile + xInc; xCur != xRook; xCur += xInc) { /* Is the castle blocked? */ if (Board[1][yNew][xCur]) { n3DcErr = E3DcBLOCK; return FALSE; } } return CASTLE; } return TRUE; } Local INLINE Boolean QueenMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff; Level zDiff; Piece *pDestSquare; xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; zDiff = zNew - piece->xyzPos.zLevel; if ((xDiff && yDiff && (ABS(xDiff) != ABS(yDiff))) || (xDiff && zDiff && (ABS(xDiff) != ABS(zDiff))) || (yDiff && zDiff && (ABS(yDiff) != ABS(zDiff)))) { n3DcErr = E3DcSIMPLE; return False; } /* * At this stage, we have determined that, given an empty board, * the move is legal. Now take other pieces into account. */ pDestSquare = TraverseDir(piece, xDiff, yDiff, zDiff, MAX(ABS(xDiff), MAX(ABS(yDiff), ABS(zDiff)))); return IsMoveLegal(piece, pDestSquare); } Local INLINE Boolean BishopMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff; Level zDiff; Piece *pDestSquare; xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; zDiff = zNew - piece->xyzPos.zLevel; if (!DIAG3D(xDiff, yDiff, zDiff)) { n3DcErr = E3DcSIMPLE; return FALSE; } /* * At this stage, we have determined that, given an empty board, * the move is legal. Now take other pieces into account. */ pDestSquare = TraverseDir(piece, xDiff, yDiff, zDiff, MAX(ABS(xDiff), ABS(yDiff))); return IsMoveLegal(piece, pDestSquare); } Local INLINE Boolean KnightMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff; if (zNew != piece->xyzPos.zLevel) { n3DcErr = E3DcLEVEL; return FALSE; /* Knights may not change level */ } xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; xDiff = ABS(xDiff); yDiff = ABS(yDiff); if ((xDiff == 0) || (yDiff == 0) || ((xDiff + yDiff) != 3)) return FALSE; return TRUE; } Local INLINE Boolean RookMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff; Level zDiff; Piece *pDestSquare; xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; zDiff = zNew - piece->xyzPos.zLevel; if (!HORZ3D(xDiff, yDiff, zDiff)) { n3DcErr = E3DcSIMPLE; return FALSE; } /* * At this stage, we have determined that, given an empty board, * the move is legal. Now take other pieces into account. */ pDestSquare = TraverseDir(piece, xDiff, yDiff, zDiff, MAX(ABS(xDiff), MAX(ABS(yDiff), ABS(zDiff)))); return IsMoveLegal(piece, pDestSquare); } Local INLINE Boolean PrinceMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff; if (zNew != piece->xyzPos.zLevel) { n3DcErr = E3DcLEVEL; return FALSE; /* Princes may not change level */ } xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; xDiff = ABS(xDiff); yDiff = ABS(yDiff); if (xDiff > 1 || yDiff > 1) /* Not allowed move more than 1 */ { n3DcErr = E3DcDIST; return FALSE; } return TRUE; } Local INLINE Boolean PrincessMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff; Piece * pDestSquare; if (zNew != piece->xyzPos.zLevel) { n3DcErr = E3DcLEVEL; return FALSE; /* Princesses may not change level */ } xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; if (xDiff && yDiff && (ABS(xDiff) != ABS(yDiff))) { n3DcErr = E3DcSIMPLE; return FALSE; } /* * At this stage, we have determined that, given an empty board, * the move is legal. Now take other pieces into account. */ pDestSquare = TraverseDir(piece, xDiff, yDiff, 0, MAX(ABS(xDiff), ABS(yDiff))); return IsMoveLegal(piece, pDestSquare); } Local INLINE Boolean AbbeyMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff; Piece *pDestSquare; if (zNew != piece->xyzPos.zLevel) { n3DcErr = E3DcLEVEL; return FALSE; /* Abbies may not change level */ } xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; if (!DIAG(xDiff, yDiff)) { n3DcErr = E3DcSIMPLE; return FALSE; } /* * At this stage, we have determined that, given an empty board, * the move is legal. Now take other pieces into account. */ pDestSquare = TraverseDir(piece, xDiff, yDiff, 0, MAX(ABS(xDiff), ABS(yDiff))); return IsMoveLegal(piece, pDestSquare); } Local INLINE Boolean CannonMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff; Level zDiff; xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; zDiff = zNew - piece->xyzPos.zLevel; xDiff = ABS(xDiff); yDiff = ABS(yDiff); zDiff = ABS(zDiff); if (((xDiff + yDiff + zDiff) != 6) || ((xDiff != 3) && (yDiff != 3)) || ((xDiff != 2) && (yDiff != 2) && (zDiff != 2))) { n3DcErr = E3DcSIMPLE; return FALSE; } return TRUE; } Local INLINE Boolean GalleyMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff; Piece *pDestSquare; if (zNew != piece->xyzPos.zLevel) { n3DcErr = E3DcLEVEL; return FALSE; /* Gallies may not change level */ } xDiff = xNew - piece->xyzPos.xFile; yDiff = yNew - piece->xyzPos.yRank; if (!HORZ(xDiff, yDiff)) { n3DcErr = E3DcSIMPLE; return FALSE; } /* * At this stage, we have determined that, given an empty board, * the move is legal. Now take other pieces into account. */ pDestSquare = TraverseDir(piece, xDiff, yDiff, 0, MAX(ABS(xDiff), ABS(yDiff))); return IsMoveLegal(piece, pDestSquare); } Local INLINE Boolean PawnMayMove(Piece *piece, const File xNew, const Rank yNew, const Level zNew) { File xDiff; Rank yDiff, yInc; if (zNew != piece->xyzPos.zLevel) { n3DcErr = E3DcLEVEL; return FALSE; /* Pawns may not change level */ } xDiff = xNew - piece->xyzPos.xFile; yInc = yDiff = yNew - piece->xyzPos.yRank; xDiff = ABS(xDiff); yDiff = ABS(yDiff); /* * Pawns must move at least 1 forward */ if ((yDiff == 0) || ((yInc < 0) && (piece->bwSide == WHITE)) || ((yInc > 0) && (piece->bwSide == BLACK))) /* Moving backwards */ { n3DcErr = E3DcSIMPLE; return FALSE; } /* Check the definitely-illegal moves first.. */ if (xDiff > 1 || (xDiff == 1 && yDiff != 1)) { n3DcErr = E3DcSIMPLE; return FALSE; } /* * It is difficult to cater for 'en passant' in the middle of a * conditional. So, against all convention laid out in other * rules functions, I am checking a move and returning true if it * is valid, rather than returning FALSE if it is invalid. */ #if 0 /* * TODO: * Only allow en passant taking of pawns that moved two spaces * forward in one go (in the previous move only?) * Each piece must have an identifier; either its memory location * or its offset into the Muster. That way this can be used as the * 4th line of this conditional. */ ( StackPeek(MoveStack, 1)->nId == Board[zNew][yNew - yInc][xNew]->nId && !(StackPeek(MoveStack, 1)->nHadMoved) && Board[zNew][yNew - yInc][xNew]->bHasMoved /* Moved only once */ ) #endif /* 0 */ if (xDiff == 1 && yDiff == 1 && !Board[zNew][yNew][xNew]) { /* En passant? */ if (Board[zNew][yNew - yInc][xNew] && /* 'Takable' piece */ Board[zNew][yNew - yInc][xNew]->nName == pawn && /* Is pawn */ Board[zNew][yNew - yInc][xNew]->bwSide != piece->bwSide && /* Is enemy */ 1) /* Dummy line to reduce no. of changes */ { return EnPASSANT; } else { n3DcErr = E3DcSIMPLE; return FALSE; } } /* * Pawns can not move forward under these conditions: * They move more than 2 * They move more than 1 and they have already moved * They attempt to take any piece (catered for in next conditional) */ if (yDiff > 2 || /* Move too far */ (piece->bHasMoved && yDiff == 2)) /* Move too far */ { n3DcErr = E3DcDIST; return FALSE; } /* * Pawns may not take anything under these conditions: * They do not move diagonally forward one space * The victim is an ally */ if (Board[zNew][yNew][xNew] && /* Taking something */ (!(xDiff == 1 && yDiff == 1) || /* Not moving diagonally */ Board[zNew][yNew][xNew]->bwSide == piece->bwSide)) { n3DcErr = E3DcSIMPLE; return FALSE; } /* Check for possible promotion */ if ((yNew == FILES-1 && piece->bwSide == WHITE) || (yNew == 0 && piece->bwSide == BLACK)) return PROMOTE; return TRUE; } 3dchess-0.8.1.orig/src/engine.c100644 0 17 12753 6132215010 14306 0ustar rootkmem/* * engine.c * * The rules engine for 3Dc. */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #include #include #include #include "machine.h" #include "3Dc.h" /* * Returns a pointer to any one piece of the specified colour threatening * the mentioned square. Will return NULL if the square is not * threatened. */ Global Piece * SquareThreatened(Colour bwSide, const File xFile, const Rank yRank, const Level zLevel) { int pieceIdx; for (pieceIdx = 0; pieceIdx < PIECES; ++pieceIdx) { if (Muster[bwSide][pieceIdx]->bVisible && PieceMayMove( Muster[bwSide][pieceIdx], xFile, yRank, zLevel )) return Muster[bwSide][pieceIdx]; } return NULL; } /* Go dist in given direction. Direction is positive, negative, 0, * with obvious meanings (think of the axes). * Return SQUARE_EMPTY, SQUARE_INVALID, or a pointer to the piece * first encountered (even if it is before the "destination" * location). * * SQUARE_EMPTY and SQUARE_INVALID are of type (Piece *); the only * legitimate value in them is xyzPos which is the coord of the * square in question (SQUARE_EMPTY) or the coord of the last * legitimate square on the route (SQAURE_INVALID). If any or all * members of the xyzPos struct are equal to UINT_MAX then there was * error which utterly precludes moving (e.g. dist == 0). */ Global Piece * TraverseDir(const Piece *piece, Dir xDir, Dir yDir, Dir zDir, unsigned dist) { int x, y, z, d = 0; /* Most move at least one in a real direction */ if ((dist == 0) || ((xDir == 0) && (yDir == 0) && (zDir == 0))) { SQUARE_INVALID->xyzPos.xFile = SQUARE_INVALID->xyzPos.yRank = SQUARE_INVALID->xyzPos.zLevel = UINT_MAX; return SQUARE_INVALID; } if ((piece->nName != knight) && (piece->nName != cannon)) { /* Make all directions be 1, -1 or 0 */ if (xDir != 0) xDir /= ABS(xDir); if (yDir != 0) yDir /= ABS(yDir); if (zDir != 0) zDir /= ABS(zDir); } else dist = 1; x = piece->xyzPos.xFile; y = piece->xyzPos.yRank; z = piece->xyzPos.zLevel; do { x += xDir; y += yDir; z += zDir; if (!((x >= 0) && (y >= 0) && (z >= 0) && (x < FILES) && (y < RANKS) && (z < LEVELS))) { SQUARE_INVALID->xyzPos.xFile = x; SQUARE_INVALID->xyzPos.yRank = y; SQUARE_INVALID->xyzPos.zLevel = z; return SQUARE_INVALID; } if (Board[z][y][x]) { if (Board[z][y][x]->bwSide == piece->bwSide) { SQUARE_INVALID->xyzPos.xFile = x; SQUARE_INVALID->xyzPos.yRank = y; SQUARE_INVALID->xyzPos.zLevel = z; return SQUARE_INVALID; } else return Board[z][y][x]; } } while (++d < dist); /* * At this point, because we haven't returned, we know these things: * We have not encountered another piece. * We have moved dist spaces. */ if ((x >= 0) && (y >= 0) && (z >= 0) && (z < LEVELS) && (y < RANKS) && (x < FILES)) { /* Valid (empty) square */ SQUARE_EMPTY->xyzPos.xFile = x; SQUARE_EMPTY->xyzPos.yRank = y; SQUARE_EMPTY->xyzPos.zLevel = z; return SQUARE_EMPTY; } /* * We fell off the board. Go back one place to the last valid * location. */ SQUARE_INVALID->xyzPos.xFile = x - xDir; SQUARE_INVALID->xyzPos.yRank = y - yDir; SQUARE_INVALID->xyzPos.zLevel = z - zDir; return SQUARE_INVALID; } /* * Return TRUE if the king is checked in the current board layout. */ Inline Global Boolean IsKingChecked( Colour bwSide ) { Coord xyz; xyz = Muster[ bwSide ][ MusterIdx( king, 0 ) ]->xyzPos; return ( SquareThreatened( (bwSide == WHITE) ? BLACK : WHITE, xyz.xFile, xyz.yRank, xyz.zLevel ) != NULL ); } /* Check move re. putting own king in check */ Inline Global Boolean FakeMoveAndIsKingChecked( Piece *piece, const File x, const Rank y, const Level z) { Piece *temp; Boolean retVal; Coord xyz; xyz = piece->xyzPos; temp = Board[z][y][x]; if ( temp != NULL ) temp->bVisible = FALSE; Board[z][y][x] = piece; Board[xyz.zLevel][xyz.yRank][xyz.xFile] = NULL; if (piece->nName == king) { /* We're moving the king, so it's xyzPos may not be accurate. * check manually. */ retVal = (SquareThreatened( (piece->bwSide == WHITE) ? BLACK : WHITE, x, y, z ) != NULL) ; } else retVal = IsKingChecked(piece->bwSide); Board[z][y][x] = temp; if ( temp != NULL ) temp->bVisible = TRUE; Board[xyz.zLevel][xyz.yRank][xyz.xFile] = piece; return retVal; } 3dchess-0.8.1.orig/src/init.c100644 0 17 12270 6116376335 14022 0ustar rootkmem/* * init.c * * Initialisations for 3Dc engine and pieces. * Interface initialisation is external. */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #include #include #include #include #include "machine.h" #include "3Dc.h" int n3DcErr; Piece *SQUARE_EMPTY, *SQUARE_INVALID; stack *MoveStack; /* The history of moves */ Piece *Board[LEVELS][RANKS][FILES]; /* The board */ Piece *Muster[COLOURS][PIECES]; /* The list of pieces */ int titleCount[TITLES] = { /* king */ 1, /* queen */ 1, /* bishop */ 2, /* knight */ 2, /* rook */ 2, /* prince */ 2, /* princess */ 2, /* abbey */ 4, /* cannon */ 4, /* galley */ 4, /* pawn */ 24 }; /* * This function sets up the board */ Global Boolean Init3Dc(void) { File x; Rank y; Level z; Colour bw; int count[COLOURS][TITLES] = {{0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0}}; Title name; /* This structure is mainly for "obviousness"; it is entirely trivial */ Title StartBoard[LEVELS][RANKS][FILES] = { /* The boards */ { /* Bottom board */ { galley, cannon, abbey, prince, princess,abbey, cannon, galley}, { pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn}, { none, none, none, none, none, none, none, none}, { none, none, none, none, none, none, none, none}, { none, none, none, none, none, none, none, none}, { none, none, none, none, none, none, none, none}, { pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn}, { galley, cannon, abbey, prince, princess,abbey, cannon, galley}, }, { /* Middle board */ { rook, knight, bishop, king, queen, bishop, knight, rook}, { pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn}, { none, none, none, none, none, none, none, none}, { none, none, none, none, none, none, none, none}, { none, none, none, none, none, none, none, none}, { none, none, none, none, none, none, none, none}, { pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn}, { rook, knight, bishop, king, queen, bishop, knight, rook} }, { /* Top board */ { galley, cannon, abbey, prince, princess,abbey, cannon, galley}, { pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn}, { none, none, none, none, none, none, none, none}, { none, none, none, none, none, none, none, none}, { none, none, none, none, none, none, none, none}, { none, none, none, none, none, none, none, none}, { pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn}, { galley, cannon, abbey, prince, princess,abbey, cannon, galley}, } }; /* StartBoard */ for (z = 0; z < LEVELS; ++z) { bw = WHITE; for (y = 0; y < RANKS; ++y) { /* From the 4th rank on is black's half of the board */ if (y == 4) bw = BLACK; for (x = 0; x < FILES; ++x) { name = StartBoard[z][y][x]; if ((name != none) /* * this part of the conditional is unnecessary as * there are no "unknown" variables */ /* * && (count[bw][name] < titleCount[name]) */ ) { Muster[bw][MusterIdx(name, count[bw][name])] = Board[z][y][x] = PieceNew(name, x, y, z, bw); (count[bw][name])++; } } } } /* That's the pieces done. Now for the move stack */ MoveStack = StackNew(); /* Start the random number generator */ srandom((unsigned)time(NULL)); /* * And finally initialise the global variables: * these are really dynamic global identifiers, in that they * are read-only interfaces to various modules; kind of like * getopt()'s optind and optarg. */ n3DcErr = 0; SQUARE_INVALID = (Piece *)malloc(sizeof(Piece)); SQUARE_EMPTY = (Piece *)malloc(sizeof(Piece)); if (!CHECK(SQUARE_INVALID != NULL) && !CHECK(SQUARE_EMPTY != NULL)) return FALSE; /* If there's no memory now there never will be.. */ return TRUE; } 3dchess-0.8.1.orig/src/main.c100644 0 17 25641 6132217175 14003 0ustar rootkmem/* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #include #include #include #include #include #include #include #include #include "machine.h" #include "3Dc.h" #define MAX_RETRIES 100 /* Number of times to guess a tricky move */ Colour bwToMove = WHITE; Local Colour computer = NOCOL; Local Boolean gamePaused = FALSE; Local Boolean SetupAutoplay(char *); Local void DoMain3DcLoop(void); int main(int argc, char **argv) { int argNum; printf("3Dc version %s, Copyright (C) 1995,1996 Paul Hicks\n", VERSION); printf("3Dc comes with ABSOLUTELY NO WARRANTY: see the GPL file for details\n"); printf("This is free software: you are welcome to redistribute it\n"); printf(" under certain conditions (see the GPL file).\n"); Init3Dc(); if (Init3DcGFX(argc, argv) == FALSE) return 1; for (argNum = 1; argNum < argc; ++argNum) { if (!strcmp(argv[argNum], "-play")) { if (++argNum >= argc) { fprintf(stderr, "%s: -play requires a colour (black or white)\n", argv[0]); return 1; } if (SetupAutoplay(argv[argNum]) == FALSE) { fprintf(stderr, "%s: %s is not a colour (must be black or white)\n", argv[0], argv[argNum]); return 1; } } /* End autoplay setup */ else if (!strcmp(argv[argNum], "-altdisplay") || !strcmp(argv[argNum], "-ad")) { /* If no more params or next param is a new option */ if ((++argNum == argc) || argv[argNum][0] == '-') { fprintf(stderr, "%s: option %s requires a display name parameter\n", argv[0], argv[argNum -1]); return 1; } else { Open2ndDisplay(argv[argNum]); } } /* End net setup */ else /* The help option */ { fprintf(stderr, "Usage:\n"); fprintf(stderr, "\ %s ; play 3Dc, two humans on one display\n\ %s -ad|-altdisplay [display] ; black plays on display `display'\n\ %s -play colour ; play against the computer, which plays colour\n", argv[0], argv[0], argv[0]); return 1; } } /* Finish parameters */ DoMain3DcLoop(); return 0; } /* Set up the computer intelligence and all that */ Local Boolean SetupAutoplay(char *colourName) { if (!strcmp(colourName, "black")) computer = BLACK; else if (!strcmp(colourName, "white")) computer = WHITE; else { return FALSE; } return TRUE; } Local void DoMain3DcLoop(void) { Move *automove; XEvent event; Local Boolean retry = FALSE; while (firstGFX->mainWindow) { /* First thing to do: check for end of game! */ if (IsGameFinished() && !gamePaused) FinishGame((bwToMove == BLACK) ? WHITE : BLACK); if ( (bwToMove == computer) && !gamePaused) { if (((retry == FALSE) && GenMove(computer, &automove) == TRUE) || ((retry == TRUE) && GenAltMove(computer, &automove) == TRUE)) { if ( automove == NULL ) { /* * Give up, it's too hard for me.. */ PauseGame(); /* Can we delay after this? */ Err3Dc(firstGFX, "Gaah! I give up.", TRUE); XFlush( XtDisplay( firstGFX->mainWindow )); FinishGame((computer == BLACK) ? WHITE : BLACK); } /*** This assertion fails with stack size of 1---or at least it used to */ else if ( (Board[ automove->xyzBefore.zLevel ] [ automove->xyzBefore.yRank ] [ automove->xyzBefore.xFile ] == NULL ) || (!CHECK( PieceMove( Board[ automove->xyzBefore.zLevel ] [ automove->xyzBefore.yRank ] [ automove->xyzBefore.xFile ], automove->xyzAfter.xFile, automove->xyzAfter.yRank, automove->xyzAfter.zLevel ) )) ) { /* The move was illegal for some reason * (in the future I plan to eliminate all * possibility of getting in here) */ D( printf( "Can't move from (%i,%i,%i) to (%i,%i,%i)\n", automove->xyzBefore.xFile, automove->xyzBefore.yRank, automove->xyzBefore.zLevel, automove->xyzAfter.xFile, automove->xyzAfter.yRank, automove->xyzAfter.zLevel ) ); retry = TRUE; } else /* Move is legit: do it */ { retry = FALSE; PrintMove( automove ); bwToMove = ((computer == WHITE) ? BLACK : WHITE); } /* End 'found computer move' */ } /* Still finding computer's move? */ } /* End computer's move */ if (XtAppPending(XtWidgetToApplicationContext(firstGFX->mainWindow))) { XtAppNextEvent(XtWidgetToApplicationContext(firstGFX->mainWindow), &event); XtDispatchEvent(&event); } if ((secondGFX != NULL) && (XtAppPending(XtWidgetToApplicationContext(secondGFX->mainWindow)))) { XtAppNextEvent(XtWidgetToApplicationContext(secondGFX->mainWindow), &event); XtDispatchEvent(&event); } } /* End game loop */ return; } /*************************************************************/ /* Utility functions */ Global int MusterIdx(const Title name, const int nth) { int i, count = 0; for (i = 0; i != name && i < TITLES; ++i) count += titleCount[i]; if (i == TITLES) return 47; /* 47 is a hack; it is a legal array index that is only * valid for pawns */ if (nth < titleCount[name]) { return count + nth; } /* else */ return 47; } Global char *Piece2String( Piece *piece ) { static char *names[] = { "King", "Queen", "Bishop", "Knight", "Rook", "Prince", "Princess", "Abbey", "Cannon", "Galley", "Pawn", "" }; return names[piece->nName]; } Global Colour Computer(void) { return computer; } Global void PauseGame(void) { gamePaused = TRUE; return; } Global void ResumeGame(void) { gamePaused = FALSE; return; } Global Boolean IsGamePaused(void) { return gamePaused; } Global Boolean IsGameFinished(void) { Boolean blackKingVisible, whiteKingVisible, blackFirstPrinceVisible, whiteFirstPrinceVisible, blackSecondPrinceVisible, whiteSecondPrinceVisible; blackKingVisible = Muster[BLACK][MusterIdx(king, 0)]->bVisible; whiteKingVisible = Muster[WHITE][MusterIdx(king, 0)]->bVisible; blackFirstPrinceVisible = Muster[BLACK][MusterIdx(prince, 0)]->bVisible; whiteFirstPrinceVisible = Muster[WHITE][MusterIdx(prince, 0)]->bVisible; blackSecondPrinceVisible = Muster[BLACK][MusterIdx(prince, 1)]->bVisible; whiteSecondPrinceVisible = Muster[WHITE][MusterIdx(prince, 1)]->bVisible; if ((!whiteKingVisible || (!whiteFirstPrinceVisible && !whiteSecondPrinceVisible)) || (!blackKingVisible || (!blackFirstPrinceVisible && !blackSecondPrinceVisible))) { return TRUE; } return FALSE; } Global void FinishGame(const Colour bwWinner) { char winString[19]; gamePaused = TRUE; sprintf(winString, "%s player wins!", (bwWinner == BLACK) ? "Black" : "White"); XtSetSensitive(firstGFX->undo, FALSE); Err3Dc(firstGFX, winString, TRUE); if (secondGFX != NULL) { XtSetSensitive(secondGFX->undo, FALSE); Err3Dc(secondGFX, winString, TRUE); } } Global void PrintMove( const Move *move ) { char *moveString = NULL; if (move != NULL) moveString = (char *)malloc(26); /* moveString is TRUE only if move != NULL too */ if (moveString) { Piece *piece, *enemy; Coord pos; piece = Board[ move->xyzAfter.zLevel] [ move->xyzAfter.yRank ] [ move->xyzAfter.xFile ]; CHECK( piece != NULL ); enemy = Muster[(piece->bwSide == WHITE) ? BLACK : WHITE] [ MusterIdx(king, 0) ]; pos = enemy->xyzPos; sprintf( moveString, "%s %c%c%c to %c%c%c%s", Piece2String( piece ), move->xyzBefore.zLevel + 'X', move->xyzBefore.xFile + 'a', move->xyzBefore.yRank + '1', move->xyzAfter.zLevel + 'X', move->xyzAfter.xFile + 'a', move->xyzAfter.yRank + '1', IsKingChecked( piece->bwSide ) ? " check!" : ""); /* Display the move: beep if * 1) the computer or * 2) the other player in a network game * moved or if * 3) the move resulted in a check * This is now changed so that there's no beep when the computer * moves 'cos it's so fast. */ Err3Dc( firstGFX, moveString, (/* (Computer() == bwToMove) || */ ( (secondGFX != NULL) && (bwToMove == BLACK) ) || ( IsKingChecked( piece->bwSide ))) ? TRUE : FALSE ); if ( secondGFX != NULL ) { Err3Dc( secondGFX, moveString, (bwToMove == WHITE) ? TRUE : FALSE ); } /* I think that this isn't allowed becase the string is * still needed by the label widget but it hasn't caused * any problems so far.. */ free(moveString); } else { /* Print something, even if out of memory.. */ if ( (Computer() == bwToMove) || ( (secondGFX != NULL) && (bwToMove == BLACK))) Err3Dc(firstGFX, "Opponent has moved", TRUE); else if ( (secondGFX != NULL) && (bwToMove == WHITE) ) Err3Dc(secondGFX, "Opponent has moved", TRUE); } } 3dchess-0.8.1.orig/src/Makefile100644 0 17 3763 6133212771 14332 0ustar rootkmemINSTALL=cp # This is the destination directory for 3Dc; you might like to # put it in /usr/games or equivalent but I think that the lastability # of 3Dc is too small without proper AI. Until the computer can # play properly, 3Dc remains a local installation. BINDIR=.. # The principle system configuration area. # Define -DHAVE_UNISTD_H if /usr/include/unistd.h exists # Define -DHAVE_ULIMIT_H if /usr/include/ulimit.h exists # Define -DFONTCURSOR if you don't have libXext or shape extensions. # This also requires removing the relevant libraries from LDLIBS below. # If your system doesn't have a unique define already, define one here. # Linux CONFIGS=-DHAVE_UNISTD_H -DHAVE_ULIMIT_H # OSF/Digital Unix/HPUX #CONFIGS=-fPIC -DHAVE_UNISTD_H -DHAVE_ULIMIT_H # Sun #CONFIGS=-fPIC -Wno-implicit VERSION=0.8.1 # The game preferences. # Define -DUNDO_ANY_MOVE to allow infinte undo; otherwise, you can only # undo your own moves. I think that it should always be defined; you # can send me opinions at mailto:paulh@euristix.ie PREFS=-DUNDO_ANY_MOVE CC=gcc #DEBUG=-g -Wall -DDEBUG DEBUG= COPTIONS=-O2 -fstrength-reduce -fpcc-struct-return -DVERSION=\"${VERSION}\" CFLAGS=${COPTIONS} ${DEBUG} ${CONFIGS} ${PREFS} -I../include LDOPTIONS= # LDLIBS should include the name of your X library path if not /usr/lib; # and I definitely recommend getting Xaw3d. The extra appearance doesn't # appear much but it looks much better when it does. # Linux LDLIBS=-L/usr/X11R6/lib -lXpm -lXaw3d -lXmu -lXext -lXt -lX11 # Sun #LDLIBS=-lXpm -lXaw -lXmu -lXext -lXt -lX11 -lm # There should be no need to configure anything below here OBJS =\ init.o \ main.o \ engine.o \ piece.o \ stack.o \ ai.o \ xif.o \ xnet.o \ callbaks.o \ DrawingA.o all:: 3Dc 3Dc:: ${OBJS} ${CC} -o $@ ${OBJS} ${LDOPTIONS} ${LDLIBS} install: 3Dc ${INSTALL} 3Dc ${BINDIR} archive: clean cd ../.. tar zcvf 3Dc-${VERSION}.tar.gz 3Dc clean: ${RM} *.o *~ TAGS ${RM} ../*~ ${RM} ../include/*~ tags: ${RM} TAGS etags *.c ../include/*.h 3dchess-0.8.1.orig/src/stack.c100644 0 17 5313 6120653022 14126 0ustar rootkmem/* * stack.c * * The move stack for 3Dc. */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #include #include #include #include "machine.h" #include "3Dc.h" #include "3DcErr.h" Global stack * StackNew(void) { stack *s; s = (stack *)malloc(sizeof(stack)); if (!CHECK( s != NULL )) return NULL; s->top = NULL; s->nSize = 0; return s; } Global void StackDelete(stack *s) { while(StackPop(s) != NULL) nop(); free(s); return; } Global void StackPush(stack *s, const Move *newMove) { struct stack_el *newEl; newEl = (struct stack_el *)malloc(sizeof(struct stack_el)); if (!CHECK( newEl != NULL )) return; newEl->mvt = (Move *)malloc(sizeof(Move)); if (!CHECK( newEl->mvt != NULL )) return; memcpy(newEl->mvt, newMove, sizeof(Move)); newEl->below = s->top; s->top = newEl; s->nSize++; return; } Global Move * StackPop(stack *s) { Move *oldMove; struct stack_el *oldEl; if (s->top == NULL) return NULL; oldMove = s->top->mvt; oldEl = s->top; s->top = s->top->below; s->nSize--; free(oldEl); return oldMove; } /* Don't delete returned value; it's still on the stack! */ Global Move * StackPeek(stack *s, int numMoves) { struct stack_el *oldEl; if (numMoves >= s->nSize) return NULL; for (oldEl = s->top; numMoves > 0; --numMoves) oldEl = oldEl->below; return oldEl->mvt; } #ifdef DEBUG Global void StackDump( stack *s ) { int i; struct stack_el *el; el = s->top; for (i=0; inSize; ++i) { printf("%i: %s at (%i,%i,%i) to (%i,%i,%i)\n",i, Piece2String( Board[el->mvt->xyzBefore.zLevel][el->mvt->xyzBefore.yRank][ el->mvt->xyzBefore.xFile] ), el->mvt->xyzBefore.xFile, el->mvt->xyzBefore.yRank, el->mvt->xyzBefore.zLevel, el->mvt->xyzAfter.xFile, el->mvt->xyzAfter.yRank, el->mvt->xyzAfter.zLevel); el = el->below; } } #endif /* DEBUG */ 3dchess-0.8.1.orig/src/DrawingA.c100644 0 17 12011 6116376335 14544 0ustar rootkmem/* DrawingA.c: The DrawingArea Widget Methods */ /* Copyright 1990, David Nedde * * Permission to use, copy, modify, and distribute this * software and its documentation for any purpose and without fee * is granted provided that the above copyright notice appears in all copies. * It is provided "as is" without express or implied warranty. */ #include #include #include #include #include "DrawingAP.h" static void Initialize(); static void Destroy(); static void Redisplay(); static void input_draw(); static void motion_draw(); static void resize_draw(); static char defaultTranslations[] = ": input() \n : input() \n : input() \n : input() \n : motion() \n : resize()"; static XtActionsRec actionsList[] = { { "input", (XtActionProc)input_draw }, { "motion", (XtActionProc)motion_draw }, { "resize", (XtActionProc)resize_draw }, }; /* Default instance record values */ static XtResource resources[] = { {XtNexposeCallback, XtCCallback, XtRCallback, sizeof(caddr_t), XtOffset(DrawingAreaWidget, drawing_area.expose_callback), XtRCallback, NULL }, {XtNinputCallback, XtCCallback, XtRCallback, sizeof(caddr_t), XtOffset(DrawingAreaWidget, drawing_area.input_callback), XtRCallback, NULL }, {XtNmotionCallback, XtCCallback, XtRCallback, sizeof(caddr_t), XtOffset(DrawingAreaWidget, drawing_area.motion_callback), XtRCallback, NULL }, {XtNresizeCallback, XtCCallback, XtRCallback, sizeof(caddr_t), XtOffset(DrawingAreaWidget, drawing_area.resize_callback), XtRCallback, NULL }, }; DrawingAreaClassRec drawingAreaClassRec = { /* CoreClassPart */ { (WidgetClass) &simpleClassRec, /* superclass */ "DrawingArea", /* class_name */ sizeof(DrawingAreaRec), /* size */ NULL, /* class_initialize */ NULL, /* class_part_initialize */ FALSE, /* class_inited */ Initialize, /* initialize */ NULL, /* initialize_hook */ XtInheritRealize, /* realize */ actionsList, /* actions */ XtNumber(actionsList), /* num_actions */ resources, /* resources */ XtNumber(resources), /* resource_count */ NULLQUARK, /* xrm_class */ FALSE, /* compress_motion */ FALSE, /* compress_exposure */ TRUE, /* compress_enterleave */ FALSE, /* visible_interest */ Destroy, /* destroy */ NULL, /* resize */ Redisplay, /* expose */ NULL, /* set_values */ NULL, /* set_values_hook */ XtInheritSetValuesAlmost, /* set_values_almost */ NULL, /* get_values_hook */ NULL, /* accept_focus */ XtVersion, /* version */ NULL, /* callback_private */ defaultTranslations, /* tm_table */ XtInheritQueryGeometry, /* query_geometry */ XtInheritDisplayAccelerator, /* display_accelerator */ NULL /* extension */ }, /* CoreClass fields initialization */ { /* change_sensitive */ XtInheritChangeSensitive }, /* SimpleClass fields initialization */ { 0, /* field not used */ }, /* DrawingAreaClass fields initialization */ }; WidgetClass drawingAreaWidgetClass = (WidgetClass)&drawingAreaClassRec; static void Initialize( request, new) DrawingAreaWidget request, new; { if (request->core.width == 0) new->core.width = 100; if (request->core.height == 0) new->core.height = 100; } static void Destroy( w) DrawingAreaWidget w; { XtRemoveAllCallbacks((Widget)w, XtNexposeCallback); XtRemoveAllCallbacks((Widget)w, XtNinputCallback); XtRemoveAllCallbacks((Widget)w, XtNmotionCallback); XtRemoveAllCallbacks((Widget)w, XtNresizeCallback); } /* Invoke expose callbacks */ static void Redisplay(w, event, region) DrawingAreaWidget w; XEvent *event; Region region; { XawDrawingAreaCallbackStruct cb; cb.reason = XawCR_EXPOSE; cb.event = event; cb.window = XtWindow(w); XtCallCallbacks((Widget)w, XtNexposeCallback, (char *)&cb); } /* Invoke resize callbacks */ static void resize_draw(w, event, args, n_args) DrawingAreaWidget w; XEvent *event; char *args[]; int n_args; { XawDrawingAreaCallbackStruct cb; cb.reason = XawCR_RESIZE; cb.event = event; cb.window = XtWindow(w); XtCallCallbacks((Widget)w, XtNresizeCallback, (char *)&cb); } /* Invoke input callbacks */ static void input_draw(w, event, args, n_args) DrawingAreaWidget w; XEvent *event; char *args[]; int n_args; { XawDrawingAreaCallbackStruct cb; cb.reason = XawCR_INPUT; cb.event = event; cb.window = XtWindow(w); XtCallCallbacks((Widget)w, XtNinputCallback, (char *)&cb); } /* Invoke motion callbacks */ static void motion_draw(w, event, args, n_args) DrawingAreaWidget w; XEvent *event; char *args[]; int n_args; { XawDrawingAreaCallbackStruct cb; cb.reason = XawCR_MOTION; cb.event = event; cb.window = XtWindow(w); XtCallCallbacks((Widget)w, XtNmotionCallback, (char *)&cb); } 3dchess-0.8.1.orig/src/xif.c100644 0 17 37415 6125614052 13644 0ustar rootkmem/* * The X interface for 3Dc */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "DrawingA.h" #include #include "pieces.xpm" #include "3Dc.h" Local GfxInfo GFX1; GfxInfo *firstGFX, *secondGFX; Global Boolean Init3DcGFX(int argc, char **argv) { XtAppContext app; XColor col, dummy; XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL); firstGFX = &GFX1; #if XlibSpecificationRelease > 5 firstGFX->mainWindow = XtOpenApplication(&app, "3Dc", NULL, 0, &argc, argv, NULL, topLevelShellWidgetClass, NULL, 0); #else /* XlibSpecificationRelease <= 5 */ firstGFX->mainWindow = XtAppInitialize(&app, "3Dc", NULL, 0, &argc, argv, NULL, NULL, 0); #endif /* XlibSpecificationRelease */ #ifdef FONTCURSOR firstGFX->monoGC = NULL; #endif /* FONTCURSOR */ firstGFX->gc = XDefaultGCOfScreen(XtScreen(firstGFX->mainWindow)); XSetFunction(XtDisplay(firstGFX->mainWindow), firstGFX->gc, GXcopy); firstGFX->whitePixel = WhitePixelOfScreen(XtScreen(firstGFX->mainWindow)); firstGFX->blackPixel = BlackPixelOfScreen(XtScreen(firstGFX->mainWindow)); /* Make two attempts at getting a grey colour. */ if (!XAllocNamedColor(XtDisplay(firstGFX->mainWindow), DefaultColormapOfScreen(XtScreen(firstGFX->mainWindow)), "grey", &col, &dummy)) { if (!XAllocNamedColor(XtDisplay(firstGFX->mainWindow), DefaultColormapOfScreen(XtScreen(firstGFX->mainWindow)), "light grey", &col, &dummy)) { firstGFX->greyPixel = firstGFX->blackPixel; } else firstGFX->greyPixel = col.pixel; } else firstGFX->greyPixel = col.pixel; if (InitPixmaps( firstGFX )) return FALSE; if (InitMainWindow( firstGFX )) return FALSE; if (InitBoardWindows( firstGFX )) return FALSE; XtRealizeWidget(firstGFX->mainWindow); return TRUE; } Global int InitPixmaps( GfxInfo *gfx ) { Colour bwCol; Title nTitle; int ret = 0; XpmAttributes attrs; XpmColorSymbol cols[2]; cols[0].name = strdup("foreground"); cols[0].value = NULL; cols[1].name = strdup("edge"); cols[1].value = NULL; attrs.valuemask = XpmColorSymbols; attrs.colorsymbols = cols; attrs.numsymbols = 2; for (bwCol = WHITE; bwCol <= BLACK; ++bwCol) { if (bwCol == WHITE) { cols[0].pixel = gfx->whitePixel; cols[1].pixel = gfx->blackPixel; } else { cols[0].pixel = gfx->blackPixel; cols[1].pixel = gfx->whitePixel; } for (nTitle = king; nTitle <= pawn; ++nTitle) { ret |= XpmCreatePixmapFromData(XtDisplay(gfx->mainWindow), XRootWindowOfScreen(XtScreen(gfx->mainWindow)), XPMpixmaps[nTitle], &(gfx->face[bwCol][nTitle]), bwCol == WHITE ? &(gfx->mask[nTitle]) : NULL, &attrs); } } free(cols[0].name); free(cols[1].name); if (ret != 0) { printf("Error reading XPM images.\n"); return 1; } return 0; } Global int InitMainWindow( GfxInfo *gfx ) { Widget form, /* remark, */ /* undo, */ resign, musterTitle /* muster */; int bg; form = XtVaCreateManagedWidget("form", formWidgetClass, gfx->mainWindow, NULL); gfx->remark = XtVaCreateManagedWidget("remark", labelWidgetClass, form, XtNlabel, "Welcome to 3Dc", XtNright, XtChainRight, XtNwidth, 175, NULL); /* Eliminate border */ XtVaGetValues(gfx->remark, XtNbackground, &bg, NULL); XtVaSetValues(gfx->remark, XtNborder, bg, NULL); gfx->undo = XtVaCreateManagedWidget("Undo", commandWidgetClass, form, XtNlabel, "Undo", XtNfromVert, gfx->remark, NULL); resign = XtVaCreateManagedWidget("Resign", commandWidgetClass, form, XtNlabel, "Resign", XtNfromVert, gfx->remark, XtNfromHoriz, gfx->undo, NULL); musterTitle = XtVaCreateManagedWidget("mtitle", labelWidgetClass, form, XtNlabel, "Muster", XtNfromVert, resign, NULL); /* Eliminate border */ XtVaGetValues(musterTitle, XtNbackground, &bg, NULL); XtVaSetValues(musterTitle, XtNborder, bg, NULL); gfx->muster = XtVaCreateManagedWidget("muster", drawingAreaWidgetClass, form, XtNfromVert, musterTitle, XtNwidth, 175, XtNheight, 250, NULL); gfx->font = XLoadQueryFont(XtDisplay(gfx->muster), "fixed"); XSetFont(XtDisplay(gfx->muster), gfx->gc, gfx->font->fid); XtAddCallback(gfx->undo, XtNcallback, UndoMove, NULL); XtAddCallback(resign, XtNcallback, ResignGame, NULL); XtAddCallback(gfx->muster, XtNresizeCallback, DrawMuster, NULL); XtAddCallback(gfx->muster, XtNexposeCallback, DrawMuster, NULL); return 0; } Global int InitBoardWindows( GfxInfo *gfx ) { Widget curShell; char *boardName; int zCounter, x, y; boardName = (char *)malloc(14); if ( boardName == NULL ) exit(1); sprintf(boardName, "3Dc board ?"); /* These equation determine the best place for the second * board by either placing the windows corner-to-corner * or (if there isn't enough screen space) halving the * difference between the top left and the place where the * last screen will be (i.e. one screen from the bottom right). * The equation ignores window decorations but that isn't much. */ x = MIN( (XWidthOfScreen( XtScreen( gfx->mainWindow ) ) - (XPM_SIZE * FILES))/2, XPM_SIZE * FILES ); y = MIN( (XHeightOfScreen( XtScreen( gfx->mainWindow ) ) - (XPM_SIZE * RANKS))/2, XPM_SIZE * RANKS ); for (zCounter = 0; zCounter < LEVELS; ++zCounter) { boardName[10] = zCounter + 'X'; curShell = XtVaAppCreateShell( boardName, "3Dc", applicationShellWidgetClass, XtDisplay( gfx->mainWindow ), XtNx, x * zCounter, XtNy, y * zCounter, NULL); gfx->board[zCounter] = XtVaCreateManagedWidget(boardName, drawingAreaWidgetClass, curShell, XtNbackground, gfx->whitePixel, XtNwidth, XPM_SIZE * FILES, XtNheight, XPM_SIZE * RANKS, NULL); XtAddCallback(gfx->board[zCounter], XtNinputCallback, MouseInput, NULL); XtAddCallback(gfx->board[zCounter], XtNexposeCallback, DrawBoard, NULL); XtAddCallback(gfx->board[zCounter], XtNresizeCallback, DrawBoard, NULL); XtRealizeWidget(curShell); gfx->width [zCounter] = XPM_SIZE * FILES; gfx->height[zCounter] = XPM_SIZE * RANKS; XtPopup(curShell, XtGrabNone); } return 0; } Global void PieceDisplay(const Piece *piece, const Boolean bDraw) { XRectangle rect = {0, 0, XPM_SIZE, XPM_SIZE}; int centX, centY; GfxInfo *gfx; if (!piece) return; gfx = firstGFX; while ( gfx != NULL ) { rect.width = gfx->width [piece->xyzPos.zLevel] / FILES; rect.height = gfx->height[piece->xyzPos.zLevel] / RANKS; XSetForeground(XtDisplay(gfx->mainWindow), gfx->gc, gfx->greyPixel); XSetClipRectangles(XtDisplay(gfx->mainWindow), gfx->gc, SQ_POS_X(gfx, piece->xyzPos.zLevel, piece->xyzPos.xFile), SQ_POS_Y(gfx, piece->xyzPos.zLevel, piece->xyzPos.yRank), &rect, 1, Unsorted); if (((piece->xyzPos.xFile + piece->xyzPos.yRank) % 2) == 1) { XFillRectangle(XtDisplay(gfx->mainWindow), XtWindow(gfx->board[piece->xyzPos.zLevel]), gfx->gc, SQ_POS_X(gfx, piece->xyzPos.zLevel, piece->xyzPos.xFile), SQ_POS_Y(gfx, piece->xyzPos.zLevel, piece->xyzPos.yRank), rect.width, rect.height); } else { XClearArea(XtDisplay(gfx->mainWindow), XtWindow(gfx->board[piece->xyzPos.zLevel]), SQ_POS_X(gfx, piece->xyzPos.zLevel, piece->xyzPos.xFile), SQ_POS_Y(gfx, piece->xyzPos.zLevel, piece->xyzPos.yRank), rect.width, rect.height, FALSE); } if (piece->bVisible && bDraw) { centX = (rect.width - XPM_SIZE) /2; centY = (rect.height - XPM_SIZE) /2; XSetClipOrigin(XtDisplay(gfx->mainWindow), gfx->gc, SQ_POS_X(gfx, piece->xyzPos.zLevel, piece->xyzPos.xFile) + centX, SQ_POS_Y(gfx, piece->xyzPos.zLevel, piece->xyzPos.yRank) + centY); XSetClipMask(XtDisplay(gfx->mainWindow), gfx->gc, gfx->mask[piece->nName]); XCopyArea(XtDisplay(gfx->mainWindow), gfx->face[piece->bwSide][piece->nName], XtWindow(gfx->board[piece->xyzPos.zLevel]), gfx->gc, 0, 0, XPM_SIZE, XPM_SIZE, SQ_POS_X(gfx, piece->xyzPos.zLevel, piece->xyzPos.xFile) + centX, SQ_POS_Y(gfx, piece->xyzPos.zLevel, piece->xyzPos.yRank) + centY); } if ( gfx == firstGFX ) gfx = secondGFX; else gfx = NULL; } return; } Global void Draw3DcBoard( void ) { Level z; for (z = 0; z < LEVELS; z++) DrawBoard(firstGFX->board[z], NULL, NULL); if ( secondGFX != NULL ) { for (z = 0; z < LEVELS; z++) DrawBoard(secondGFX->board[z], NULL, NULL); } return; } Global int Err3Dc( const GfxInfo *gfx, const char *pszLeader, const Boolean beep ) { char *err; /* * All strings are designed to be printed thus: * printf("That piece %s.\n"); */ error_t ERRORS[] = { {E3DcSIMPLE, "may not move thus"}, {E3DcLEVEL, "may not move vertically"}, {E3DcCHECK, "would place your king in check"}, {E3DcDIST, "may not move that far"}, {E3DcINVIS, "is not currently on the board"}, {E3DcBLOCK, "is blocked from moving there"}, {E3DcMOVED, "has already moved"} }; if (beep) XBell(XtDisplay(gfx->mainWindow), 0); if (pszLeader == NULL) { XtVaSetValues(gfx->remark, XtNlabel, "", NULL); return 0; } err = (char *)malloc(strlen(pszLeader) + 40); if (!err) return 1; sprintf(err, pszLeader, ERRORS[n3DcErr].pszErrStr); XtVaSetValues(gfx->remark, XtNlabel, err, NULL); free(err); return 0; } /* Prompt for piece type to which to promote the pawn */ Global void PiecePromote(Piece *piece) { Widget dialog, list; GfxInfo *gfx; #define PROMOTABLES 8 static char *types[] = { "Queen", "Rook", "Bishop", "Knight", "Princess", "Galley", "Abbey", "Cannon", NULL }; if ( Computer() == piece->bwSide ) { piece->nName = queen; /* This saves many headaches */ PieceDisplay( piece, TRUE ); return; } PauseGame(); /* Suspend thinking */ gfx = firstGFX; if ( (secondGFX != NULL) && (piece->bwSide == BLACK) ) gfx = secondGFX; dialog = XtCreatePopupShell("Promotion", transientShellWidgetClass, gfx->mainWindow, NULL, 0); list = XtVaCreateManagedWidget("list", listWidgetClass, dialog, XtNlist, types, XtNnumberStrings, PROMOTABLES, XtNverticalList, TRUE, XtNforceColumns, TRUE, XtNdefaultColumns, 1, NULL); XtAddCallback(list, XtNcallback, PromotePiece, (XtPointer)piece); XtManageChild(dialog); return; } /* Update the muster count for the given type/colour in the muster window */ Global void UpdateMuster(Colour bwSide, Title nType, Bool redisplay) { int count, i, curX, curY; Dimension mWidth, mHeight; char cnt[2] = {' ', '0'}; GfxInfo *gfx; gfx = firstGFX; while ( gfx != NULL ) { XSetClipMask(XtDisplay(gfx->muster), gfx->gc, None); XSetForeground(XtDisplay(gfx->muster), gfx->gc, gfx->blackPixel); count = 0; for (i = 0; i < titleCount[nType]; ++i) { if (Muster[bwSide][MusterIdx(nType, i)]->bVisible) ++count; } cnt[0] = '0' + (count / 10); cnt[1] = '0' + (count % 10); if (cnt[0] == '0') cnt[0] = ' '; XtVaGetValues(gfx->muster, XtNheight, &mHeight, XtNwidth, &mWidth, NULL); curY = (((mHeight / 5) - XPM_SIZE) / 2) + ((mHeight % 5) / 2) + 2; if (nType == pawn) { curX = (((mWidth / 2) - XPM_SIZE) / 2) + ((mWidth % 2) / 2) + 10; if (bwSide == BLACK) curX += mWidth / 2; curY += (2 * (mHeight / 5)); } else if (bwSide == WHITE) { curX = (((mWidth / 5) - XPM_SIZE) / 2) + ((mWidth % 5) / 2) + 10; curX += (nType % 5) * (mWidth / 5); curY += ((mHeight / 5) * (nType / 5)); } else /* bwSide == BLACK */ { curX = (((mWidth / 5) - XPM_SIZE) / 2) + ((mWidth % 5) / 2) + 10; curX += (nType % 5) * (mWidth / 5); curY += (4 * bwSide * (mHeight / 5)) - ((mHeight / 5) * (nType / 5)); } XClearArea(XtDisplay(gfx->muster), XtWindow(gfx->muster), curX, curY - gfx->font->ascent, XTextWidth(gfx->font, "MM", 2), gfx->font->ascent + gfx->font->descent, redisplay); XDrawString(XtDisplay(gfx->muster), XtWindow(gfx->muster), gfx->gc, curX, curY, cnt, 2); if ( gfx == firstGFX ) gfx = secondGFX; else gfx = NULL; } return; } 3dchess-0.8.1.orig/src/xnet.c100644 0 17 5027 6116376335 14017 0ustar rootkmem/* * The TCP interface for 3Dc */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #include #include #include #include #include #include "machine.h" /* AutoInclude all necessary files */ #include "3Dc.h" #include Local GfxInfo GFX2; Global Boolean Open2ndDisplay(const char *displayName) { XtAppContext app; XColor col, dummy; int x; Display *display; secondGFX = &GFX2; app = XtCreateApplicationContext(); x = 0; display = XtOpenDisplay(app, displayName, "3Dc", "3Dc", NULL, 0, &x, NULL); secondGFX->mainWindow = XtAppCreateShell("3Dc", "3Dc", applicationShellWidgetClass, display, NULL, 0); #ifdef FONTCURSOR secondGFX->monoGC = NULL; #endif /* FONTCURSOR */ secondGFX->gc = XDefaultGCOfScreen(XtScreen(secondGFX->mainWindow)); XSetFunction(display, secondGFX->gc, GXcopy); secondGFX->whitePixel = WhitePixelOfScreen(XtScreen(secondGFX->mainWindow)); secondGFX->blackPixel = BlackPixelOfScreen(XtScreen(secondGFX->mainWindow)); /* Make two attempts at getting a grey colour. */ if (!XAllocNamedColor(display, DefaultColormapOfScreen(XtScreen(secondGFX->mainWindow)), "grey", &col, &dummy)) { if (!XAllocNamedColor(display, DefaultColormapOfScreen(XtScreen(secondGFX->mainWindow)), "light grey", &col, &dummy)) secondGFX->greyPixel = secondGFX->blackPixel; else secondGFX->greyPixel = col.pixel; } else secondGFX->greyPixel = col.pixel; if (InitPixmaps( secondGFX )) return 1; if (InitMainWindow( secondGFX )) return 1; if (InitBoardWindows( secondGFX )) return 1; XtRealizeWidget(secondGFX->mainWindow); return 0; } 3dchess-0.8.1.orig/src/callbaks.c100644 0 17 46005 6125606616 14634 0ustar rootkmem/* * The callbacks for the X interface for 3Dc */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "DrawingA.h" #include #include "local.h" #include "machine.h" #include "3Dc.h" Local GfxInfo * Widget2GfxInfo(Widget w) { if ((secondGFX != NULL) && (XtDisplay(secondGFX->mainWindow) == XtDisplay(w))) return secondGFX; return firstGFX; } /* Draw one level of the board */ Global void DrawBoard(Widget w, XtPointer client, XtPointer call) { unsigned curX, curY, minX = 0, minY = 0, maxX = 7, maxY = 7; Level boardNum; XEvent *event; GfxInfo *gfx; Dimension width, height; gfx = Widget2GfxInfo(w); for (boardNum = 0; boardNum < LEVELS; ++boardNum) { if (w == gfx->board[boardNum]) break; } if (!CHECK(boardNum != LEVELS)) return; width = gfx->width [boardNum] / FILES; height = gfx->height[boardNum] / RANKS; /* call is NULL if called manually */ if ( call != NULL ) { event = ((XawDrawingAreaCallbackStruct *)call)->event; if ( event->type == ConfigureNotify ) { gfx->width [boardNum] = event->xconfigure.width; gfx->height[boardNum] = event->xconfigure.height; } width = gfx->width [boardNum] / FILES; height = gfx->height[boardNum] / RANKS; /* If call is null, then the function is called by us * and the whole board (ignoring expose-rects) is to be redrawn. * Similarly, the whole board is redrawn when resizing. */ if (event->type == Expose) { minX = event->xexpose.x / width; minY = event->xexpose.y / height; maxX = MIN(FILES-1, 1+ minX + (event->xexpose.width / width)); maxY = MIN(RANKS-1, 1+ minY + (event->xexpose.height / height)); } } XSetForeground(XtDisplay(w), gfx->gc, gfx->greyPixel); for (curY = minY; curY <= maxY; ++curY) { for (curX = minX; curX <= maxX; ++curX) { if ( Board[boardNum][curY][curX] == NULL ) { XRectangle rect = {0, 0, XPM_SIZE, XPM_SIZE}; rect.width = width; rect.height = height; XSetClipRectangles(XtDisplay(gfx->mainWindow), gfx->gc, SQ_POS_X(gfx, boardNum, curX), SQ_POS_Y(gfx, boardNum, curY), &rect, 1, Unsorted); /* White in the bottom right... */ if ( ((curX + curY) %2) == 1 ) XFillRectangle(XtDisplay(w), XtWindow(w), gfx->gc, SQ_POS_X(gfx, boardNum, curX), SQ_POS_Y(gfx, boardNum, curY), width, height); else XClearArea(XtDisplay(w), XtWindow(w), SQ_POS_X(gfx, boardNum, curX), SQ_POS_Y(gfx, boardNum, curY), width, height, FALSE); } else /* if (Board[boardNum][curY][curX] != NULL) */ { PieceDisplay(Board[boardNum][curY][curX], TRUE); } } } return; } /* If you want to use the cursor font, define FONTCURSOR. It's not * really worth it, 'cos the pixmap cursors look better */ /* #define FONTCURSOR */ Global void MouseInput(Widget w, XtPointer client, XtPointer call) { XADCS *data; Piece *piece; int moved; Level boardNum; int xWinRel, yWinRel, dummy1, dummy2, dummy3; Window win, dummy; XColor fore, back; Local Cursor cursor = 0; Pixmap pixmap; GfxInfo *gfx; Local Coord src; #ifdef FONTCURSOR if (!cursor) cursor = XCreateFontCursor(XtDisplay(w), XC_exchange); #endif /* FONTCURSOR */ gfx = Widget2GfxInfo(w); data = (XADCS *)call; if (data->event->type == ButtonPress) { /* Getting boardNum is easy for ButtonPress */ for (boardNum = 0; (w != gfx->board[boardNum]) && (boardNum < LEVELS); ++boardNum); if (boardNum == LEVELS) return; /* Error! */ src.xFile = data->event->xbutton.x / (gfx->width [boardNum]/FILES); src.yRank = data->event->xbutton.y / (gfx->height[boardNum]/RANKS); src.zLevel = boardNum; if (Board[src.zLevel][src.yRank][src.xFile] == NULL) { src.zLevel = LEVELS; return; } #ifndef FONTCURSOR /* Define the colours */ if (Board[src.zLevel][src.yRank][src.xFile]->bwSide == BLACK) { fore.pixel = gfx->whitePixel; back.pixel = gfx->blackPixel; } else { fore.pixel = gfx->blackPixel; back.pixel = gfx->whitePixel; } XQueryColor(XtDisplay(w), DefaultColormapOfScreen(XtScreen(w)), &fore); XQueryColor(XtDisplay(w), DefaultColormapOfScreen(XtScreen(w)), &back); /* Create the pixmap */ pixmap = XCreatePixmap(XtDisplay(w), XtWindow(w), XPM_SIZE, XPM_SIZE, 1); /* Create the GC */ if (gfx->monoGC == NULL) { gfx->monoGC = XCreateGC(XtDisplay(w), pixmap, 0, NULL); XSetFunction(XtDisplay(w), gfx->monoGC, GXcopy); } XCopyPlane(XtDisplay(w), gfx->face[WHITE] [Board[src.zLevel] [src.yRank] [src.xFile]->nName], pixmap, gfx->monoGC, 0, 0, XPM_SIZE, XPM_SIZE, 0, 0, 1); /* Now we can create the cursor */ cursor = XCreatePixmapCursor(XtDisplay(w), pixmap, gfx->mask[Board[src.zLevel] [src.yRank] [src.xFile]->nName], &fore, &back, 15, 15); XFreePixmap(XtDisplay(w), pixmap); #endif /* FONTCURSOR */ /* Now let's change the cursor */ for (boardNum = 0; boardNum < LEVELS; ++boardNum) { XDefineCursor(XtDisplay(w), XtWindow(w), cursor); } } else if (data->event->type == ButtonRelease) { /* First of all - if we didn't pick up a piece, there's no * point in continuing */ if (src.zLevel == LEVELS) return; for (boardNum = 0; boardNum < LEVELS; ++boardNum) { /* Now we have to restore the cursor */ XUndefineCursor(XtDisplay(w), XtWindow(w)); } /* For ButtonRelease, we have to take care of the release being * in another board */ for (boardNum = 0; boardNum < LEVELS; ++boardNum) { /* Before I added in pixmap cursors, I needed only run * XQueryPointer once, but now I must do it once per * board. Even if I define FONTCURSOR. Presumably * I changed something about XQueryPointer and searching * through many levels of children, but I can't find what * it was. O well. */ XQueryPointer(XtDisplay(w), XtWindow(XtParent(gfx->board[boardNum])), &dummy, &win, &dummy1, &dummy2, &xWinRel, &yWinRel, &dummy3); if (win == XtWindow(gfx->board[boardNum])) break; } #ifndef FONTCURSOR XFreeCursor(XtDisplay(w), cursor); cursor = 0; #endif if (boardNum == LEVELS) { Err3Dc(gfx, "Can't move outside boards", TRUE); return; } /* First - ignore clicks on the one square */ if ((src.xFile == (xWinRel / (gfx->width [boardNum]/FILES))) && (src.yRank == (yWinRel / (gfx->height[boardNum]/RANKS))) && (src.zLevel == boardNum)) { Err3Dc(gfx, NULL, FALSE); return; } piece = Board[src.zLevel][src.yRank][src.xFile]; if ((!piece) || (!piece->bVisible)) { Err3Dc(gfx, "There's no piece there!", FALSE); return; } else if ( (piece->bwSide == Computer()) || ( (secondGFX != NULL) && ( ((gfx == firstGFX) && (piece->bwSide == BLACK)) || (((gfx == secondGFX) && (piece->bwSide == WHITE))) ) ) ) { Err3Dc(gfx, "That's not your piece!", FALSE); return; } else if (piece->bwSide != bwToMove) { Err3Dc(gfx, "It's not your go yet!", FALSE); return; } moved = PieceMove(piece, xWinRel / (gfx->width [boardNum]/FILES), yWinRel / (gfx->height[boardNum]/RANKS), boardNum); if (moved) { PieceDisplay(piece, TRUE); UpdateMuster(piece->bwSide, piece->nName, TRUE); PrintMove( StackPeek( MoveStack, 0 ) ); bwToMove = (bwToMove == WHITE ? BLACK : WHITE); } /* End "this was a legal move" */ else Err3Dc(gfx, "That piece %s.", TRUE); } /* End "this was a buttonrelease" */ } Global void ResignGame(Widget w, XtPointer client, XtPointer call) { Widget dialog, form, cont, restart, quit; XtPopdownID popMeDown; Dimension x, y; GfxInfo *gfx; PauseGame(); /* Suspend thinking */ gfx = Widget2GfxInfo(w); /* This is one smart function. XtCreatePopupShell will create * an unmanaged widget if it doesn't already exist, or do nothing * otherwise. In combination with XtCallbackPopdown, this makes * dialogs a doddle (kudos to the Xt people - everything else handy * about programming in X seems to be from Motif, this is nice for * a change). * * Addendum: * Hmm. It appears that I spoke hastily. In my version of Xt, * XtCallbackPopdown appears to do nothing; at least, I can't get * it to do anything. So I've written cancelDialog, which does * exactly the same thing (well, actually it works, you know, * pops the dialog down :). */ XtVaGetValues(gfx->mainWindow, XtNx, &x, XtNy, &y, NULL); dialog = XtVaCreatePopupShell("Resign Game?", transientShellWidgetClass, gfx->mainWindow, XtNx, x + 50, XtNy, y + 50, NULL); form = XtVaCreateManagedWidget("form", formWidgetClass, dialog, NULL); cont = XtVaCreateManagedWidget("Continue", commandWidgetClass, form, XtNlabel, "Continue", NULL); restart = XtVaCreateManagedWidget("Restart", commandWidgetClass, form, XtNlabel, "Restart", XtNfromHoriz, cont, NULL); quit = XtVaCreateManagedWidget("Quit", commandWidgetClass, form, XtNlabel, "Quit", XtNfromHoriz, restart, NULL); popMeDown = (XtPopdownID)XtMalloc(sizeof(XtPopdownIDRec)); popMeDown->shell_widget = dialog; popMeDown->enable_widget = gfx->mainWindow; XtAddCallback(cont, XtNcallback, CancelDialog, popMeDown); XtAddCallback(restart, XtNcallback, Restart3Dc, popMeDown); XtAddCallback(quit, XtNcallback, Quit3Dc, NULL); XtManageChild(dialog); return; } Global void UndoMove(Widget w, XtPointer client, XtPointer call) { GfxInfo *gfx; gfx = Widget2GfxInfo(w); /* This fearsome conditional disallows undoing any but your * own moves. I don't know if it should be in or not; * thus it is conditionally compiled */ #ifndef UNDO_ANY_MOVE if ( ((Computer() != NOCOL) && (bwToMove != Computer())) || ( (secondGFX != NULL) && ( ((gfx == secondGFX) && (bwToMove == BLACK)) || ((gfx == firstGFX) && (bwToMove == WHITE)) ) ) ) { Err3Dc( gfx, "You can only undo your own moves!", FALSE ); return; } #endif /* UNDO_ANY_MOVE */ if (PieceUndo() == FALSE) { Err3Dc(gfx, "Nothing to undo!", FALSE); return; } /* Because we don't know what type was done, update them all */ DrawMuster(gfx->muster, NULL, NULL); if (secondGFX != NULL) DrawMuster(secondGFX->muster, NULL, NULL); /* TODO: * pop up dialog asking for permission to undo * in multi-display games */ /* Undo means that the same guy goes again... */ bwToMove = (bwToMove == WHITE ? BLACK : WHITE); return; } /* Draw the muster window */ Global void DrawMuster(Widget w, XtPointer client, XtPointer call) { Dimension musterWidth, musterHeight; int leftX, curX, curY, x; GfxInfo *gfx; /* On which display are we working? */ gfx = Widget2GfxInfo( w ); XtVaGetValues(w, XtNheight, &musterHeight, XtNwidth, &musterWidth, NULL); /* Resize the remark label */ XtVaSetValues(gfx->remark, XtNwidth, musterWidth, NULL); /* Factor in centring */ leftX = curX = (musterWidth % 5) / 2 + ((musterWidth / 5) - XPM_SIZE) / 2; curY = (musterHeight % 5) / 2 + ((musterHeight / 5) - XPM_SIZE) / 2; XSetForeground(XtDisplay(w), gfx->gc, gfx->blackPixel); /* Draw white royalty */ for (x = 0; x < 5; ++x) { XSetClipOrigin(XtDisplay(w), gfx->gc, curX, curY); XSetClipMask(XtDisplay(w), gfx->gc, gfx->mask[x]); XCopyArea(XtDisplay(w), gfx->face[WHITE][x], XtWindow(w), gfx->gc, 0, 0, XPM_SIZE, XPM_SIZE, curX, curY); UpdateMuster(WHITE, x, FALSE); curX += musterWidth / 5; } curX = leftX; curY += musterHeight / 5; /* Draw white nobility */ for (x = 0; x < 5; ++x) { XSetClipOrigin(XtDisplay(w), gfx->gc, curX, curY); XSetClipMask(XtDisplay(w), gfx->gc, gfx->mask[x+5]); XCopyArea(XtDisplay(w), gfx->face[WHITE][x+5], XtWindow(w), gfx->gc, 0, 0, XPM_SIZE, XPM_SIZE, curX, curY); UpdateMuster(WHITE, x+5, FALSE); curX += musterWidth / 5; } curX = ((musterWidth % 2) / 2) + (((musterWidth / 2) - XPM_SIZE) / 2); curY += musterHeight / 5; /* Draw pawns */ for (x = 0; x < 2; ++x) { if (curX < 0) curX = 0; XSetClipOrigin(XtDisplay(w), gfx->gc, curX, curY); XSetClipMask(XtDisplay(w), gfx->gc, gfx->mask[pawn]); XCopyArea(XtDisplay(w), gfx->face[x][pawn], XtWindow(w), gfx->gc, 0, 0, XPM_SIZE, XPM_SIZE, curX, curY); UpdateMuster(x, pawn, FALSE); curX += musterWidth / 2; } curX = leftX; curY += musterHeight / 5; /* Draw black nobility */ for (x = 0; x < 5; ++x) { XSetClipOrigin(XtDisplay(w), gfx->gc, curX, curY); XSetClipMask(XtDisplay(w), gfx->gc, gfx->mask[x+5]); XCopyArea(XtDisplay(w), gfx->face[BLACK][x+5], XtWindow(w), gfx->gc, 0, 0, XPM_SIZE, XPM_SIZE, curX, curY); UpdateMuster(BLACK, x+5, FALSE); curX += musterWidth / 5; } curX = leftX; curY += musterHeight / 5; /* Draw BLACK royalty */ for (x = 0; x < 5; ++x) { XSetClipOrigin(XtDisplay(w), gfx->gc, curX, curY); XSetClipMask(XtDisplay(w), gfx->gc, gfx->mask[x]); XCopyArea(XtDisplay(w), gfx->face[BLACK][x], XtWindow(w), gfx->gc, 0, 0, XPM_SIZE, XPM_SIZE, curX, curY); UpdateMuster(BLACK, x, FALSE); curX += musterWidth / 5; } return; } /* The promotion callback */ Global void PromotePiece(Widget w, XtPointer client, XtPointer call) { Piece *piece; piece = (Piece *)client; PieceDisplay(piece, FALSE); switch (((XawListReturnStruct *)call)->list_index) { case 0: piece->nName = queen; break; case 1: piece->nName = rook; break; case 2: piece->nName = bishop; break; case 3: piece->nName = knight; break; case 4: piece->nName = princess; break; case 5: piece->nName = galley; break; case 6: piece->nName = abbey; break; case 7: piece->nName = cannon; break; } PieceDisplay(piece, TRUE); UpdateMuster(piece->bwSide, piece->nName, TRUE); XtPopdown(XtParent(w)); XtDestroyWidget(XtParent(w)); ResumeGame(); /* Resume thinking */ return; } Global void Restart3Dc(Widget w, XtPointer client, XtPointer call) { int i; if (w) { XtPopdownID popMeDown; popMeDown = (XtPopdownID)client; XtPopdown(popMeDown->shell_widget); XtDestroyWidget(popMeDown->shell_widget); XtSetSensitive(popMeDown->enable_widget, TRUE); XtFree((char *)popMeDown); } XtSetSensitive(firstGFX->undo, TRUE); if ( secondGFX != NULL ) XtSetSensitive(secondGFX->undo, TRUE); /* Destroy all the pieces */ for (i = 0; i < PIECES; ++i) { PieceDelete(Muster[WHITE][i]); PieceDelete(Muster[BLACK][i]); } /* Free the move stack */ StackDelete(MoveStack); /* Recreate 3Dc, with pieces in the right places and an empty move stack */ Init3Dc(); bwToMove = WHITE; ResumeGame(); /* Refresh the screen */ Draw3DcBoard(); for (i = 0; i < TITLES; ++i) { UpdateMuster(WHITE, i, TRUE); UpdateMuster(BLACK, i, TRUE); } return; } Global void CancelDialog(Widget w, XtPointer client, XtPointer call) { XtPopdownID popMeDown; popMeDown = (XtPopdownID)client; XtPopdown(popMeDown->shell_widget); XtDestroyWidget(popMeDown->shell_widget); XtSetSensitive(popMeDown->enable_widget, TRUE); XtFree((char *)popMeDown); ResumeGame(); /* Most dialogs are modal, requiring the use of this line */ return; } Global void Quit3Dc(Widget w, XtPointer client, XtPointer call) { /* XCloseDisplay frees fonts, pixmaps, everything---cool! */ XtDestroyApplicationContext( XtWidgetToApplicationContext( firstGFX->mainWindow ) ); firstGFX->mainWindow = NULL; if (secondGFX != NULL) { XtDestroyApplicationContext( XtWidgetToApplicationContext( secondGFX->mainWindow ) ); } return; } 3dchess-0.8.1.orig/src/ai.c100644 0 17 43214 6132222146 13436 0ustar rootkmem/* * ai.c * * An implementation of computer intelligence (you wot?) for 3Dc. */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995,1996 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #ifdef DEBUG #include #endif /* DEBUG */ #include #include #include #include "machine.h" #include "3Dc.h" #ifndef MAX #define MAX(a,b) ((a) < (b) ? (b) : (a)) #define MIN(a,b) ((a) > (b) ? (b) : (a)) #endif /* MAX */ #define BEST_STACKS 5 Local struct stackList { stack *stacks[BEST_STACKS]; int ratings[BEST_STACKS]; } bestMoves = { { NULL, NULL, NULL, NULL, NULL }, { INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN } }; Local int values[ TITLES ] = { 26, 42, 22, 10, 25, /* Royalty */ 45, 21, 12, 24, 15, /* Nobility */ 6 /* Pawn */ }; Local void PushMove(Move *move, int value) { int i; if ( value == INT_MIN ) return; for ( i = 0; (bestMoves.stacks [i] != NULL) && (bestMoves.ratings[i] > value) && (i < BEST_STACKS); ++i ) nop(); if ( i == BEST_STACKS ) { free( move ); return; } if ( bestMoves.ratings[i] == value ) { StackPush( bestMoves.stacks[i], move ); free( move ); } else { int j; j = BEST_STACKS-1; /* Get rid of the lowest level (if it falls off the end) */ if (bestMoves.stacks[j] != NULL) StackDelete( bestMoves.stacks[j] ); /* Move all the lower levels down */ for (; j > i; --j) { bestMoves.stacks [j] = bestMoves.stacks [j-1]; bestMoves.ratings[j] = bestMoves.ratings[j-1]; } /* Create the new stack */ bestMoves.stacks[i] = StackNew(); StackPush( bestMoves.stacks[i], move ); bestMoves.ratings[i] = value; } return; } /* This function circumvents the problem of negative ratings * by adding to all ratings enough to make the smallest rating == 0 */ Local void FixMoves( void ) { int i, add; for ( i = (BEST_STACKS -1); (bestMoves.stacks[i] == NULL) && (i >= 0); --i ) nop(); if ((i < 0) || (bestMoves.ratings[i] >= 0)) return; add = -(bestMoves.ratings[i]); for (; i >= 0; --i) bestMoves.ratings[i] += add; } Local Move * PopMove( void ) { Move *ret; int stacks, randStack, randMove, randBase, randNum; if ( bestMoves.stacks[0] == NULL ) return NULL; /* * This algorithm works by generating a number randBase on which to base a * call to random(): think of it as a die with randBase sides. randBase * it dependant on the rating of the moves at the current level and * on the level itself. It may be that the number of moves at the current * level will also be a factor in later version. (A "level" is all moves * with equal rating. Only the top BEST_STACKS levels are remembered). * Then the generated random number is reverse engineered into a level. * Finally a purely random choice of move within that level is made. */ if ( bestMoves.ratings[0] == INT_MAX ) { /* If this move wins the game then do it unconditionally */ randMove = 0; randStack = 0; } else { for ( stacks = 0, randBase = 0; ( bestMoves.stacks[stacks] != NULL ) && ( stacks < BEST_STACKS ) ; ++stacks ) randBase += ((BEST_STACKS-stacks) * bestMoves.ratings[stacks]); randNum = random()%randBase; for ( randStack = stacks-1; (randStack > 0) && (randNum > 0); --randStack ) { randNum -= (( BEST_STACKS - randStack ) * bestMoves.ratings[randStack] ); } randMove = random()%bestMoves.stacks[randStack]->nSize; D( printf( "Choosing move %i from a stack of size %i\n", randMove+1, bestMoves.stacks[randStack]->nSize ) ); } ret = StackPeek( bestMoves.stacks[randStack], randMove ); CHECK((ret->xyzBefore.zLevel != 3) && (ret->xyzAfter.zLevel != 3)); /* This defeats the opaqueness of stack.c but it's easy */ /* It just clears the one move we've just made from the move stack */ /* If the chosen move was the top of the stack.. */ if (randMove == 0) { /* Don't free the move: it's "ret" and still in use! */ StackPop( bestMoves.stacks[randStack] ); /* If there is only the one move then we remove the stack */ if ( bestMoves.stacks[randStack]->nSize == 0 ) { StackDelete( bestMoves.stacks[randStack] ); while ( ((randStack+1) < BEST_STACKS) && (bestMoves.stacks[randStack+1] != NULL) ) { bestMoves.stacks [randStack] = bestMoves.stacks [randStack+1]; bestMoves.ratings[randStack] = bestMoves.ratings[randStack+1]; ++randStack; } bestMoves.stacks[randStack] = NULL; bestMoves.ratings[randStack] = INT_MIN; } } /* We used a second or later move */ else { int i; struct stack_el *el, *temp; el = bestMoves.stacks[randStack]->top; for (i = 1; (i < randMove) && (el->below != NULL); ++i) { el = el->below; } if (!CHECK((el->below != NULL) && (el->below->mvt == ret))) { /* Hopefully this can never happen */ } else { temp = el->below; el->below = temp->below; bestMoves.stacks[randStack]->nSize--; free( temp ); } } return ret; } Local int RateMove( Move *move, Colour bwSide ) { int rating = 0; Colour bwEnemy; Coord xyzPos; Piece *moving, *storing; bwEnemy = ( bwSide == WHITE ) ? BLACK : WHITE; /* Rate taking king */ if (move->pVictim == Muster[ bwEnemy ][ MusterIdx( king, 0 )]) return INT_MAX; /* Fake the move for simple lookahead */ moving = Board[ move->xyzBefore.zLevel ] [ move->xyzBefore.yRank ] [ move->xyzBefore.xFile ]; storing = Board[ move->xyzAfter.zLevel ] [ move->xyzAfter.yRank ] [ move->xyzAfter.xFile ]; if (!CHECK( moving != NULL )) return INT_MIN; /* Rate saving king */ /* It might be more efficient to put the IsKingChecked() call * inside the move faked below but that would mean nasty code * duplication re: finding king coords and so on. This code * is easier to maintain. */ if ( FakeMoveAndIsKingChecked( Muster[ bwSide ][ MusterIdx( king, 0 )], move->xyzAfter.xFile, move->xyzAfter.yRank, move->xyzAfter.zLevel )) return INT_MIN; /* Fake the move */ Board[ move->xyzBefore.zLevel ] [ move->xyzBefore.yRank ] [ move->xyzBefore.xFile ] = NULL; Board[ move->xyzAfter.zLevel ] [ move->xyzAfter.yRank ] [ move->xyzAfter.xFile ] = moving; if ( storing != NULL ) storing->bVisible = FALSE; /* Rate check */ xyzPos = (Muster[ bwEnemy ][ MusterIdx( king, 0 )])->xyzPos; if ( SquareThreatened( bwSide, xyzPos.xFile, xyzPos.yRank, xyzPos.zLevel) != NULL ) rating += values[ king ]; /* Rate danger: if there's a chance of being captured in the new pos. */ xyzPos = move->xyzAfter; if ( SquareThreatened( bwEnemy, xyzPos.xFile, xyzPos.yRank, xyzPos.zLevel) != NULL ) rating -= (values[ moving->nName ] /2); /* Undo the fake */ Board[ move->xyzBefore.zLevel ] [ move->xyzBefore.yRank ] [ move->xyzBefore.xFile ] = moving; Board[ move->xyzAfter.zLevel ] [ move->xyzAfter.yRank ] [ move->xyzAfter.xFile ] = storing; if ( storing != NULL ) storing->bVisible = TRUE; /* Rate capture */ if (( move->pVictim != NULL ) && ( move->pVictim->bwSide == bwEnemy )) { int i; rating += values[ move->pVictim->nName ]; /* Rate evasion: if there's a chance of any friendly piece * being captured in the old pos but not in the new (this isn't * an authorative check and needs to be enhanced). */ for ( i = 0; i < PIECES; ++i ) { if ( Muster[ bwSide ][ i ]->bVisible && SquareThreatened( bwEnemy, Muster[ bwSide ][ i ]->xyzPos.xFile, Muster[ bwSide ][ i ]->xyzPos.yRank, Muster[ bwSide ][ i ]->xyzPos.zLevel ) == move->pVictim ) rating += (values[ Muster[ bwSide ][ i ]->nName ] /2); } } /* Rate special moves */ /* En passant and castling not yet possible for computer */ if (( move->pVictim != NULL ) && ( move->pVictim->bwSide == bwSide)) rating += 10; /* Castling */ if (( move->xyzAfter.yRank == (bwSide == WHITE ? RANKS-1 : 0) ) && ( moving->nName == pawn )) rating += values[queen]; /* Promotion */ /* Note the horrible magic numbers below */ if ( (ABS( move->xyzAfter.yRank - move->xyzBefore.yRank ) == 2) && ( moving->nName == pawn )) rating += 1; /* Two-forward by pawn: the computer doesn't * usually like opening its attack routes otherwise */ /* Rate position; distance forward (should be proximity to * enemy king except for pawns */ if ( bwSide == WHITE ) rating += move->xyzAfter.yRank - move->xyzBefore.yRank; else rating += 7 - move->xyzAfter.yRank + move->xyzBefore.yRank; return rating; } Global Boolean GenMove(const Colour bwSide, Move **ret) { Local int pieceIdx = 0; stack *moves; Move *thisMove; /* First clear out any old moves */ if (pieceIdx == 0) { int i; for ( i = 0; (bestMoves.stacks[i] != NULL) && (i < BEST_STACKS); ++i) { StackDelete(bestMoves.stacks[i]); bestMoves.stacks[i] = NULL; bestMoves.ratings[i] = INT_MIN; } } if ( Muster[bwSide][pieceIdx]->bVisible ) { moves = FindAllMoves( Muster[bwSide][pieceIdx] ); if (moves != NULL) { # ifdef NOTDEF StackDump( moves ); # endif /* DEBUG */ while ( (thisMove = StackPop( moves )) != NULL ) { PushMove( thisMove, RateMove( thisMove, bwSide ) ); } StackDelete( moves ); } } if (++pieceIdx == PIECES) { FixMoves(); *ret = PopMove(); pieceIdx = 0; return TRUE; } *ret = NULL; return FALSE; } /* This tries again for a move in case the last one failed for some reason */ Global Boolean GenAltMove(const Colour bwSide, Move **ret) { *ret = PopMove(); return TRUE; } /* Creates a stack of legal moves that this piece can take in this go */ stack * FindAllMoves(Piece *piece) { stack *moves; Move move; Colour bwEnemy; int x, y, z; #define CURX (piece->xyzPos.xFile) #define CURY (piece->xyzPos.yRank) #define CURZ (piece->xyzPos.zLevel) moves = StackNew(); if (moves == NULL) return NULL; bwEnemy = ((piece->bwSide == WHITE) ? BLACK : WHITE); move.xyzBefore = piece->xyzPos; if (piece->nName == knight) { for (y = MAX(0, CURY -2); y < MIN(RANKS, CURY +3); y++) { if (y == CURY) continue; for (x = MAX(0, CURX -2); x < MIN(FILES, CURX +3); x++) { if (x == CURX) continue; if (ABS(CURX-x) == ABS(CURY-y)) continue; if ((Board[CURZ][y][x] == NULL) || (Board[CURZ][y][x]->bwSide == bwEnemy)) { move.xyzAfter.xFile = x; move.xyzAfter.yRank = y; move.xyzAfter.zLevel = CURZ; move.pVictim = Board[CURZ][y][x]; move.nHadMoved = piece->bHasMoved; if (!FakeMoveAndIsKingChecked( piece, x, y, CURZ )) StackPush(moves, &move); } /* End valid move */ } /* End x loop */ } /* End y loop */ } /* End knight */ else if (piece->nName == cannon) { for (z = 0; z < LEVELS; z++) { if (z == CURZ) continue; for (y = MAX( 0, CURY -3 ); y < MIN( RANKS, CURY +4 ); y++) { if (y == CURY) continue; for (x = MAX( 0, CURX -3 ); x < MIN( FILES, CURX +4 ); x++) { if (x == CURX) continue; if ((ABS(CURX-x) == ABS(CURY-y)) || (ABS(CURX-x) == ABS(CURZ-z)) || (ABS(CURY-y) == ABS(CURZ-z))) continue; if ((Board[z][y][x] == NULL) || (Board[z][y][x]->bwSide == bwEnemy)) { move.xyzAfter.xFile = x; move.xyzAfter.yRank = y; move.xyzAfter.zLevel = z; move.pVictim = Board[z][y][x]; move.nHadMoved = piece->bHasMoved; if (!FakeMoveAndIsKingChecked( piece, x, y, z )) StackPush(moves, &move); } /* End valid move */ } /* End x loop */ } /* End y loop */ } /* End z loop */ } /* End cannon */ else if (piece->nName == pawn) /* Don't bother searching for en passant */ { y = ((piece->bwSide == WHITE) ? 1 : -1); for (x = MAX(0, CURX-1); x < MIN(FILES, CURX+2); ++x) { /* Due to the complexity of the conditional this time, * I've opted for aborting when illegal instead of * proceeding when legal. */ if ((x == CURX) && (Board[CURZ][CURY+y][CURX] != NULL)) continue; if ( (x != CURX) && ((Board[CURZ][CURY + y][x] == NULL) || ((Board[CURZ][CURY + y][x])->bwSide != bwEnemy)) ) continue; move.xyzAfter.xFile = x; move.xyzAfter.yRank = CURY + y; move.xyzAfter.zLevel = CURZ; move.pVictim = Board[CURZ][CURY + y][x]; move.nHadMoved = piece->bHasMoved; if (!FakeMoveAndIsKingChecked(piece, x, CURY+y, CURZ)) StackPush(moves, &move); /* This next conditional is for the two-forward move: * it only happens when the previous attempt was the one-forward * move and makes assumptions based on that fact. */ if ( (x==CURX) && (piece->bHasMoved == FALSE) && (Board[CURZ][CURY + y+y][CURX] == NULL) ) { move.xyzAfter.yRank += y; if (!FakeMoveAndIsKingChecked(piece, CURX, CURY+y+y, CURZ)) StackPush(moves, &move); } } /* End x loop */ } /* End pawn */ else { int d, dist; Piece *pEncountered; /* * The king and prince can only move one square; * all others can move MAX(FILES,RANKS)-1. * For a regular board, this is 7. (Not 8: If you moved 8 * in any direction you would be off the edge of the board) */ if ((piece->nName == king) || (piece->nName == prince)) dist = 1; else dist = MAX(FILES, RANKS) -1; for (z = -1; z <= 1; ++z) { /* * Cater for pieces that can't change level. */ if (((piece->nName == prince) || (piece->nName == princess) || (piece->nName == abbey) || (piece->nName == galley)) && (z != 0)) continue; for (y = -1; y <= 1; ++y) { for (x = -1; x <= 1; ++x) { if ((x==0) && (y==0) && (z==0)) continue; /* * Cater for the pieces that can only move * horizontally/vertically. */ if (((piece->nName == rook) || (piece->nName == galley)) && !HORZ(x, y)) continue; /* * Cater for the pieces that can only move * diagonally. */ else if (((piece->nName == bishop) || (piece->nName == abbey)) && !DIAG(x, y)) continue; for (d = 1; d <= dist; ++d) { pEncountered = TraverseDir(piece, x, y, z, d); if (IsMoveLegal(piece, pEncountered)) { move.xyzAfter = pEncountered->xyzPos; move.pVictim = pEncountered; move.nHadMoved = piece->bHasMoved; /* Check for putting own king in check */ if (!FakeMoveAndIsKingChecked(piece, pEncountered->xyzPos.xFile, pEncountered->xyzPos.yRank, pEncountered->xyzPos.zLevel)) StackPush(moves, &move); } if (pEncountered != SQUARE_EMPTY) break; /* No point on continuing in this direction if * we've hit a piece or the edge of the board.. */ } /* End d loop */ } /* End x loop */ } /* End y loop */ } /* End z loop */ } return moves; #undef CURX #undef CURY #undef CURZ } 3dchess-0.8.1.orig/README100644 0 17 3121 6115371115 12745 0ustar rootkmem3Dc: Three dimensional chess Code written by Paul Hicks, copyright 1995,1996 You can copy and use this software as described by the GNU copyleft; see the file GPL. No infringement of intellectual copyright is intended; I did not invent this game and make no claims that I did. I just coded it. Game designed and invented by Bernard Kennedy, copyright 1993. We (Paul and Bernard) request that our names be mentioned in any work you derive from the algorithms within 3Dc; I (Paul) request that my name be mentioned in a work you derive from any part of the code for 3Dc. The latest version of this tar file, and of the rules page, can be accessed at http://mbmartin.bevc.blacksburg.va.us/~paulh/3Dc/3Dc.html For plain ftp, go to ftp://mbmartin.bevc.blacksburg.va.us/pub/3Dc/3Dc.tar.gz Command line params: -play: Tells the computer to play. Requires a following parameter, either black or white, which tells the computer which colour to play. -altdisplay -ad: Tells the computer that you are playing as the white player in a network game. It requires one additional parameter---the display to pop the black player's windows up on. The other display must allow connections, via xhost or xauth. Most standard X command line parameters (-geometry, -foreground, etc.) work too. There are no 3Dc-specific resources but normal Xt resources (foreground, geometry, etc.) work. By default, the muster (main) window's resource name is "3Dc"; the board windows are "3Dc board {X|Y|Z}", depending on the board. See file:3Dc-rules.html for 3Dc rules. Paul Hicks 3dchess-0.8.1.orig/GPL100644 0 17 43076 5740320440 12465 0ustar rootkmem GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. 3dchess-0.8.1.orig/3Dc-rules.html100644 0 17 11774 6113141241 14542 0ustar rootkmem 3Dc rules

3Dc rules

Be careful - this can be heavy reading unless you have a board (or the 3Dc program) in front of you.
3Dc is played with three chess boards arranged one above another. The pieces on the middle board are the standard chess pieces; the other two boards have the following pieces (with equivalent "normal" pieces parenthesized):
  • Prince (king)
  • Princess (queen)
  • Abbey (bishop) (should have been abbot, but the plastic piece was too hard to make, apparently)
  • Cannon (knight)
  • Galley (rook)

These pieces all move exacly like their equivalent pieces in chess, with the exception of the cannon (which we'll come to later).

A brief note on naming: just as squares in chess are named a1, f3, and so on, squares in 3Dc are named Xa1, Yd7, etc., with X being the top board, Y the middle, and Z the bottom.

Back on the middle board..
The knight moves as per the usual game of chess. The other court pieces on the middle board, as well as moving as they usually do, move in the third dimension. Imagining a straight line from one square in any direction gives you twenty-six directions; along the three axes (6), at forty five degrees to each axis (12), and at forty five degrees to each of those lines (8). It's easier to imagine if you draw the boards, or if you hold one (real) chess board above another. If you've got a head for coordinates, then you should realise that square Yd4 is adjacent to Xd4, Xd5, Ze3, Zc4 and lots others.

In this manner, the king may move to one of twenty six squares, if it is in a central position. It can move to the eight squares as per normal chess, the nine squares above it, and the nine below it. Obviously, it may not move onto a board which does not exist.

The queen moves in exactly the same manner. Because the queen may move any distance, special care must be taken when moving from the top to bottom boards (or vice versa). If moving diagonally up (or down) two levels, it must take care to move two squares across in the appropriate direction. So Xb2-Zd4 is legal, but Zd4-Xe6 is not (it moved two boards up, one rank forward, and two files right; it must move two in every direction in which it is moving). It may, of course, move directly up, in which case there is no problem.

The bishop may move diagonally (as per usual), or diagonally and vertically. That is, starting in square Yd4, it may move to any of the squares Zc3, Zc5, Ze3, Ze5, Xc3, Xc5, Xe3, Xe5, or the squares to which it would normally move if playing chess on the Y board.

The rook moves, as you might expect, at forty five degrees to how the bishop moves. This allows the rooks to come into play much earlier in 3Dc than in normal chess, as it can move from, say, Ya1 to Za2 (assuming the pawn which belongs there has vacated the square), thence to Ya3 and a threatening position. It can also move directly up or down, to which the bishop has no analogue.

The only remaining piece to describe is the cannon. Just as the knight moves two spaces in one direction and then one space in a perpendicular direction, the cannon moves three spaces in one direction, two in a perpendicular direction, and one in a direction perpendicular to both previous steps. As there are a maximum of two boards vertically above (or below) the cannon, the first component of the move must be on the same board; but after that, the cannon may move two boards up and one square across, or two squares across and one board up. The cannon must obviously change board every time it is moved, and it moves a long way; it is the most common cause of anguish to beginner players. To combat players who are more experienced, many who have played only a few games initially attempt to take all their opponents' cannons, temporarily neglecting other aims in the game.

Special moves in the game are preserved. Every pawn may be promoted to any piece except a king or prince; en passant is a legal move. The pawn captures with a diagonal move but may only move forward when not capturing. The pawn moves 1 or 2 spaces, according to the normal chess rules, and cannot change levels (until it is promoted). Castling is legal, but only kings and rooks may castle (i.e. princes and galleys may not). Castling has the usual provisos (neither piece may have moved yet, and the king may never be in check while castling). Checking the king must be announced as usual.

The aim of 3Dc is also slightly more complex than in chess. Mating the opponent's king will win the game, as will capturing both his princes. You do not check a prince and thus do not have to declare when you threaten one. Forking the king and prince is a popular move, as the king must be moved out of check (of course, capturing the offending piece is a better solution..).

3dchess-0.8.1.orig/include/ 40755 0 17 0 6132224066 13417 5ustar rootkmem3dchess-0.8.1.orig/include/3Dc.h100644 0 17 13040 6125616161 14317 0ustar rootkmem/* * 3Dc.h * * Definitions file for 3Dc */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #ifndef __3Dc_H #define __3Dc_H #include /* For all other X stuff */ #include "local.h" #include "machine.h" /***************************************************************************** * A miscellany of useful tidbits */ #ifndef ABS #define ABS(a) ((a) < 0 ? -(a) : (a)) #endif /* ABS */ /* Returns from pieceMayMove */ #define CASTLE 2 #define EnPASSANT 3 #define PROMOTE 4 typedef enum { /* Misnomers (but handy) */ king, queen, bishop, knight, rook, /* Royalty */ prince, princess, abbey, cannon, galley, /* Nobility */ pawn, none } Title; #define TITLES 11 Global int titleCount[TITLES]; #define PIECES 48 typedef enum { NOCOL = -1, WHITE, BLACK } Colour; #define COLOURS 2 typedef struct { unsigned xFile :3, yRank :3, zLevel :2; } Coord; typedef int File; #define FILES 8 typedef int Rank; #define RANKS 8 typedef int Level; #define LEVELS 3 /* Directions */ typedef int Dir; #define LEFT -1 #define RIGHT 1 #define FORW 1 /* if colour is black => -1 */ #define BACK -1 /* if colour is black => +1 */ #define UP 1 #define DOWN -1 #define NODIR 0 #define RANDDIR() ((random()%3)-1) #define HORZ(x, y) ( ((x)==0) ^ ((y)==0) ) #define DIAG(x, y) ((x)!=0 && (ABS(x)==ABS(y))) #define HORZ2D(x, y, z) (HORZ(x, y) && (z)==0) #define DIAG2D(x, y, z) (DIAG(x, y) && (z)==0) /* Don't have to check for z==0 in 2nd line below bcs at least one of * x,y is 0 so the check is implicit */ #define HORZ3D(x, y, z) ((HORZ(x, y) && \ ((ABS(z)==ABS(x)) || \ (ABS(z)==ABS(y)) || ((z)==0))) || \ ((x)==0 && (y)==0 && (z)!=0)) #define DIAG3D(x, y, z) (DIAG(x, y) && \ ((z)==0 || ABS(z)==ABS(x))) /* * End miscellany ****************************************************************************/ /***************************************************************************** * Piece definitions for all pieces */ typedef struct { Coord xyzPos; Colour bwSide; Title nName; unsigned bVisible :1, bHasMoved:1; /* For king, rook, pawn only */ } Piece; Global Piece *SQUARE_INVALID, *SQUARE_EMPTY; Global Boolean IsMoveLegal( const Piece *, const Piece *); Global Boolean PieceMayMove(Piece *, const File, const Rank, const Level); Global Boolean PieceMove(Piece *, const File, const Rank, const Level); Global Boolean PieceUndo(void); Global Piece *SquareThreatened(Colour, const File, const Rank, const Level); Global Boolean IsKingChecked(Colour); Global Boolean FakeMoveAndIsKingChecked( Piece *, const File, const Rank, const Level); Global Piece *TraverseDir(const Piece *, Dir, Dir, Dir, unsigned); Global Piece *PieceNew(const Title, const File, const Rank, const Level, const Colour); Global void PieceDelete(Piece *); /* * End piece definitions ****************************************************************************/ /***************************************************************************** * The move-stack (for undos, checking for en passant, etc) */ typedef struct { Coord xyzBefore; Coord xyzAfter; Piece *pVictim; /* Status of bHasMoved before move. Relevant to Kings, Rooks, and Pawns. * TRUE, FALSE, PROMOTE, CASTLE or EnPASSANT. */ int nHadMoved; } Move; struct stack_el { Move *mvt; struct stack_el *below; }; typedef struct { int nSize; struct stack_el *top; } stack; Global stack *StackNew(void); Global void StackDelete(stack *); Global void StackPush(stack *, const Move *); Global Move *StackPop(stack *); Global Move *StackPeek(stack *, int); /* Returns move n places down stack. Do not free! */ #ifdef DEBUG Global void StackDump(stack *); #endif /* DEBUG */ Global stack *FindAllMoves(Piece *); Global stack *MoveStack; /* * End of the move stack ****************************************************************************/ /****************************************************************************/ Global Piece *Board[LEVELS][RANKS][FILES]; Global Piece *Muster[COLOURS][PIECES]; /* Database of all pieces */ Global Colour bwToMove; #include "x3Dc.h" #include "3DcErr.h" /* And finally the function prototypes for the game itself */ Global Boolean Init3Dc(void); Global int MusterIdx(const Title, const int); Global char *Piece2String( Piece * ); Global Colour Computer(void); Global void PauseGame(void); Global void ResumeGame(void); Global Boolean IsGamePaused(void); Global Boolean IsGameFinished(void); Global void FinishGame(Colour); Global void PrintMove( const Move * ); /* ComputerPlay stuff */ Global Boolean GenMove(const Colour, Move **); Global Boolean GenAltMove(const Colour, Move **); #endif /* __3Dc_h */ 3dchess-0.8.1.orig/include/3DcErr.h100644 0 17 2510 6104456511 14746 0ustar rootkmem/* * This file defines everything to do with error-handling * that is unique to 3Dc. */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #ifndef __3DcErr_h #define __3DcErr_h extern int n3DcErr; typedef enum { E3DcSIMPLE, E3DcLEVEL, E3DcCHECK, E3DcDIST, E3DcINVIS, E3DcBLOCK, E3DcMOVED } Error; typedef struct { Error nErrNum; char *pszErrStr; } error_t; /* * All strings are designed to be printed thus: * printf("That piece %s.\n"); */ /* To be defined by interface */ extern int Err3Dc(const GfxInfo *, const char *, const Boolean); #endif /* __3DcErr_h */ 3dchess-0.8.1.orig/include/machine.h100644 0 17 2665 6133212244 15276 0ustar rootkmem/* * This file is supposed to get over any machine-dependent * problems. Some, like ulimit(2) are fixed in the kernel (usually); * the rest are up to us users to work out */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #ifndef _3DC_MACHINE_H #define _3DC_MACHINE_H #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_ULIMIT_H #include #endif #ifdef __alpha__ #include #endif /* __alpha__ */ #ifdef SYSV #define random() rand() #define srandom(a) srand(a) #endif /* SYSV */ #ifdef sun #define XtSetLanguageProc(a,b,c) #endif /* sun */ #ifdef __GNUC__ #define INLINE __inline__ #else #define INLINE #endif /* __GNUC__ */ #endif /* _3DC_MACHINE_H */ 3dchess-0.8.1.orig/include/DrawingA.h100644 0 17 2645 5735344476 15410 0ustar rootkmem/* DrawingA.h - Public Header file */ /* Copyright 1990, David Nedde * * Permission to use, copy, modify, and distribute this * software and its documentation for any purpose and without fee * is granted provided that the above copyright notice appears in all copies. * It is provided "as is" without express or implied warranty. */ /* Define widget's class pointer and strings used to specify resources */ #ifndef _XawDrawingArea_h #define _XawDrawingArea_h #define XADCS XawDrawingAreaCallbackStruct /* Resources ADDED to label widget: Name Class RepType Default Value ---- ----- ------- ------------- exposeCallback Callback Pointer NULL inputCallback Callback Pointer NULL motionCallback Callback Pointer NULL resizeCallback Callback Pointer NULL */ extern WidgetClass drawingAreaWidgetClass; typedef struct _DrawingAreaClassRec *DrawingAreaWidgetClass; typedef struct _DrawingAreaRec *DrawingAreaWidget; /* Resource strings */ #define XtNexposeCallback "exposeCallback" #define XtNinputCallback "inputCallback" #define XtNmotionCallback "motionCallback" #define XtNresizeCallback "resizeCallback" typedef struct _XawDrawingAreaCallbackStruct { int reason; XEvent *event; Window window; } XawDrawingAreaCallbackStruct; /* Reasons */ #define XawCR_EXPOSE 1 #define XawCR_INPUT 2 #define XawCR_MOTION 3 #define XawCR_RESIZE 4 #endif /* _XawDrawingArea_h */ 3dchess-0.8.1.orig/include/DrawingAP.h100644 0 17 2526 5735344476 15526 0ustar rootkmem/* DrawingArea Private header file */ /* Copyright 1990, David Nedde * * Permission to use, copy, modify, and distribute this * software and its documentation for any purpose and without fee * is granted provided that the above copyright notice appears in all copies. * It is provided "as is" without express or implied warranty. */ #ifndef _XawDrawingAreaP_h #define _XawDrawingAreaP_h #include "DrawingA.h" #ifdef X11_R3 #include #else #include #endif /* The drawing area's contribution to the class record */ typedef struct _DrawingAreaClassPart { int ignore; } DrawingAreaClassPart; /* Drawing area's full class record */ typedef struct _DrawingAreaClassRec { CoreClassPart core_class; SimpleClassPart simple_class; DrawingAreaClassPart drawing_area; } DrawingAreaClassRec; extern DrawingAreaClassRec drawingAreaClassRec; /* Resources added and status of drawing area widget */ typedef struct _XsDrawingAreaPart { /* Resources */ XtCallbackList expose_callback; XtCallbackList input_callback; XtCallbackList motion_callback; XtCallbackList resize_callback; } DrawingAreaPart; /* Drawing area's instance record */ typedef struct _DrawingAreaRec { CorePart core; SimplePart simple; DrawingAreaPart drawing_area; } DrawingAreaRec; #endif /* _XawDrawingAreaP_h */ 3dchess-0.8.1.orig/include/local.h100644 0 17 1740 6104743504 14763 0ustar rootkmem/* * local.h * * Application-independant defines. */ #ifndef _LOCAL_H #define _LOCAL_H #ifndef Boolean #define Boolean int #endif /* Boolean */ #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif /* True */ #ifndef NULL #define NULL 0 #endif /* NULL */ #ifndef ABS #define ABS(a) ((a) < 0 ? -(a) : (a)) #endif /* ABS */ #ifndef MAX #define MAX(a,b) ((a) < (b) ? (b) : (a)) #define MIN(a,b) ((a) > (b) ? (b) : (a)) #endif /* MAX */ /* Abstractions */ #define Global extern #define Local static #ifdef DEBUG # define D(debug_code) debug_code # define CHECK(bool) ((bool)?1:(fprintf(stderr, "Assertion failed on line %i of %s\n", __LINE__, __FILE__),0)) #else /* DEBUG */ # define D(debug_code) # define CHECK(bool) ((bool)?1:0) #endif /* DEBUG */ /* The empty function (for empty loops etc.) */ #define nop() /* The fall-through case for switch statements */ #define FallThrough() #ifdef GCC #define Inline inline #else /* GCC */ #define Inline #endif /* GCC */ #endif /* _LOCAL_H */ 3dchess-0.8.1.orig/include/x3Dc.h100644 0 17 6470 6114412252 14471 0ustar rootkmem/* * x3Dc.h * * Definitions file for 3Dc X interface */ /* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: paulh@euristix.ie */ #ifndef __x3Dc_H #define __x3Dc_H #include /* For all other X stuff */ #include "local.h" /***************************************************************************** * Platform-dependent graphics info */ typedef struct { GC #ifndef FONTCURSOR monoGC, /* Mono GC for cursor */ #endif /* FONTCURSOR */ gc; /* Graphics context */ Widget mainWindow, /* Toplevel widget */ muster, /* Display area */ remark, /* Message area */ undo, /* Undo button */ board[LEVELS]; /* Playing areas */ Dimension width[LEVELS], height[LEVELS]; /* Sizes of playing areas */ Pixel blackPixel, whitePixel, greyPixel; /* Colours */ Pixmap face[COLOURS][TITLES], mask[TITLES]; /* Pixmaps */ XFontStruct *font; /* The display font */ } GfxInfo; Global GfxInfo *firstGFX, *secondGFX; #define XPM_SIZE 32 /* * End of graphics info ****************************************************************************/ /****************************************************************************/ /* Functions */ /* Interface stuff */ Global int Init3DcGFX(int, char **); Global int InitPixmaps( GfxInfo * ); Global int InitMainWindow( GfxInfo * ); Global int InitBoardWindows( GfxInfo * ); Global void Draw3DcBoard(void); Global void UpdateMuster(Colour, Title, Boolean); Global void PieceDisplay(const Piece *, const Boolean); Global void PiecePromote( Piece * ); /* 2nd interface stuff */ Global Boolean Open2ndDisplay(const char *); /* Callbacks */ Global void DrawBoard(Widget, XtPointer, XtPointer); Global void DrawMuster(Widget, XtPointer, XtPointer); Global void ResignGame(Widget, XtPointer, XtPointer); Global void MouseInput(Widget, XtPointer, XtPointer); Global void PromotePiece(Widget, XtPointer, XtPointer); Global void CancelDialog(Widget, XtPointer, XtPointer); Global void UndoMove(Widget, XtPointer, XtPointer); Global void Restart3Dc(Widget, XtPointer, XtPointer); Global void Quit3Dc(Widget, XtPointer, XtPointer); /* Useful macros */ #define SQ_POS_X(gfx, boardNum, x) \ (((gfx->width[(boardNum)]%FILES) / 2) + \ ((gfx->width[(boardNum)]/FILES) * (x))) #define SQ_POS_Y(gfx, boardNum, y) \ (((gfx->height[(boardNum)]%RANKS) / 2) + \ ((gfx->height[(boardNum)]/RANKS) * (y))) #endif /* __x3Dc_h */ 3dchess-0.8.1.orig/include/pieces.xpm100644 0 17 41767 5757423640 15564 0ustar rootkmem/* 3Dc, a game of 3-Dimensional Chess Copyright (C) 1995 Paul Hicks This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. E-Mail: P.Hicks@net-cs.ucd.ie */ /* XPM */ static char *XPMpixmaps[11][37] = { { /* king */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " ", " ", " ", " .. ", " .##. ", " .. .####. .. ", " ...##... .#xx#. ...##... ", " .########...##...########. ", " .############xx############. ", " .########xx###xx###xx########. ", " .#####xxx#xx####xx#xxx#####. ", " .####xx#####x##x#####xx####. ", " .###xx#####x##x#####xx###. ", " .####xx####x##x####xx####. ", " .####xxx##x##x##xxx####. ", " .######xxxxxxxxxx######. ", " .########xxxx########. ", " .####################. ", " .##################. ", " .################. ", " ..############.. ", " .###xxxxxxxx###. ", " .##############. ", " .################. ", " .################. ", " ................ ", " ", " ", " ", " ", " " }, { /* queen */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " .. .. ", " .##. .##. ", " .. .##. .##. .. ", " .##. .#. .#. .##. ", " .##. .#. .#. .##. ", " .#. .##. .##. .#. ", " .##. .##. .##. .#. ", " .##. .##. .###. .##. ", " .###. .###. .. .###. .##. ", " .###. .###..##.####. .###. ", " .###. .#####..#####. .###. ", " .####.#####. .#####.###. ", " .####x#####x..x#####x###. ", " .##########xx#########. ", " .#####################. ", " .#####################. ", " .#####################. ", " .###################. ", " ..###############.. ", " ...#########... ", " ......... ", " " }, { /* bishop */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " . ", " .#. . ", " .###.x. ", " .###.x. ", " .#####xx. ", " .#######xx. ", " .#######xx. ", " .####x####xx. ", " .####x####xx. ", " .#####x#####xx. ", " .##xxxxxxx##xx. ", " .######x######xx. ", " .######x######xx. ", " .######x######xx. ", " .###########xx. ", " .###########xx. ", " .#########xx. ", " .#########xx. ", " .#######xx. ", " .#######.. ", " .##xxxxx##. ", " .#########. ", " .#########. ", " ..#xxxxxxx#.. ", " .#############. ", " .###############. ", " .#################. ", " .#################. ", " ................. ", " ", " " }, { /* knight */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " ", " . .. ", " .#. .##.. ", " .##.#####.. ", " .######x###. ", " .######xx##. ", " .##########x. ", " .#x#######x##. ", " .##xx#########. ", " .############xx#. ", " .###############. ", " .#############x##. ", " .#####.########.. ", " .#####..#########. ", " .#x##..##########. ", " .#.. .##########. ", " . .###########. ", " .###########. ", " .###########. ", " .############. ", " .#############. ", " .#############. ", " .#############. ", " .############x. ", " .#########xxxx##. ", " .################. ", " .xxxxxxxxxxxxxx. ", " .################. ", " .##################. ", " .................. ", " " }, { /* rook */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " ", " ", " ... ... ... .. ", " .###..###..###..##. ", " .###..###..###..##. ", " .###..###..###..##. ", " .###..###..###..##. ", " .###..###..###..##. ", " .#################. ", " .###############. ", " .#xxxxxxxxxxxxx#. ", " .###############. ", " ...#########... ", " .#########. ", " .#########. ", " .#########. ", " .###########. ", " .###########. ", " .###########. ", " .#############. ", " .#############. ", " .#############. ", " .###############. ", " .###############. ", " ..#################.. ", " .#####################. ", " .#######################. ", " .#######################. ", " ....................... ", " ", " " }, { /* prince */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " .. ", " ..##.. ", " .######. ", " .########. ", " .####.... ", " .##.. ", " .##. ", " ...####.... ", " .###########. ", " .###########. ", " ....#############.... ", " .####xxxxxxxxxxxxx####. ", " .##x#############x##. ", " .##xxxxxxxxxxxxx##. ", " ...###########... ", " ..#######.. ", " .#####. ", " .#####. ", " .#######. ", " .#######. ", " .#########. ", " .#########. ", " .#######. ", " .#######. ", " .#########. ", " ..###xxx###.. ", " ...#############... ", " .####xxxxxxxxxxx####. ", " .###################. ", " ................... ", " " }, { /* princess */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " ", " . ", " ..#. . ", " .####.#. ", " ..#######. ", " ....########. ", " .####x#######. ", " .#####xx####. ", " .######xxxx. ", " .#########. ", " .#######. ", " .#xx##. ", " ...#x###x#... ", " .#####xxx#####. ", " .###############. ", " .###############. ", " ....########... ", " .######. ", " .######. ", " .######. ", " .######. ", " ..#xxxx#.. ", " ..##########.. ", " ..##############.. ", " .##################. ", " .########x###x#######. ", " .##########xxx#########. ", " .######################. ", " ...................... ", " ", " " }, { /* abbey */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " ", " . ", " .#. ", " .###. ", " .###. ", " .#####. ", " .#######. ", " .###x###. ", " .####x####. ", " .#####x#####. ", " .##xxxxxxx##. ", " .######x######. ", " .#######x#######. ", " .#######x#######. ", " .#################. ", " .###################. ", " .....#xxxxxxx#..... ", " .#########. ", " .#########. ", " .#########. ", " .#########. ", " .###########. ", " .#############. ", " .#xxxxxxxxxxxxx#. ", " .###############. ", " .###############. ", " .#xxxxxxxxxxxxxxx#. ", " .#################. ", " ................. ", " ", " " }, { /* cannon */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " ", " .. ", " . .x#. ", " .#.##x#. ", " ...##x##x#. ", " ...#####x##x#. ", " ..#########x.##. ", " ...#########... .. ", " ..###########. ", " ...#############. ", " ..################. ", " ..x#################. ", " .##x#####xxxxxxxxxxxx. ", " .##x####x###########. ", " .###x###x###########. ", " ....xxxx###########. ", " .###############. ", " .###############. ", " .xxxxxxxxxxxxxx. ", " ..###########. ", " .###########. ", " .###########. ", " ..###########.. ", " .###############. ", " .#################. ", " .#################. ", " .#################. ", " .###################. ", " .###################. ", " ................... ", " " }, { /* galley */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground c red", " s mask m none", "x s shade c LightGrey", ". s edge m black", /* pixels */ " ", " . ", " .#. ", " .###. ", " .#x. ", " .#xx. ", " .xxx. ", " .xxxx. ", " .xxxx. ", " .xxxx. ", " .xxxx. ", " .xxxxx. ", " .xxxxxx. ", " .xxxxxx. ", " .xxxxxxx. ", " .xxxxxx. ", " ........ .xxx#x.. .... ", " .########...xxx.#. .....####.", " .############...#....#########.", " .############################. ", " .###########################. ", " .###########################. ", " .#########################. ", " ..#####################.. ", " ..#################.. ", " ..##x######xx##.. ", " .#xxxxxxxxxxx#. ", " .#############. ", " .###xxxxxxxxx###. ", " .###############. ", " ............... ", " " }, { /* pawn */ /* width height ncolors chars_per_pixel */ "32 32 4 1", /* colors */ "# s foreground m black", " s mask m none", "x s shade c LightGrey", ". s edge c black", /* pixels */ " ", " ", " ", " ", " ", " ", " ", " .. ", " .##. ", " .####. ", " .######. ", " .######. ", " .########. ", " .######. ", " .######. ", " .####. ", " ..#x##x#.. ", " .####xx####. ", " .############. ", " .##########. ", " ...####... ", " .####. ", " .######. ", " .######. ", " .########. ", " .########. ", " .##########. ", " .#xxxxxxxx#. ", " .############. ", " .############. ", " ............ ", " " } }; 3dchess-0.8.1.orig/ACKNOWLEDGEMENTS100644 0 17 2255 6113142277 14354 0ustar rootkmemRight from the start, I've used the Xpm lib because it is very useful. In fact, it is so useful that I'm not eliminating it from 3Dc despite the fact that it is not a 'requirement' for development on X. Xpm was written by Arnaud Le Hors and GROUPE BULL. I haven't included any specific copyrights for them because you have to get libXpm to compile 3Dc anyway, so you'll get it that way. In moving from Motif to plain Xaw (or preferably Xaw3d, if you have it), I've imitated a lot of code from libsx by Dominic Giampoalo, who deserves a lot of credit for making X accessible to beginner programmers. Even if you're an accomplished programmer, libsx is highly cool. The only reason I don't use it directly is because I had already written most of the code, and didn't want to change too much. All my new projects will use it though. Also, the DrawingArea widget that he uses, written by David Nedde, is copied directly into 3Dc - no infringement of copyright is intended, and his copyright notice is preserved in DrawingA*. Finally, thanks to Michael B. Martin for providing (at least temporarily) a home ftp/http site for 3Dc. See http://mbmartin.bevc.blacksburg.va.us/~paulh/3Dc/3Dc.html 3dchess-0.8.1.orig/CHANGES100644 0 17 20747 6132213626 13116 0ustar rootkmem---- Version 0.8 -> 0.8.1 o Added reasonable intelligence based on - Finishing the game - Check - Capture - Castling and Promotion - Proximity to end of board. These are very basic and frequently wrong guesses, but they are better than previous versions. All possible moves are checked. There is almost no lookahead but there is a little asynchronicity (stuff can happen while the computer is working). It's very easy to win, but it does teach moves. Watch out for the computer's cannons; it knows how to use them... o Fixed problem concerning PieceThreatened and promoted pieces, simplified the routine hugely, and renamed it to SquareThreatened. o Optimised TraverseDir by stopping checking in a direction if a piece is hit or the edge of the board is encountered. Macroized many of the complexities of directions. o Discovered that Solaris has function prototypes, so took that into consideration in mahine.h o Moved back to X11R5 compatibility. Using XlibSpecificationRelease to determine which version is being compiled. o Fixed problem which allowed promotion if the pawn's king was in check. o Fixed bug re: bishop, which allowed it to move diagonally in *any* two directions, even though it can actually move diagonally in only two way: strictly on the one board (a la chess) or like this and between boards. That is, a move from Yc1 to Zc2 is illegal. Additionally fixed bug which prevented it from changing levels. o Fixed bug with knights which meant that the computer thought that it move them from row 7 to row 0 via an ABS() oversight. o Arranged board windows so that they tend not to overlap at startup. o Minor editing of the docs. ---- Version 0.7.6 -> 0.8 o No changes. I just decided that enough was done in 0.7.6 (which was never released) to justify the version bump. ---- Version 0.7.5 -> 0.7.6 o Some minor new functionality; slightly more descriptive messages; beeps are less frequent. o Reduced the size of xif.c by putting some code into callbaks.c and some into xnet.c. Moved the X stuff in 3Dc.h into x3Dc.h o Networking code is eliminated. It was causing portability problems. "What!" I hear you exclaim---"No more network 3Dc?!" Don't worry, I've merely realised what a plonker I really am and moved over to X; after all, it is a networking GUI so why not use it? See the new "-ad" command-line option. o All the AI code is now in ai.c; it has changed quite a bit. Several bugs in the AI code found and fixed. The associated global variables (DontMove) are now module variables, local to their respective files. Only Board and bwToMove are global now. o Move some of the code from pieceThreatened and similar functions into the new function TraverseDir, added a DIR macro and added direction defines. This was primarily to reduce function sizes and reduce nesting. o Added a make install (how did I miss putting this in ages ago?) Got rid of that dodgy make config code in favour of a user-modifyable Makefile. Made an undo option configurable from the Makefile. o Fixed a few bugs in engine.c and piece.c which allowed a few dodgy things when moving a king out of check and another bug in engine.c, which caused a seg fault if you moved into one of eight spaces on the top board. At least one precompiler bug was found and fixed. o Changed function names to all start with capital letters. Variables still start with small letter. ---- Version 0.7.4 -> 0.7.5 Only few (tiny) changes this time o namelen in net.c is now set to sizeof(SOCKADDR) before calling accept. Thanks Robert. o string.h is now included by xif.c and main.c, and references to strdup and sprintf put into machine.h ---- Version 0.7.3 -> 0.7.4 o Investigated the use of pixmap cursors again, and came up with the following on the way: - Put in pixmap cursors (you can go back to using the cursor font by defining FONTCURSOR in xif.c). - Memory leak; only need to call XCreateFontCursor once (I don't call XFreeCursor, as it should be autofreed on quitting. Bad practice, I know, but it means that I don't have to make cursor a global. This bug doesn't apply to pixmap cursors, as I create the cursor each time, rather than maintain 22 cursors). - Fixed bug whereby the cursor would only be changed for the current board and any above it; boards below wouldn't have it changed (this one applies to both the new pixmap cursors and the older font cursors). - Fixed bug where the cursor would change even if nothing was picked up. This wasn't serious for FONTCURSOR, but segfaulted with pixmap cursors. o Halved the number of masks required (thus saving the space required for 11 32x32x1 pixmaps and the relevant pointers and IDs - talk about conscientious..) o Fixed redrawing of muster window during restart (i.e. now it gets redrawn). o Fixed a bug with undo - the undone piece thought that it was in both its original place and the place from which it was undone. o Made the "Resign Game?" dialog pop up in a more sensible position. It doesn't check to see if some of the dialog has gone missing off the edge of the screen, but I don't care - do you? o Improved the net play a bit. Now restart and resign work over the net. There's no verification by the other player, but the whole net stuff is hanging together by a thread anyway. I'll totally rewrite it one year. ---- Version 0.7.2 -> 0.7.3 o Fixed the problem whereby the game would crash when trying to put up the promotion callback. So now you can have 25 Queens.. o Taking En Passant would remove the piece from the board, but not from the game (this could be seen by examining the muster window while taking en passant - nothing would change). This is now fixed. o Fixed bug whereby a pawn taking a piece on the final rank would destroy the piece utterly, even unto undos. o Removed some dependance on the shape of the boards; this will simplify extending the game to arbitrarily sized boards, with arbitrarily many players. o Discovered that my fix to the makefile only works for GNU make; the real fix is to create an empty file .config, and to change the -f in the test to a -s; now it works. ---- Version 0.7.1 -> 0.7.2 Small changes, again. The muster window got most of the attention. o The following changes were made in the muster window: - The black royalty had the count of the black nobility, and vice versa. - The black royalty and nobility were too far to the left. - The Pawns' count vertical position was dependant on the width of the muster window - a silly mistake. o Fixed memory leak in Err3Dc. o Fixed bug with pawn allowing it to move 2 forward, 1 sideways (like a knight) on its first move. o Got the make working properly, so that you don't have to make config first; now it'll do it for you automatically. o Really got that truncated status line bug fixed. It now auto-centres (sic) the status line, too. ---- Version 0.7 -> 0.7.1 Not too much, this time. o Muster window added, showing how many pieces of each type and colour are still in play. o Improved exposure-handling; now only exposed squares get drawn. It's too complicated to draw just exposed pixels. Also, it's not worth doing the same in the muster window; there's not much in there. o Bug fixes, including truncated status line, and bad redrawing of enlarged boards (that one had me stumped for a while..) ---- Version 0.6 -> 0.7 Big changes this time, deserving the creation of this file. o Changed from Xm to Xaw (with DrawingArea widget; see ACKNOWLEDGEMENTS), which involved a lot of necessary (and usually highly cool) changes: - Changed from one DrawnButton per square to one DrawingArea per level. - Can trap ButtonPress and ButtonRelease much easier, so implemented drag-and-drop moving instead of src-dest-ok clicking. - Removed the Source and Dest fields in the main window. - Reduced size of internal representations of the muster and graphics. o Now change cursor while move is in progress (I'm working on changing the cursor to a pixmap of the piece being moved, but getting Xpm to generate monochrome pixmaps is harder than I thought..) o Removed last message from message-box if it is no longer applicable. o Got rid of that irritating beep all the time - now it only happens on the events which are both "interesting" and need your attention (such as your opponent moving). o Added some measure of machine configuration and autodetection. o Fixed an undo bug, a bug with kings and checking them, and one or two others. 3dchess-0.8.1.orig/TODO100644 0 17 2355 6132223005 12556 0ustar rootkmem* Fix bugs: capturing en passant allowed whenever the victim is two ranks ahead of its start position; it should only be allowed on the move after a single two-space move. Piece counts in muster window are sometimes updated the move after they should be. * Replace the conditionals in piece.c which allow/disallow moves on empty boards with table look ups. This would require a table for every piece; each table would be 3x3x3. Queen and King would be all 1, Bishop would be Bottom Middle Top 1 0 1 1 0 1 1 0 1 0 0 0 0 1 0 0 0 0 1 0 1 1 0 1 1 0 1 etc... I'm using this "plan" as an excuse not to document those conditionals. * Make the resign button bring up a bigger dialog, incl. network and autoplay options. The button should read "start" before the first move. * Play more interesting sounds than "beep", and allow them to be varied. * Improve the move-generation routine. * Animation!! (This one's a long way off..) * Alternative interfaces - X11 is all very well, but MS-Windows, VT100, Mac, .... * Network undo: not only is it not yet working properly, I'm not even sure that it should be allowed; at the very least, opponents should have veto over it. 3dchess-0.8.1.orig/INSTALL100644 0 17 1306 6113141741 13117 0ustar rootkmemChange into the src directory, edit the Makefile, making the standard changes. One or two changes are commented. Type 'make; make install', and hopefully it'll all work first time! So far, I've only got it to work on X11R5 and X11R6 under Linux, SunOS, Solaris, Irix and HPUX (thanks again, Robert). If you get it working on any other platform, send me the diffs or even just explanations of what's wrong (preferably with suggestions on fixing it). Ports to any X11R5 or X11R6 platform should involve relatively minor changes. Lots of people mail me about a Windows port. Unfortunately there is none. I'd love for someone to work on it, though. So if you're volunteering, please get in contact ASAP!