本文整理汇总了C++中ChessBoard类的典型用法代码示例。如果您正苦于以下问题:C++ ChessBoard类的具体用法?C++ ChessBoard怎么用?C++ ChessBoard使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChessBoard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generatePawnMoves
void ChessBoard::generatePawnMoves(ChessBoard& board, int sqSrc, Moves& mvs)
{
int sqDst;
if (board.m_sdPlayer != SQ_SIDE(sqSrc))
{
sqDst = sqSrc - 1;
if (IN_BOARD(sqDst) && board.canMove(board, sqSrc, sqDst))
{
mvs.append(ChessBoard::mv(sqSrc, sqDst));
}
sqDst = sqSrc + 1;
if (IN_BOARD(sqDst) && board.canMove(board, sqSrc, sqDst))
{
mvs.append(ChessBoard::mv(sqSrc, sqDst));
}
}
if (board.m_sdPlayer==0)
{
sqDst = sqSrc - 16;
}
else{
sqDst = sqSrc + 16;
}
if (IN_BOARD(sqDst) && board.canMove(board, sqSrc, sqDst))
{
mvs.append(ChessBoard::mv(sqSrc, sqDst));
}
}
示例2: WriteEmail
void WriteEmail ( const ChessBoard &board, const char *filename )
{
FILE *f = fopen ( filename, "wt" );
if ( !f )
{
sprintf ( ExitMessage, "Error opening file '%s' for write!\n", filename );
exit(1);
}
ListChessGame ( board, f );
fprintf ( f, "\n\n%s", ChessDataStart );
unsigned n = board.GetCurrentPlyNumber();
fprintf ( f, "%u\n", n );
for ( unsigned i=0; i < n; i++ )
{
Move move = board.GetPastMove ( i );
// Write source, dest codes as ASCII data...
fprintf ( f, "%02X %02X\n", unsigned(move.source), unsigned(move.dest) );
}
fprintf ( f, "%s", ChessDataEnd );
fclose ( f );
}
示例3: search
void Engine::search(ChessBoard& board, MoveList& moves, SEARCHTYPE searchtype, int wtime, int winc, int btime, int binc, int movestogo)
{
if (!process)
return;
QString cmd;
QStringList list;
ChessBoard b;
int i;
currentBoard = board;
for (i = 0; i < moves.size; i++)
{
list.append(currentBoard.makeMoveText(moves.at(i),UCI).c_str());
if (!currentBoard.doMove(moves.at(i), true))
break;
}
string s=board.getFen();
cmd = "position fen ";
if (board.startposition())
cmd += "startfen";
else
cmd += board.getFen(true).c_str();
if (list.size())
{
cmd += " moves";
QStringList::iterator lit = list.begin();
while (lit != list.end())
{
cmd += " ";
cmd += *lit;
++lit;
}
}
// If engine playing white it is most probaly not ready yet.
if (readyok)
write(cmd);
else
waitCommand += cmd;
cmd="go";
if (searchtype == PONDER_SEARCH)
cmd += " ponder";
if (searchtype == INFINITE_SEARCH)
{
cmd += " infinite";
}
else
{
cmd += " wtime " + QString().setNum(wtime);
cmd += " btime " + QString().setNum(btime);
cmd += " winc " + QString().setNum(winc);
cmd += " binc " + QString().setNum(binc);
}
if (movestogo)
cmd += "movestogo " + QString().setNum(movestogo);
cmd += "\n";
if (readyok)
write(cmd);
else
waitCommand += cmd;
}
示例4: Java_jwtc_chess_JNI_putPiece
JNIEXPORT void JNICALL Java_jwtc_chess_JNI_putPiece( JNIEnv* env, jobject thiz, jint pos, jint piece, jint turn)
{
ChessBoard *board = stGame->getBoard();
board->put(pos, piece, turn);
//DEBUG_PRINT("Put [%d, %d, %d]\n", pos, piece, turn);
}
示例5: send
bool InternetChessPlayer::send ( const ChessBoard &board )
{
char tempString [256];
UINT32 numPlies = board.GetCurrentPlyNumber();
if ( numPlies > 0 )
{
// Before receiving the move from the remote opponent, we must
// send him the complete state of the game as it exists locally.
// Send an 8-byte string to specify what kind of message this is.
// In this case, it is "history", because we are sending the entire history
// of moves in the game history so far...
UINT32 plyBytes = numPlies * sizeof(Move);
UINT32 packetSize = 8 + sizeof(numPlies) + plyBytes;
int result = ::send ( connectInfo.commSocket, (const char *)&packetSize, 4, 0 );
if ( result != 4 )
{
sprintf ( tempString, "send psize: %d", WSAGetLastError() );
userInterface.ReportSpecial (tempString);
return false;
}
result = ::send ( connectInfo.commSocket, "history ", 8, 0 );
if ( result != 8 )
{
sprintf ( tempString, "send 'history': %d", WSAGetLastError() );
userInterface.ReportSpecial (tempString);
return false;
}
result = ::send ( connectInfo.commSocket, (const char *)&numPlies, 4, 0 );
if ( result != 4 )
return false;
Move *history = new Move [numPlies];
if ( !history )
{
userInterface.ReportSpecial ( "out of memory!" );
return false;
}
for ( UINT32 ply = 0; ply < numPlies; ++ply )
history[ply] = board.GetPastMove (ply);
result = ::send ( connectInfo.commSocket, (const char *)history, plyBytes, 0 );
delete[] history;
history = NULL;
if ( UINT32(result) != plyBytes )
{
sprintf ( tempString, "send: %d", WSAGetLastError() );
userInterface.ReportSpecial (tempString);
return false;
}
}
return true;
}
示例6: CalculatePositionHashes
void CalculatePositionHashes (LearnBranch *table, int tablesize, ChessBoard &board, int node)
{
UnmoveInfo unmove;
assert (node >= 0);
assert (node < tablesize);
int myhash = board.Hash();
do
{
++NumHashPositions;
table[node].reserved[0] = myhash;
if (table[node].child >= 0)
{
board.MakeMove (table[node].move, unmove);
CalculatePositionHashes (table, tablesize, board, table[node].child);
board.UnmakeMove (table[node].move, unmove);
int checkhash = board.Hash();
assert (checkhash == myhash);
}
node = table[node].sibling;
}
while (node >= 0);
assert (node == -1);
}
示例7: ChessBoard_checkFigureMove
void PgntestTest::ChessBoard_checkFigureMove()
{
ChessBoard cb;
pgn::Ply ply("Nf3");
cb.makeMove(White, ply);
QCOMPARE((int)cb.getPiece(2, 5).type, (int)Knight);
}
示例8: ZobristHash
void Own2::AI(uint8 inp)
{
hash = ZobristHash(hash,inp,choose,0);
ChessBoard *rootChessBoard = new ChessBoard(a,hash);
int16 output = rootChessBoard->run();
delete rootChessBoard;
int p = 0;
// while (p == 0)
// {
// (time(NULL)) ;//通过系统时间初始化随机数种子
int m = output / 16;
int n = output % 16;
int q = 3-choose;
if(a[m][n] == 0 )
{
a[m][n] = q;
p = 1;
if(Win(m, n))
{
update();
int ch = choose;
if (ch==2) QMessageBox::information(this, "Win", "Black Win", QMessageBox::Ok);
if (ch==1) QMessageBox::information(this, "Win", "White Win", QMessageBox::Ok);
}
}
// }
realPly++;
}
示例9: ChessBoard_checkSimpleMove
void PgntestTest::ChessBoard_checkSimpleMove()
{
ChessBoard cb;
pgn::Ply ply("e4");
cb.makeMove(White, ply);
QCOMPARE((int)cb.getPiece(3, 4).type, (int)Pawn);
}
示例10: testSetupQuiesce
void testSetupQuiesce()
{
char buf[1024] = "", s[255];
ChessBoard *board = g->getBoard();
board->put(ChessBoard::d7, ChessBoard::PAWN, ChessBoard::BLACK);
board->put(ChessBoard::f8, ChessBoard::KING, ChessBoard::BLACK);
board->put(ChessBoard::c6, ChessBoard::PAWN, ChessBoard::BLACK);
board->put(ChessBoard::e7, ChessBoard::QUEEN, ChessBoard::BLACK);
board->put(ChessBoard::b4, ChessBoard::BISHOP, ChessBoard::WHITE);
board->put(ChessBoard::c3, ChessBoard::PAWN, ChessBoard::WHITE);
board->put(ChessBoard::d4, ChessBoard::PAWN, ChessBoard::WHITE);
board->put(ChessBoard::e5, ChessBoard::PAWN, ChessBoard::WHITE);
board->put(ChessBoard::d3, ChessBoard::KING, ChessBoard::WHITE);
board->setCastlingsEPAnd50(0, 0, 0, 0, -1, 0);
board->setTurn(0);
g->commitBoard();
board->toFEN(buf);
DEBUG_PRINT(buf, 0);
}
示例11: complete
// static
Move MoveChecker::complete(IncompleteMove incomplete_move,
const ChessBoard& board)
{
const Position src(incomplete_move.source());
const Piece::piece_index_t piece_index = board.piece_index(src);
const Position dst(incomplete_move.destination());
const int color_index = static_cast<int>(board.turn_color());
if (BitBoard(src) & BitBoard(MagicNumbers::c_king_positions[color_index])
&& BitBoard(dst) & BitBoard(MagicNumbers::c_castle_squares[color_index])
&& piece_index == PieceSet::c_king_index) {
if (dst.column() == Position::c_kings_knight_column) {
return Move(src, dst, Move::c_castle_k_flag);
} else {
assert(dst.column() == Position::c_queens_bishop_column);
return Move(src, dst, Move::c_castle_q_flag);
}
}
const BitBoard capturable = board.opponents();
const BitBoard dst_board(dst);
const bool is_capture = capturable & dst_board;
if (piece_index == PieceSet::c_pawn_index) {
if (board.ep_captures() & dst_board) {
return Move(src, dst, Move::c_ep_flag);
} else if (incomplete_move.is_promotion()) {
const uint16_t flags = (static_cast<uint16_t>(is_capture) << 14) | incomplete_move.m_state;
return Move(src, dst, flags);
} else if (abs(src.row() - dst.row()) == 2) {
return Move(src, dst, Move::c_double_pawn_push_flag);
}
}
return Move(src, dst, is_capture << 14);
}
示例12: Edit_DrawBoard
void Edit_DrawBoard ( const ChessBoard &board )
{
const SQUARE *b = board.queryBoardPointer();
printf ( " +--------+\n" );
for ( int y=9; y >= 2; --y )
{
printf ( " %d |", y-1 );
for ( int x=2; x <= 9; ++x )
{
char c = PieceRepresentation ( b[OFFSET(x,y)] );
printf ( "%c", c );
}
printf ( "|" );
if ( y == 6 )
printf ( " ply = %d", board.GetCurrentPlyNumber() );
else if ( y == 5 )
printf ( " hash = %08lx", (unsigned long)(board.Hash()) );
printf ( "\n" );
}
printf ( " +--------+\n" );
printf ( " abcdefgh\n\n" );
}
示例13: main
int main()
{
ChessBoard mainBoard;
GUI::initializeBoard(mainBoard);
GUI::displayBoard(mainBoard);
while (!mainBoard.getCheckmate()) // Move cycle.
{
string userInput;
cin >> userInput;
if (Input::isSentinelValue(userInput)) // Sentinel values are "end" and "forfeit."
{
break;
}
if (Input::isDiagnosticTest(userInput, mainBoard) || !Input::isMove(userInput))
{
continue;
}
Input* move = Input::interpretInput(userInput); // Converts user input into integer values.
ChessPiece* movingPiece = mainBoard.ChessBoard::getPieceAt(move->getFromX(), move->getFromY()); // Figures out which piece is being moved.
bool isPiece = (movingPiece != nullptr);
if (isPiece)
{
bool isValidMove = Rules::isValidMove(mainBoard, *movingPiece, move);
if (!isValidMove)
{
continue;
}
ChessPiece* removedPiece = mainBoard.movePiece(*movingPiece, move->getToX(), move->getToY()); // If it doesn't violate basic movement rules, the piece is moved to its new location.
bool compliesWithCheckRules = Rules::compliesWithCheckRules(mainBoard, *movingPiece, removedPiece, move);
if (!compliesWithCheckRules)
{
continue;
}
bool gameover = mainBoard.getCheckmate();
if (gameover)
{
break;
}
}
else
{
cout << "That is not a piece\n\n";
continue;
}
cout << string(50, '\n'); // "Clears" old board.
GUI::displayBoard(mainBoard); // Displays new board.
mainBoard.nextTurn(); // It's now the other player's turn.
}
cin.ignore();
return 0;
}
示例14: PawnMoveChecker_checkPossibleEnPassante
void PgntestTest::PawnMoveChecker_checkPossibleEnPassante()
{
ChessBoard cb;
cb.clear();
PawnMoveChecker checker;
QVERIFY(checker.canMoveTo(1, 0, White, 3, 0, cb));
}
示例15: BasicMoveChecker_doNotMoveOnFrienCell
void PgntestTest::BasicMoveChecker_doNotMoveOnFrienCell()
{
ChessBoardPiece piece;
piece.color = White;
piece.type = Rook;
ChessBoard cb;
cb.setPiece(5, 5, piece);
BasicMoveChecker checker;
QVERIFY(!checker.canMoveTo(0, 5, White, 5, 5, cb));
}