本文整理汇总了C++中board::get方法的典型用法代码示例。如果您正苦于以下问题:C++ board::get方法的具体用法?C++ board::get怎么用?C++ board::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类board
的用法示例。
在下文中一共展示了board::get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: try_square
// Tries new position to see if it is a valid move. The move is valid if the
// destination square is on the board, and either empty or containing an
// opposing piece. Valid moves are added to the move list.
//
// Returns true if square is on the board and EMPTY. If it has an opposing piece,
// the move is added to the move list, but we return false. Good for generating
// moves for rook/bishop/queen.
//
bool try_square(
piece_colour pc, const row_col& pos, const row_col& newpos,
const board& b, move* movelist, int& num_moves)
{
if (newpos.is_out_of_bounds())
return false;
square s = b.get(newpos);
if (get_piece_colour(s) == pc)
return false; // piece on destination square is the same as our colour
movelist[num_moves] = move(pos, newpos, b);
num_moves++;
return is_empty(s);
}
示例2: check_captures
int check_captures(position src, position dst, board const& board,
piece what, OutIter out) {
piece::color_t const player = what.color();
board::mask supporters;
int score = 0;
if (trap(dst)) {
supporters = neighbourhood(dst) & board.player(player);
supporters[src] = false;
// Check for piece stepping into a trap.
if (supporters.empty()) {
*out++ = elementary_step::make_capture(dst, what);
score -= CAPTURE_COEF * cost(what, src);
}
}
// Check for piece abandoning another one standing on a trap.
if (neighbourhood(src) & board::mask::TRAPS && !trap(dst)) {
position const trap =
(neighbourhood(src) & board::mask::TRAPS).first_set();
boost::optional<piece> const trapped = board.get(trap);
if (trapped) {
piece::color_t const trapped_player = trapped->color();
supporters = neighbourhood(trap) & board.player(trapped_player);
supporters[src] = false;
if (supporters.empty()) {
*out++ = elementary_step::make_capture(trap, *trapped);
score +=
(trapped->color() == what.color() ? -1 : +1) *
CAPTURE_COEF * cost(*trapped, trap);
}
}
}
return score;
}
示例3: gen_moves
void gen_moves(const board& b, piece_colour pc, move* movelist, int& num_moves)
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
row_col rc(i, j);
square s = b.get(rc);
if (pc == get_piece_colour(s))
{
piece_type pt = get_piece_type(s);
switch (pt)
{
case NONE:
assert(0); // only here if square contains one of our pieces
break;
case PAWN:
pawn_moves(pc, rc, b, movelist, num_moves);
break;
case KNIGHT:
knight_moves(pc, rc, b, movelist, num_moves);
break;
case BISHOP:
bishop_moves(pc, rc, b, movelist, num_moves);
break;
case ROOK:
rook_moves(pc, rc, b, movelist, num_moves);
break;
case KING:
king_moves(pc, rc, b, movelist, num_moves);
break;
case QUEEN:
queen_moves(pc, rc, b, movelist, num_moves);
break;
}
}
}
}
}
示例4: from
move::move(const row_col& f, const row_col& t, const board& b) :
from(f), to(t), from_sq(b.get(f)), to_sq(b.get(t)), score(0)
{
}