#import <OpenGL/gl.h>
#import <Cocoa/Cocoa.h>
#import <stdio.h>
enum MBCVariant {
kVarNormal,
kVarCrazyhouse,
kVarSuicide,
kVarLosers
};
extern NSString * gVariantName[];
extern const char gVariantChar[];
enum MBCPlayers {
kHumanVsHuman,
kHumanVsComputer,
kComputerVsHuman,
kComputerVsComputer,
kHumanVsGameCenter,
};
enum MBCSideCode {
kPlayWhite,
kPlayBlack,
kPlayEither
};
enum MBCUniqueCode {
kMatchingPieceExists = 1,
kMatchingPieceOnSameRow = 2,
kMatchingPieceOnSameCol = 4,
};
typedef int MBCUnique;
enum MBCPieceCode {
EMPTY = 0,
KING, QUEEN, BISHOP, KNIGHT, ROOK, PAWN,
kWhitePiece = 0,
kBlackPiece = 8,
kPromoted = 16,
kPieceMoved = 32
};
typedef unsigned char MBCPiece;
inline MBCPiece White(MBCPieceCode code) { return kWhitePiece | code; }
inline MBCPiece Black(MBCPieceCode code) { return kBlackPiece | code; }
inline MBCPieceCode Piece(MBCPiece piece){ return (MBCPieceCode)(piece&7); }
inline MBCPieceCode Color(MBCPiece piece){ return (MBCPieceCode)(piece&8); }
inline MBCPieceCode What(MBCPiece piece) { return (MBCPieceCode)(piece&15);}
inline MBCPiece Matching(MBCPiece piece, MBCPieceCode code)
{ return (piece & 8) | code; }
inline MBCPiece Opposite(MBCPiece piece) { return piece ^ 8; }
inline MBCPieceCode Promoted(MBCPiece piece)
{ return (MBCPieceCode)(piece & 16); }
inline MBCPieceCode PieceMoved(MBCPiece piece)
{ return (MBCPieceCode)(piece & 32); }
enum MBCMoveCode {
kCmdNull,
kCmdMove, kCmdDrop, kCmdUndo,
kCmdWhiteWins, kCmdBlackWins, kCmdDraw,
kCmdPong, kCmdStartGame,
kCmdPMove, kCmdPDrop,
kCmdMoveOK
};
typedef unsigned char MBCSquare;
enum {
kSyntheticSquare = 0x70,
kWhitePromoSquare = 0x71,
kBlackPromoSquare = 0x72,
kBorderRegion = 0x73,
kInHandSquare = 0x80,
kInvalidSquare = 0xFF,
kSquareA8 = 56,
kBoardSquares = 64
};
inline unsigned Row(MBCSquare square)
{ return 1+(square>>3); }
inline char Col(MBCSquare square)
{ return 'a'+(square&7); }
inline MBCSquare Square(char col, unsigned row)
{ return ((row-1)<<3)|(col-'a'); }
inline MBCSquare Square(const char * colrow)
{ return ((colrow[1]-'1')<<3)|(colrow[0]-'a'); }
enum MBCCastling {
kUnknownCastle, kCastleQueenside, kCastleKingside, kNoCastle
};
enum MBCSide {
kWhiteSide, kBlackSide, kBothSides, kNeitherSide
};
inline bool SideIncludesWhite(MBCSide side) { return side==kWhiteSide || side==kBothSides; }
inline bool SideIncludesBlack(MBCSide side) { return side==kBlackSide || side==kBothSides; }
extern const MBCSide gHumanSide[];
extern const MBCSide gEngineSide[];
typedef unsigned MBCCompactMove;
@interface MBCMove : NSObject
{
@public
MBCMoveCode fCommand; MBCSquare fFromSquare; MBCSquare fToSquare; MBCPiece fPiece; MBCPiece fPromotion; MBCPiece fVictim; MBCCastling fCastling; BOOL fEnPassant; BOOL fCheck; BOOL fCheckMate; BOOL fAnimate; }
- (id) initWithCommand:(MBCMoveCode)command;
+ (id) newWithCommand:(MBCMoveCode)command;
+ (id) moveWithCommand:(MBCMoveCode)command;
- (id) initFromCompactMove:(MBCCompactMove)move;
+ (id) newFromCompactMove:(MBCCompactMove)move;
+ (id) moveFromCompactMove:(MBCCompactMove)move;
- (id) initFromEngineMove:(NSString *)engineMove;
+ (id) newFromEngineMove:(NSString *)engineMove;
+ (id) moveFromEngineMove:(NSString *)engineMove;
+ (BOOL) compactMoveIsWin:(MBCCompactMove)move;
- (NSString *) localizedText;
- (NSString *) engineMove;
- (NSString *) origin;
- (NSString *) operation;
- (NSString *) destination;
- (NSString *) check;
@end
struct MBCPieces {
MBCPiece fBoard[64];
char fInHand[16];
MBCSquare fEnPassant;
bool NoPieces(MBCPieceCode color);
};
@interface MBCBoard : NSObject
{
MBCPieces fCurPos;
MBCPieces fPrvPos;
int fMoveClock;
MBCVariant fVariant;
NSMutableArray * fMoves;
MBCPiece fPromotion[2];
NSMutableArray * fObservers;
id fDocument;
}
- (void) removeChessObservers;
- (void) setDocument:(id)doc;
- (void) startGame:(MBCVariant)variant;
- (MBCPiece) curContents:(MBCSquare)square; - (MBCPiece) oldContents:(MBCSquare)square; - (int) curInHand:(MBCPiece)piece; - (int) oldInHand:(MBCPiece)piece; - (void) makeMove:(MBCMove *)move; - (MBCCastling) tryCastling:(MBCMove *)move;
- (void) tryPromotion:(MBCMove *)move;
- (MBCSide) sideOfMove:(MBCMove *)move;
- (MBCUnique) disambiguateMove:(MBCMove *)move;
- (bool) undoMoves:(int)numMoves;
- (void) commitMove; - (NSString *) fen; - (NSString *) holding; - (NSString *) moves; - (void) setFen:(NSString *)fen holding:(NSString *)holding
moves:(NSString *)moves;
- (BOOL) saveMovesTo:(FILE *)f;
- (BOOL) canPromote:(MBCSide)side;
- (BOOL) canUndo;
- (MBCMove *) lastMove;
- (int) numMoves;
- (MBCMove *) move:(int)index;
- (MBCPieces *) curPos;
- (MBCPiece) defaultPromotion:(BOOL)white;
- (void) setDefaultPromotion:(MBCPiece)piece for:(BOOL)white;
- (MBCMoveCode)outcome;
- (NSString *) stringFromMove:(MBCMove *)move withLocalization:(NSDictionary *)localization;
- (NSString *) extStringFromMove:(MBCMove *)move withLocalization:(NSDictionary *)localization;
@end
NSString * LocalizedString(NSDictionary * localization, NSString * key, NSString * fallback);
#define LOC(key, fallback) LocalizedString(localization, key, fallback)