void* nonGeekArrives(void *data){ sem_wait(&mutex); c_ngeek++; board(); sem_post(&mutex); sem_wait(&s_ngeek); pthread_exit(NULL); }
void GenericTetrix::hideBoard() { int i,j; erasePiece(); for(i = height - nClearLines - 1 ; i >= 0 ; i--) for(j = 0 ; j < width ; j++) if (board(j,i) != 0) draw(j,i,0); }
int main() { Draw win; Board board(win.getW() + 1, win.getH() + 1); Player player; Game game(board, win, player); srand(time(NULL)); game.lauchGame(); }
void GenericTetrix::fillRandom(int line) { int i,j; int holes; for(i = 0 ; i < width ; i++) board(i,line) = TetrixPiece::randomValue(7); holes = 0; for(i = 0 ; i < width ; i++) if (board(i,line) == 0) // Count holes in the line. holes++; if (holes == 0) // Full line, make a random hole: board(TetrixPiece::randomValue(width),line) = 0; if (holes == width) // Empty line, make a random square: board(TetrixPiece::randomValue(width),line) = TetrixPiece::randomValue(6) + 1; for(j = 0 ; j < width ; j++) draw(j,i,board(j,i)); }
int totalNQueens(int n) { int result = 0; vector<string>board(n, string(n, '.')); solveNQueens_helper(n, board, result, 0); return result; }
void UciEngine::startPondering() { if (m_ponderMove.isNull()) return; m_moveStrings += " " + board()->moveString(m_ponderMove, Chess::Board::LongAlgebraic); sendPosition(); ping(); startThinking(); }
void* singerArrives(void *data){ sem_wait(&mutex); c_singer++; board(); sem_post(&mutex); sem_wait(&s_singer); pthread_exit(NULL); }
bool ComplexTetris::tryMove(const Tetronimo &newPiece, int newX, int newY){ if(board().isFree(newPiece, newX, newY)){ game->setCurrentPiece(newPiece); curX = newX; curY = newY; return true; } else { return false; } }
vector<vector<string>> solveNQueens(int n) { vector<vector<string>> ans; if (n < 1) return ans; BOARD_LEN = n; vector<string> board(n, string(n, '.')); colOfQueenAtRow = vector<int>(n, -1); helper(0, board, ans); return ans; }
TEST(Board, parameterizedConstructor) { int testSpace[] = { 1, 1, 1, 1 }; Board board(2, 2, testSpace); ASSERT_EQ(board.getMaxCols(), 2); ASSERT_EQ(board.getMaxRows(), 2); ASSERT_TRUE(testBoardSpace(board, testSpace)); }
void UciEngine::startGame() { Q_ASSERT(supportsVariant(board()->variant())); m_ignoreThinking = false; m_rePing = false; m_ponderState = NotPondering; m_ponderMove = Chess::Move(); m_bmBuffer.clear(); m_moveStrings.clear(); if (board()->isRandomVariant()) m_startFen = board()->fenString(Chess::Board::ShredderFen); else m_startFen = board()->fenString(Chess::Board::XFen); QString uciVariant(variantToUci(board()->variant())); if (uciVariant != m_variantOption) { if (!m_variantOption.isEmpty()) sendOption(m_variantOption, false); m_variantOption = uciVariant; } if (!m_variantOption.isEmpty()) sendOption(m_variantOption, true); write("ucinewgame"); if (m_canPonder) sendOption("Ponder", pondering()); if (m_sendOpponentsName) { QString opType = opponent()->isHuman() ? "human" : "computer"; QString value = QString("none none %1 %2") .arg(opType) .arg(opponent()->name()); sendOption("UCI_Opponent", value); } sendPosition(); }
void GenericTetrix::clearBoard(int fillRandomLines) { int i,j; if (fillRandomLines >= height) fillRandomLines = height - 1; erasePiece(); for(i = height - nClearLines - 1 ; i >= fillRandomLines ; i--) for(j = 0 ; j < width ; j++) if (board(j,i) != 0) { draw(j,i,0); board(j,i) = 0; } if (fillRandomLines != 0) for (i = 0 ; i < fillRandomLines ; i++) { fillRandom(i); } nClearLines = height - fillRandomLines; }
void CMoveGen::getEvasions(CMoveList& moves) const { bb_t mask_evasion = bbEmptyBoard; EColor side = board().getSide(); bb_t x = board().getPieceBits(eKing, side); while (x) { EField kingpos = popFirstBit(x); bb_t attacks = board().getAttackBy(kingpos, toggleColor(side)); mask_evasion |= attacks; while (attacks) { EField from = popFirstBit(attacks); mask_evasion |= gl_bitboards.getGap(from, kingpos); } } genMoves(moves, true, true, bbFullBoard, mask_evasion); }
vector<vector<string> > solveNQueens(int n) { vector<vector<string> > solutions; vector<string> board(n); for(int i=0;i<n;++i) { for(int j=0;j<n;++j) { board[i] = board[i] + "."; } } solveNQueensOnRow(n, 0, solutions, board); return solutions; }
void EmptyTest() { std::cout << "TEST EMPTY\n"; TBoard board(0, 0); std::cout << board.ToString(); size_t collapsed = board.CollapseRows(); std::cout << "Collapsed " << collapsed << " rows\n"; std::cout << board.ToString(); }
void BoardController::_moveFigure(int from, int to, Figure::Type displacer_type, Figure::Side displacer_side) { std::swap(m_figures[from], m_figures[to]); auto displacer = m_figures[from]; displacer->setType(displacer_type); displacer->setSide(displacer_side); qDebug() << "Move from " << from << " to " << to; emit boardChanged(board()); }
TEST(Borad, canMapBiominoWithHole) { int testSpace[] = { 1, 1, 1, 0 }; Board board(2, 2, testSpace); Biomino biomino(Cell(0,0), Cell(0,1)); ASSERT_TRUE (board.canShapeMap(0,0,biomino)); ASSERT_FALSE(board.canShapeMap(1,0,biomino)); ASSERT_FALSE(board.canShapeMap(0,1,biomino)); ASSERT_FALSE(board.canShapeMap(1,1,biomino)); }
/** * Creates a board containing all moves up to (including) the move with the given number. * * @param moveNo Move number. * @return Board containing all moves up to (including) the given move. */ GameLogic::FourInALine::Board Replay::computeBoard(unsigned int moveNo) const { GameLogic::FourInALine::Board board(this->nColumns, this->nRows); for (unsigned int i = 0; i <= moveNo; ++i) { board.dropToken(this->getMove(i).second, this->getMove(i).first); } return board; }
int main() { cout << "Please input the number of rows: "; int m; cin >> m; cout << "Please input the number of cols: "; int n; cin >> n; vector<vector<char> > board(m, vector<char>(n, '.')); cout << "Please input a 2D board: "; for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { char val; cin >> val; board[i][j] = val; } } for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { cout << board[i][j] << " "; } cout << endl; } while(1) { cout << "Please input a word: "; string word; cin.clear(); getline(cin, word); // getline属于string流,与cin.getline不同 cin >> word; Solution s; int result = s.exist(board, word); if (result) cout << "True! " << endl; else cout << "False! " << endl; } system("pause"); return 0; }
AnalyzeResult AI::actuate(const RawBoard ¤t_board) { std::unique_ptr<GameBoard> board(new GameBoard(current_board)); default_clock::time_point start = default_clock::now(); AnalyzeResult move = analyze(std::move(board)); std::chrono::duration<double> elapsed = default_clock::now() - start; logfile << "ai [move=" << (_move_count+1) << "]: eval time = " << elapsed.count() << " seconds" << std::endl; if (std::get<1>(move)) { _move_count++; } return move; }
// // Constructor // Dealer::Dealer( Game &g ) { game_ = &g; deck_ = game_->set_deck(); Player board("Board"); board_ = board; Player wallace("Wallace"); partner_ = wallace; Player scott("Scott"); ai1_ = scott; Player ramona("Ramona"); ai2_ = ramona; }
vector<vector<string> > solveNQueens(int n) { // write your code here vector<vector<string> > res; if(n==2 || n == 3 || n <= 0) { return res; } string s(n, '.'); // construction vector<string> board(n, s); solveNQueens(res, board, 0, n); return res; }
TEST(Board, boardIndex) { int testSpace[] = { 1, 0, 0, 1 }; Board board(2, 2, testSpace); ASSERT_EQ(board.getMaxCols(), 2); ASSERT_EQ(board.getMaxRows(), 2); ASSERT_EQ(board.getIndex(0), 0); ASSERT_EQ(board.getIndex(1), -1); ASSERT_EQ(board.getIndex(2), -1); ASSERT_EQ(board.getIndex(3), 1); }
std::string GetPosition(const char* arg) { Board board(Variant::SUICIDE); MoveGeneratorSuicide movegen(board); const auto move_str_vec = SplitString(arg, ' '); for (const auto& move_str : move_str_vec) { const Move move = SANToMove(move_str, board, &movegen); if (!move.is_valid()) { throw std::invalid_argument("Invalid move " + move_str); } board.MakeMove(move); } return board.ParseIntoFEN(); }
void GenericTetrix::removeFullLines() { int i,j,k; int nFullLines; for(i = 0 ; i < height - nClearLines ; i++) { for(j = 0 ; j < width ; j++) if (board(j,i) == 0) break; if (j == width) { nFullLines = 1; for(k = i + 1 ; k < height - nClearLines ; k++) { for(j = 0 ; j < width ; j++) if (board(j,k) == 0) break; if (j == width) { nFullLines++; } else { for(j = 0 ; j < width ; j++) { if (board(j,k - nFullLines) != board(j,k)) { board(j,k - nFullLines) = board(j,k); draw( j,k - nFullLines, board(j,k - nFullLines)); } } } } nClearLines = nClearLines + nFullLines; nLinesRemoved = nLinesRemoved + nFullLines; updateRemoved(nLinesRemoved); score = score + 10*nFullLines; // updateScore must be // called by caller! for (i = height - nClearLines ; i < height - nClearLines + nFullLines ; i++) for(j = 0 ; j < width ; j++) if (board(j,i) != 0) { draw(j,i,0); board(j,i) = 0; } } } }
const bool BoardListXML::ParseXML(const std::string &xml) { bool parsed=false; Poco::XML::DOMParser dp; dp.setEntityResolver(0); Initialize(); try { Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml)); Poco::XML::Element *root=XMLGetFirstChild(doc,"BoardList"); Poco::XML::Element *boardel=NULL; boardel=XMLGetFirstChild(root,"Board"); while(boardel) { std::string name=""; std::string description=""; Poco::XML::Element *txt=XMLGetFirstChild(boardel,"Name"); if(txt && txt->firstChild()) { name=SanitizeSingleString(txt->firstChild()->getNodeValue()); StringFunctions::LowerCase(name,name); } txt=XMLGetFirstChild(boardel,"Description"); if(txt && txt->firstChild()) { description=SanitizeSingleString(txt->firstChild()->getNodeValue()); } if(name!="" && description!="") { m_boards.push_back(board(name,description)); } boardel=XMLGetNextSibling(boardel,"Board"); } parsed=true; } catch(...) { } return parsed; }
bool Consumer::beginGame(TagSet const& tags) { if (board().notDerivableFromChess960()) return false; m_stream.reset(sizeof(m_buffer)); m_stream.resetp(); m_data.resetp(); m_text.resetp(); Encoder::setup(board()); m_streamPos = m_strm.tellp(); m_strm << uint24_t(0); // place holder for offset to text section m_strm << uint16_t(0); // place holder for run length m_move = Move::empty(); m_runLength = 0; m_endOfRun = false; m_danglingPop = false; m_danglingEndMarker = 1; m_lastCommentPos = 0; return true; }
int main() { Solution s; { std::vector<std::vector<char> > board(4, std::vector<char>(4, 0)); board[0][0]='X'; board[0][1]='X'; board[0][2]='X'; board[0][3]='X'; board[1][0]='X'; board[1][1]='O'; board[1][2]='O'; board[1][3]='X'; board[2][0]='X'; board[2][1]='X'; board[2][2]='O'; board[2][3]='X'; board[3][0]='X'; board[3][1]='O'; board[3][2]='X'; board[3][3]='X'; s.solve(board); print(board); } return 0; }
void BoardSetupDialog::slotEnPassantSquare() { Board b(board()); if(ui.epCombo->currentIndex() == 0) { b.clearEnPassantSquare(); } else { int shift = b.toMove() == White ? 39 : 15; b.setEnPassantSquare(shift + ui.epCombo->currentIndex()); } setBoard(b); }
void GAME :: change(int i,int j,int p,int q) { A[p][q].coin=A[i][j].coin; A[p][q].color=A[i][j].color; A[i][j].coin='N'; A[i][j].color=null; board(); coins(); setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); setcolor(RED); outtextxy(10,getmaxy()-15,"Congrats !! You advance to next level !!"); level++; getch(); }