📄 gchess.h
字号:
/* Copyright (C) 2006, Mike Gashler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. see http://www.gnu.org/copyleft/lesser.html*/#ifndef __GCHESS_H__#define __GCHESS_H__#define MAX_PIECE_MOVES 27class GChessBoard{public: enum Piece { Pawn = 1, Bishop = 2, Knight = 3, Rook = 4, Queen = 5, King = 6, PieceMask = 7, WhiteMask = 8, AllMask = 15, };protected: unsigned int m_rows[8];public: inline Piece GetPiece(int col, int row, bool* pbWhite) { unsigned int i = (m_rows[row] >> (4 * col)); *pbWhite = ((i & WhiteMask) ? true : false); return (Piece)(i & PieceMask); } inline void SetPiece(int col, int row, Piece piece, bool bWhite) { m_rows[row] &= ((~AllMask) << (4 * col)); m_rows[row] |= ((piece | (bWhite ? WhiteMask : 0)) << (4 * col)); } // Pass in the coordinates of a square with a piece on it // and it will return the number of moves that piece can make // and put the coordinates of the moves in pOutMoves (first // col, then row, so pOutMoves should be big enough to hold // 2 * MAX_PIECE_MOVES values) int GetMoves(int* pOutMoves, int col, int row);protected: inline int Inc(int pos) { if(pos < 0 || pos >= 7) return -1; return pos + 1; } inline int Dec(int pos) { if(pos < 1) return -1; return pos -1; } bool CheckMove(int* pOutMoves, int* pnMoves, int col, int row, bool bWhite); bool CheckPawnMove(int* pOutMoves, int* pnMoves, int col, int row, bool bDiagonal, bool bWhite);};#endif // __GCHESS_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -