本文整理汇总了C++中Board类的典型用法代码示例。如果您正苦于以下问题:C++ Board类的具体用法?C++ Board怎么用?C++ Board使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Board类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SEEMap
Score SEEMap(Board &board, Square sq)
{
board.ResetSee();
return -StaticExchangeEvaluationSq(board, sq, true);
}
示例2: srand
void Cycle::testForMove(Board b) {
srand(static_cast<unsigned int>(time(0)));
int ran = rand() % 10;
int r = row;
int c = column;
/// Locate cell in front of Cycle.
if (direction == N)
r = row - 1;
if (direction == S)
r = row + 1;
if (direction == W)
c = column - 1;
if (direction == E)
c = column + 1;
/// Cycle has chance to turn before crash. May turn any direction but current.
if (b.getBoardPos(r, c) != ' ') {
if (ran < DIFFICULTY_1) {
do {
ran = rand() % 4;
} while (direction == (Direction)ran);
direction = (Direction)ran;
}
}
/// Cycle may make ninety degree turn. Chance of turn increases in zones near border.
/// Zone 1
else if (((row == 2 || row == 3) && direction == N) || ((row == 33 || row == 34) && direction == S)){
if (ran < DIFFICULTY_2) {
ran = ran % 2;
if (ran == 0)
direction = E;
else
direction = W;
}
}
else if (((column == 2 || column == 3) && direction == W) || ((column == 75 || column == 76) && direction == E)){
if (ran < DIFFICULTY_2) {
ran = ran % 2;
if (ran == 0)
direction = N;
else
direction = S;
}
}
/// Zone 2
else if (((row >= 4 && row <= 6) && direction == N) || ((row >= 30 && row <= 32) && direction == S)){
if (ran < DIFFICULTY_3) {
ran = ran % 2;
if (ran == 0)
direction = E;
else
direction = W;
}
}
else if (((column >= 4 && column <= 6) && direction == W) || ((column >= 72 && column <= 74) && direction == E)){
if (ran < DIFFICULTY_3) {
ran = ran % 2;
if (ran == 0)
direction = N;
else
direction = S;
}
}
/// Zone 3
else if (ran < DIFFICULTY_4){
ran = ran % 2;
if (direction == N || direction == S) {
if (ran == 0)
direction = E;
else
direction = W;
}
else if (direction == E || direction == W) {
if (ran == 0)
direction = N;
else
direction = S;
}
}
}
示例3: throw
float BoardDetector::detect(const vector< Marker > &detectedMarkers, const BoardConfiguration &BConf, Board &Bdetected, Mat camMatrix, Mat distCoeff,
float markerSizeMeters) throw(cv::Exception) {
if (BConf.size() == 0)
throw cv::Exception(8881, "BoardDetector::detect", "Invalid BoardConfig that is empty", __FILE__, __LINE__);
if (BConf[0].size() < 2)
throw cv::Exception(8881, "BoardDetector::detect", "Invalid BoardConfig that is empty 2", __FILE__, __LINE__);
// compute the size of the markers in meters, which is used for some routines(mostly drawing)
float ssize;
if (BConf.mInfoType == BoardConfiguration::PIX && markerSizeMeters > 0)
ssize = markerSizeMeters;
else if (BConf.mInfoType == BoardConfiguration::METERS) {
ssize = cv::norm(BConf[0][0] - BConf[0][1]);
}
// cout<<"markerSizeMeters="<<markerSizeMeters<<endl;
Bdetected.clear();
/// find among detected markers these that belong to the board configuration
for (unsigned int i = 0; i < detectedMarkers.size(); i++) {
int idx = BConf.getIndexOfMarkerId(detectedMarkers[i].id);
if (idx != -1) {
Bdetected.push_back(detectedMarkers[i]);
Bdetected.back().ssize = ssize;
}
}
// copy configuration
Bdetected.conf = BConf;
//
bool hasEnoughInfoForRTvecCalculation = false;
if (Bdetected.size() >= 1) {
if (camMatrix.rows != 0) {
if (markerSizeMeters > 0 && BConf.mInfoType == BoardConfiguration::PIX)
hasEnoughInfoForRTvecCalculation = true;
else if (BConf.mInfoType == BoardConfiguration::METERS)
hasEnoughInfoForRTvecCalculation = true;
}
}
// calculate extrinsic if there is information for that
if (hasEnoughInfoForRTvecCalculation) {
// calculate the size of the markers in meters if expressed in pixels
double marker_meter_per_pix = 0;
if (BConf.mInfoType == BoardConfiguration::PIX)
marker_meter_per_pix = markerSizeMeters / cv::norm(BConf[0][0] - BConf[0][1]);
else
marker_meter_per_pix = 1; // to avoind interferring the process below
// now, create the matrices for finding the extrinsics
vector< cv::Point3f > objPoints;
vector< cv::Point2f > imagePoints;
for (size_t i = 0; i < Bdetected.size(); i++) {
int idx = Bdetected.conf.getIndexOfMarkerId(Bdetected[i].id);
assert(idx != -1);
for (int p = 0; p < 4; p++) {
imagePoints.push_back(Bdetected[i][p]);
const aruco::MarkerInfo &Minfo = Bdetected.conf.getMarkerInfo(Bdetected[i].id);
objPoints.push_back(Minfo[p] * marker_meter_per_pix);
// cout<<objPoints.back()<<endl;
}
}
if (distCoeff.total() == 0)
distCoeff = cv::Mat::zeros(1, 4, CV_32FC1);
// for(size_t i=0;i< imagePoints.size();i++){
// cout<<objPoints[i]<<" "<<imagePoints[i]<<endl;
// }
// cout<<"cam="<<camMatrix<<" "<<distCoeff<<endl;
cv::Mat rvec, tvec;
cv::solvePnP(objPoints, imagePoints, camMatrix, distCoeff, rvec, tvec);
rvec.convertTo(Bdetected.Rvec, CV_32FC1);
tvec.convertTo(Bdetected.Tvec, CV_32FC1);
// cout<<rvec<< " "<<tvec<<" _setYPerpendicular="<<_setYPerpendicular<<endl;
{
vector< cv::Point2f > reprojected;
cv::projectPoints(objPoints, rvec, tvec, camMatrix, distCoeff, reprojected);
double errSum = 0;
// check now the reprojection error and
for (size_t i = 0; i < reprojected.size(); i++) {
errSum += cv::norm(reprojected[i] - imagePoints[i]);
}
// cout<<"AAA RE="<<errSum/double ( reprojected.size() ) <<endl;
}
// now, do a refinement and remove points whose reprojection error is above a threshold, then repeat calculation with the rest
if (repj_err_thres > 0) {
vector< cv::Point2f > reprojected;
cv::projectPoints(objPoints, rvec, tvec, camMatrix, distCoeff, reprojected);
vector< int > pointsThatPassTest; // indices
// check now the reprojection error and
for (size_t i = 0; i < reprojected.size(); i++) {
float err = cv::norm(reprojected[i] - imagePoints[i]);
if (err < repj_err_thres)
pointsThatPassTest.push_back(i);
}
// cerr<<"Number of points after reprjection test "<<pointsThatPassTest.size() <<"/"<<objPoints.size() <<endl;
// copy these data to another vectors and repeat
vector< cv::Point3f > objPoints_filtered;
vector< cv::Point2f > imagePoints_filtered;
//.........这里部分代码省略.........
示例4: main
int main(int argc, char **argv) {
Board board;
int value;
Board::socket_t move;
bool tuzdek;
char answer;
cout << "Do you want to begin (Y/N)? ";
cin >> answer;
bool firstComp = (answer != 'Y');
while (true) {
if (firstComp) {
busy();
minimax(board, D, 0, move, tuzdek);
board.pli(move, tuzdek, 0);
unbusy();
firstComp = false;
}
int playerMove;
cout << board.rotate();
if (board.kaznas[1] > K * N) {
cout << "You win." << endl;
break;
} else if (board.kaznas[0] > K * N) {
cout << "You lose." << endl;
break;
}
cout << "Your move: ";
cin >> playerMove;
//playerMove = std::rand() % 9 + 1;
Board::socket_t pMove = playerMove + K - 1;
if (board.sockets[pMove] == 0) {
cout << "Cannot play at " << playerMove << endl;
continue;
}
auto target = board.playSocket(pMove);
if (board.tuzdekPossible(target, 1)) {
cout << "Create tuzdek at opponent's " << (static_cast<int> (target) + 1) << " (Y/N) ";
cin >> answer;
if (answer == 'Y') {
board.tuzdeks[1] = target;
}
}
board.accountSocket(target, 1);
busy();
auto value = minimax(board, D, 0, move, tuzdek);
if (move == -1) {
cout << "Game ended." << endl;
// TODO determine winner from kaznas
break;
}
board.pli(move, tuzdek, 0);
cout << "Opponent's move: " << (static_cast<int> (move) + 1) << " (worst outcome: " << value << ")" << endl;
unbusy();
}
示例5: goDown
void Entity::goDown(Board& board, Environnement& env)
{
if (moveToThisLocation(board, board.getValidValue(_loc + Coord::DOWN), env)) {
_lastAction = MOVE_DOWN;
}
}
示例6: MakeTurn
bool Player::MakeTurn(Board& board, COORDS c) {
return board.Hit(c) != NO_BOOM;
}
示例7: update
void update(const Board& board, Disc disc, eval_t error, int beta, int n_sample) {
Board next = board;
next.move(search_next(board, disc), disc);
evaluator_.update(next, (Disc)-disc, error, beta, n_sample);
}
示例8: main
int main(int argc, const char* argv[]){
ifstream infile;
infile.open("C-small-attempt2.in");
ofstream outfile;
outfile.open("C-small222.out");
int T;
infile >> T;
for(int i=0; i<T; i++) {
int r, c, m;
infile >> r >> c >> m;
Board a(r,c,m);
Board *b = &a;
outfile <<"Case #" <<i+1<<":"<<endl;
if(m>=0&&(m+1)==(r*c)){
b->ConfigMine1();
b->findc2(); //
outfile<< b->toPrint();
}
else if((r*c-m)==4&&m>=0){
b->ConfigMine6();
b->setvalues();
if(b->checkpossible()){
b->findc();
outfile << b->toPrint();
}else{
outfile<<"Impossible"<<endl;
}
}
else{
b->ConfigMine1();
b->setvalues();
if(b->checkpossible()){
b->findc();
outfile << b->toPrint() ;
}else{
b->ConfigMine2();
b->setvalues();
if(b->checkpossible()){
b->findc();
outfile << b->toPrint() ;
}else{
b->ConfigMine3();
b->setvalues();
if(b->checkpossible()){
b->findc();
outfile << b->toPrint() ;
}else{
b->ConfigMine4();
b->setvalues();
if(b->checkpossible()){
b->findc();
outfile << b->toPrint() ;
}else{
b->ConfigMine5();
b->setvalues();
if(b->checkpossible()){
b->findc();
outfile << b->toPrint() ;
}else{
outfile << "Impossible" <<endl;
}
}
}
}
}
}
}
/*
while(true){
int r, c, m;
cin>> r >> c >> m;
Board a(r,c,m);
Board *b = &a;
cout<<b->toPrint();
cout<<"Solution:"<<endl;
cout<<fixed;
//cout<<"Case #" <<i+1<<":"<<endl;
if(m>=0&&(m+1)==(r*c)){
b->ConfigMine1();
b->findc2(); //
cout<< b->toPrint();
}
else if((r*c-m)==4&&m>=0){
b->ConfigMine6();
b->setvalues();
if(b->checkpossible()){
b->findc();
cout << b->toPrint();
}else{
cout<<"Impossible"<<endl;
}
}
//.........这里部分代码省略.........
示例9: play
pos_t CompoundAIPlayer::play(Board& board) {
if (board.empty_cnt() <= 10) {
return lookn.play(board);
}
return look2.play(board);
}
示例10: isProtected_
bool Mate::isProtected_(const Board& board, Bitboard& bb, const Bitboard& occ, const Bitboard& occNoAttacker) {
const auto& king = black ? board.getBKingSquare() : board.getWKingSquare();
bool hasHand = black
? (board.getBlackHand(Piece::Pawn) != 0 ||
board.getBlackHand(Piece::Lance) != 0 ||
board.getBlackHand(Piece::Knight) != 0 ||
board.getBlackHand(Piece::Silver) != 0 ||
board.getBlackHand(Piece::Gold) != 0 ||
board.getBlackHand(Piece::Bishop) != 0 ||
board.getBlackHand(Piece::Rook) != 0)
: (board.getWhiteHand(Piece::Pawn) != 0 ||
board.getWhiteHand(Piece::Lance) != 0 ||
board.getWhiteHand(Piece::Knight) != 0 ||
board.getWhiteHand(Piece::Silver) != 0 ||
board.getWhiteHand(Piece::Gold) != 0 ||
board.getWhiteHand(Piece::Bishop) != 0 ||
board.getWhiteHand(Piece::Rook) != 0);
if (hasHand) {
BB_EACH_OPE(to, bb, {
if (isProtected_<black>(board, to, occ, occNoAttacker, king)) { return true; }
});
} else {
示例11: TEST_CASE
#include <tuple>
using std::tuple;
using std::make_tuple;
// For _1, used with std::bind
// ***** Test Cases *****
TEST_CASE("2 param Constructor", "[Board]")
{
const int SIZE = 10;
const int CELLS = SIZE*SIZE;
Board primary(SIZE,true);
REQUIRE(primary.getSize() == SIZE);
REQUIRE(primary.isPrimary() == true);
Board target(SIZE,false); //Testing Target board construction
REQUIRE(target.getSize() == SIZE);
REQUIRE(target.isPrimary() == false);
}
TEST_CASE(" Testing manipulating cells from board","[BOARD]")
{
const int SIZE = 10;
const int CELLS = SIZE*SIZE;
Board cellTest(SIZE,true);
示例12: printf
void MyDomain::received(char* str)
{
if (strncmp(str, "quit", 4)==0) {
l.exit();
return;
}
if (strncmp(str, "pos ", 4)!=0) return;
b.setState(str+4);
if (verbose) {
printf("\n\n==========================================\n");
printf(str+4);
}
int state = b.validState();
if ((state != Board::valid1) &&
(state != Board::valid2)) {
printf("%s\n", Board::stateDescription(state));
switch(state) {
case Board::timeout1:
case Board::timeout2:
case Board::win1:
case Board::win2:
l.exit();
default:
break;
}
return;
}
if (b.actColor() & myColor) {
struct timeval t1, t2;
gettimeofday(&t1,0);
Move m = b.bestMove();
gettimeofday(&t2,0);
int msecsPassed =
(1000* t2.tv_sec + t2.tv_usec / 1000) -
(1000* t1.tv_sec + t1.tv_usec / 1000);
printf("%s ", (myColor == Board::color1) ? "O":"X");
if (m.type == Move::none) {
printf(" can not draw any move ?! Sorry.\n");
return;
}
printf("draws '%s' (after %d.%03d secs)...\n",
m.name(), msecsPassed/1000, msecsPassed%1000);
b.playMove(m, msecsPassed);
sendBoard();
if (changeEval)
ev.changeEvaluation();
/* stop player at win position */
int state = b.validState();
if ((state != Board::valid1) &&
(state != Board::valid2)) {
printf("%s\n", Board::stateDescription(state));
switch(state) {
case Board::timeout1:
case Board::timeout2:
case Board::win1:
case Board::win2:
l.exit();
default:
break;
}
}
maxMoves--;
if (maxMoves == 0) {
printf("Terminating because given number of moves drawn.\n");
broadcast("quit\n");
l.exit();
}
}
}
示例13: win
//This function gets the conditions to end the game
void win(Board& game) {
if ((game.get_bc() + game.get_wc() == 64) || (game.get_bc() == 0) || (game.get_wc() == 0))
{
cout << "Game Over!" << endl;
cout << "BLACK VS WHITE: \n";
cout << game.get_bc() << " : " << game.get_wc() << endl;
if (game.get_bc() == 0){
cout << "White Wins!" << endl;
}
if (game.get_wc() == 0){
cout << "Black Wins!" << endl;
}
if ((game.get_bc() + game.get_wc() == 64) && game.get_bc() > game.get_wc())
{
cout << "Black Wins!" << endl;
}
if ((game.get_bc() + game.get_wc() == 64) && game.get_wc() > game.get_bc())
{
cout << "White Wins!" << endl;
}
if ((game.get_bc() + game.get_wc() == 64) && game.get_wc() == game.get_bc()){
cout << "DRAW!" << endl;
}
exit(0);
}
}
示例14: goRight
void Entity::goRight(Board& board, Environnement& env)
{
if (moveToThisLocation(board, board.getValidValue(_loc + Coord::RIGHT), env)) {
_lastAction = MOVE_RIGHT;
}
}
示例15: main
int main(int argc, char const *argv[])
{
// cout << "Hello world";
Board* board;
cout << "Sample test: " << endl;
board = new Board(3);
board->SetCell(0, 0, 0, 'x');
board->SetCell(0, 0, 1, 'o');
board->SetCell(0, 0, 2, 'x');
board->SetCell(0, 1, 0, 'o');
board->SetCell(0, 1, 1, 'x');
board->SetCell(0, 1, 2, '.');
board->SetCell(0, 2, 0, 'o');
board->SetCell(0, 2, 1, 'x');
board->SetCell(0, 2, 2, 'o');
board->Print(0);
board->Print(1);
cout << "changing board cell [0][2] to 'M' from player 0's perspective would result in the board: " << endl;
board->SetCell(0, 0, 2, 'M');
board->Print(0);
cout << "while changing board cell [0][2] to 'M' from player 1's perspective would result in the board" << endl;
board->Print(1);
cout << "test with size 5" << endl;
board = new Board(5);
board->SetCell(1, 0, 0, 'c');
board->SetCell(0, 0, 4, 'x');
board->SetCell(1, 3, 2, 'l');
board->SetCell(0, 0, 0, 'p');
board->Print(0);
board->Print(1);
board = new Board(5);
board->SetCell(0, 0, 0, 'x');
board->SetCell(0, 1, 1, 'y');
board->SetCell(1, 0, 0, 'g');
board->SetCell(1, 0, 0, 'x');
board->SetCell(0, 0, 0, 'f');
board->SetCell(0, 3, 3, 'p');
board->SetCell(0, 3, 0, 't');
board->SetCell(1, 0, 3, 'l');
board->Print(0);
board->Print(1);
cout << "test with size 19" << endl;
board = new Board(19);
board->SetCell(1, 0, 0, 'c');
board->SetCell(0, 0, 4, 'x');
board->SetCell(1, 3, 2, 'l');
board->SetCell(0, 0, 0, 'p');
board->Print(0);
board->Print(1);
board = new Board(19);
board->SetCell(0, 0, 0, 'x');
board->SetCell(0, 1, 1, 'y');
board->SetCell(1, 0, 0, 'g');
board->SetCell(1, 0, 0, 'x');
board->SetCell(0, 0, 0, 'f');
board->SetCell(0, 3, 3, 'p');
board->SetCell(0, 3, 0, 't');
board->SetCell(1, 0, 3, 'l');
board->Print(0);
board->Print(1);
return 0;
}