72 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
// #include <Rcpp.h>
 | 
						|
 | 
						|
// #include "SchachHoernchen/utils.h"
 | 
						|
// #include "SchachHoernchen/Board.h"
 | 
						|
// #include "SchachHoernchen/uci.h"
 | 
						|
 | 
						|
// // [[Rcpp::export(name = "print.board", rng = false)]]
 | 
						|
// void print_board(
 | 
						|
//     const Board& board,
 | 
						|
//     const bool check = true,
 | 
						|
//     const bool attacked = false,
 | 
						|
//     const bool pinned = false,
 | 
						|
//     const bool checkers = false
 | 
						|
// ) {
 | 
						|
//     using Rcpp::Rcout;
 | 
						|
 | 
						|
//     // Extract some properties
 | 
						|
//     piece color = board.sideToMove();
 | 
						|
//     piece enemy = static_cast<piece>(!color);
 | 
						|
//     u64 empty = ~(board.bb(piece::white) | board.bb(piece::black));
 | 
						|
//     u64 cKing = board.bb(king) & board.bb(color);
 | 
						|
//     // Construct highlight mask
 | 
						|
//     u64 attackMask = board.attacks(enemy, empty);
 | 
						|
//     u64 mask = 0;
 | 
						|
//     mask |= check    ? attackMask & board.bb(color) & board.bb(king) : 0;
 | 
						|
//     mask |= attacked ? attackMask & ~board.bb(color)                 : 0;
 | 
						|
//     mask |= pinned   ? board.pinned(enemy, cKing, empty)             : 0;
 | 
						|
//     mask |= checkers ? board.checkers(enemy, cKing, empty)           : 0;
 | 
						|
 | 
						|
//     // print the board to console
 | 
						|
//     Rcout << "FEN: " << board.fen() << '\n';
 | 
						|
//     for (Index line = 0; line < 17; line++) {
 | 
						|
//         if (line % 2) {
 | 
						|
//             Index rankIndex = line / 2;
 | 
						|
//             Rcout << static_cast<char>('8' - rankIndex);
 | 
						|
//             for (Index fileIndex = 0; fileIndex < 8; fileIndex++) {
 | 
						|
//                 Index squareIndex = 8 * rankIndex + fileIndex;
 | 
						|
//                 if (bitMask<Square>(squareIndex) & mask) {
 | 
						|
//                     if (board.piece(squareIndex)) {
 | 
						|
//                         if (board.color(squareIndex) == black) {
 | 
						|
//                             // bold + italic + underline + black (blue)
 | 
						|
//                             Rcout << " | \033[1;3;4;94m";
 | 
						|
//                         } else {
 | 
						|
//                             // bold + italic + underline (+ white)
 | 
						|
//                             Rcout << " | \033[1;3;4m";
 | 
						|
//                         }
 | 
						|
//                         Rcout << UCI::formatPiece(board.piece(squareIndex))
 | 
						|
//                             << "\033[0m";
 | 
						|
//                     } else {
 | 
						|
//                         Rcout << " | .";
 | 
						|
//                     }
 | 
						|
//                 } else if (board.color(squareIndex) == black) {
 | 
						|
//                     Rcout << " | \033[1m\033[94m"   // bold + blue (black)
 | 
						|
//                         << UCI::formatPiece(board.piece(squareIndex))
 | 
						|
//                         << "\033[0m";
 | 
						|
//                 } else if (board.color(squareIndex) == white) {
 | 
						|
//                     Rcout << " | \033[1m\033[97m"   // bold + white
 | 
						|
//                         << UCI::formatPiece(board.piece(squareIndex))
 | 
						|
//                         << "\033[0m";
 | 
						|
//                 } else {
 | 
						|
//                     Rcout << " |  ";
 | 
						|
//                 }
 | 
						|
//             }
 | 
						|
//             Rcout << " |";
 | 
						|
//         } else {
 | 
						|
//             Rcout << "  +---+---+---+---+---+---+---+---+";
 | 
						|
//         }
 | 
						|
//         Rcout << "\033[0K\n"; // clear rest of line (remove potential leftovers)
 | 
						|
//     }
 | 
						|
//     Rcout << "    a   b   c   d   e   f   g   h" << std::endl;
 | 
						|
// }
 |