bool Pawn::pinning(int x, int y) { bool pinning = false; Position diff; diff.x = x - getPos().x; diff.y = y - getPos().y; diff.y *= getColor(); // NOTE: White is -1 and Black 1 // Moving forward. 2 step is allowed if it's the first move if(diff.x == 0 && (diff.y == 1 || (diff.y == 2 && mFirstMove))) { if(getBoard()->getPieceAt(x, y) == NULL) { if(diff.y == 2 && mFirstMove) { if(getBoard()->getPieceAt(x, getPos().y + getColor()) == NULL) pinning = true; } else pinning = true; } } // Capturing diagonally. if(abs(diff.x) == 1 && diff.y == 1) { if(getBoard()->getPieceAt(x, y) != NULL) { if(getBoard()->getPieceAt(x, y)->getColor() != getColor()) pinning = true; } } return pinning; }
void Pawn::moved() { mFirstMove = false; // Check if queen promotion if(getPos().y == 0 && getColor() == WHITE) getBoard()->promotePawn(this); else if(getPos().y == 7 && getColor() == BLACK) getBoard()->promotePawn(this); }
void DecoyBot::move() { setPrevY(getY()); setPrevX(getX()); setPrevDirection(getDirection()); if(!active) { //If decoyList isn't empty, move without blowing up on walls GameTile *oneAhead; switch(getDirection()) { case UP: oneAhead = getBoard()->getTileAt((getY() - 1), getX()); break; case DOWN: oneAhead = getBoard()->getTileAt((getY() + 1), getX()); break; case LEFT: oneAhead = getBoard()->getTileAt(getY(), (getX() - 1)); break; case RIGHT: oneAhead = getBoard()->getTileAt(getY(), (getX() + 1)); break; } //Based on what's ahead, make the appropriate move bool blockAhead = false; vector<Moveable*> oAML = oneAhead->getMoveableList(); vector<Moveable*>::iterator iter = oAML.begin(); for(iter; iter != oAML.end(); ++iter) { if((*iter)->getType() == BLOCK) { blockAhead = true; } } //Move if nothing is in the way if(!(blockAhead || (oneAhead->getPrimaryTerrain() == WALL) || (oneAhead->getPrimaryTerrain() == BOMBABLE) || (oneAhead->getPrimaryTerrain() == LASERABLE) || (oneAhead->getPrimaryTerrain() == DRILLABLE))) { Moveable::move(getDirection(), 1, getPrevY(), getPrevX()); } else { //if we hit a wall, then become active active = true; getBoard()->addToDecoyList(getY(), getX()); } } }
bool checkEnd(TicTacToe* tictactoe) { for (int y = 1; y <= getBoard(tictactoe)->height; ++y) { for (int x = 1; x <= getBoard(tictactoe)->width; ++x) { int i = xy2i(x, y, getBoard(tictactoe)->width, getBoard(tictactoe)->height); if (getBoard(tictactoe)->table[i] == ' ') { return false; } } } return true; }
void addToPTree (PTree p, State s) { Node check = p->root; Board read = getBoard (s); int i; for (i = 0; i < p->boardSize && check->endPoint == NULL; i++) { int contents = getNextLoc (read, i); if (check->next[contents] == NULL) { check->next[contents] = newNode (p->boardSize); } check = check->next[contents]; } // Here's the spot to add it. Did we escape early? if (i < p->boardSize) { // We've found a split. Do the appropriate thing State oldEnd = check->endPoint; check->endPoint = NULL; while (getNextLoc (getBoard (oldEnd), i) == getNextLoc (read, i)) { check->next[getNextLoc (read, i)] = newNode (p->boardSize); check = check->next[getNextLoc (read, i)]; i++; } // We've found a natural split. check->next[getNextLoc (read, i)] = newNode (p->boardSize); check->next[getNextLoc (read, i)]->endPoint = s; check->next[getNextLoc (getBoard (oldEnd), i)] = newNode (p->boardSize); check->next[getNextLoc (getBoard (oldEnd), i)]->endPoint = oldEnd; } else { check->endPoint = s; } }
int Any_Touch(){ int i,j; if(PosX<0) { return 1; } if(getNowLeft()+PosX>10) { return 1; } for(i=0;i<4;i++) { for(j=0;j<4;j++) { int x=PosX+i; int y=PosY-j; int bottom = getNowBottom(i); if(PosY-bottom<-1) { return 1; } if(x>=0&&y>=0&&x<10&&y<20&&getNowBlock(i,j)!=0&&getBoard(x,y)!=0) { return 1; } } } return 0; }
int Connect4::firstEmptyRowAtColumn(int col) { for (int i=0; i<NB_ROWS; i++) { if (getBoard(i, col) == 0) return i; } return -1; }
static void printNode (Node n, int boardSize, int depth) { if (n != NULL) { if (n->endPoint == NULL) { int i; for (i = 0; i < boardSize; i++) { int j; for (j = 0; j < depth; j++) { printf ("\t"); } printf ("%d-->\n", i); printNode (n->next[i], boardSize, depth + 1); } } else { int j; for (j = 0; j < depth; j++) { printf ("\t"); } printBoard (getBoard (n->endPoint)); } } }
bool GboxInstance::Init(uint32_t argc, const char* argn[], const char* argv[]) { m_board = new GameState(1200, 700, 1/1.0); //m_board = new GameState(800, 600, 1/1.0); uint32_t kSampleFrameCount = 2048; sample_frame_count_ = pp::AudioConfig::RecommendSampleFrameCount( PP_AUDIOSAMPLERATE_44100, kSampleFrameCount); pp::AudioConfig audio_config = pp::AudioConfig( this, PP_AUDIOSAMPLERATE_44100, sample_frame_count_); assert(!audio_config.is_null()); m_board->sample(sample_frame_count_); audio_ = pp::Audio(this, audio_config, SoundCallback, this); getBoard()->initSoundBuffer(); this->init_sound(); // FIXME: sound cache belongs here?? //m_board = new GameState(800, 600, 1/1.5); pthread_create(&compute_pi_thread_, NULL, RunBoard, this); return audio_.StartPlayback(); //audio_.StartPlayback(); //return true; }
bool GameState::_isBoardSet(const mgen::FieldSetDepth depth) const { if (depth == mgen::SHALLOW) { return _m_board_isSet; } else { return _m_board_isSet && mgen::validation::validateFieldDeep(getBoard()); } }
int Connect4::lastFilledRowAtColumn(int col) { int last = 0; for (int i=0; i<NB_ROWS; i++) { if (getBoard(i, col) != 0) last = i; } return last; }
/* gets options and */ int main(int argc, char** argv) { int c; int i; opterr = 0; /* gets options */ while ((c = getopt(argc, argv, "t:h:pw:")) != -1) { if (optarg < 0) { fprintf (stderr, "Option -%c requires", optopt); fprintf (stderr, " non-negative argument.\n"); } switch (c) { case 't': turns = atoi(optarg); break; case 'w': width = atoi(optarg); break; case 'h': height = atoi(optarg); break; case 'p': pause1 = 1; break; case '?': if (optopt == 'c') fprintf (stderr, "Option -%c requires an argument.\n", optopt); else if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt); return 1; } } /* allocate space for two boards, one for current position, one for next */ char** board1 = (char**) malloc(width * sizeof(char*)); for (i = 0; i < width; i++) board1[i] = (char*) malloc(height * sizeof(char)); char** board2 = (char**) malloc(width * sizeof(char*)); for (i = 0; i < width; i++) board2[i]= (char*) malloc(height * sizeof(char)); /* print initial state */ getBoard(board1); /* print turns */ for (i = 1; i <= turns; i++) { if (pause1 != 0) { fflush(stdout); sleep(1); } if ((i % 2) != 0) nextBoard(board1, board2); else nextBoard(board2, board1); } }
std::vector<Move> Rook::getPossibleMoves(){ std::vector<Move> possible; for(int i = getRow() - 1; i >= 0; i--){ if (getBoard()->board[i][getColumn()] == NULL){ possible.push_back(Move(i, getColumn())); } else if (getBoard()->board[i][getColumn()]->isWhite() != isWhite()){ possible.push_back(Move(i, getColumn())); break; } else{ break; } } for(int i = getRow() + 1; i < 8; i++){ if (getBoard()->board[i][getColumn()] == NULL){ possible.push_back(Move(i, getColumn())); } else if (getBoard()->board[i][getColumn()]->isWhite() != isWhite()){ possible.push_back(Move(i, getColumn())); break; } else{ break; } } for (int i = getColumn() - 1; i >= 0; i--){ if (getBoard()->board[getRow()][i] == NULL){ possible.push_back(Move(getRow(), i)); } else if (getBoard()->board[getRow()][i]->isWhite() != isWhite()){ possible.push_back(Move(getRow(), i)); break; } else{ break; } } for (int i = getColumn() + 1; i < 8; i++){ if (getBoard()->board[getRow()][i] == NULL){ possible.push_back(Move(getRow(), i)); } else if (getBoard()->board[getRow()][i]->isWhite() != isWhite()){ possible.push_back(Move(getRow(), i)); break; } else{ break; } } return possible; }
bool GameState::operator==(const GameState& other) const { return true && _isRedPlayerSet(mgen::SHALLOW) == other._isRedPlayerSet(mgen::SHALLOW) && _isBluePlayerSet(mgen::SHALLOW) == other._isBluePlayerSet(mgen::SHALLOW) && _isBoardSet(mgen::SHALLOW) == other._isBoardSet(mgen::SHALLOW) && _isPhaseSet(mgen::SHALLOW) == other._isPhaseSet(mgen::SHALLOW) && getRedPlayer() == other.getRedPlayer() && getBluePlayer() == other.getBluePlayer() && getBoard() == other.getBoard() && getPhase() == other.getPhase(); }
bool isThreadUrlValid(const QString &url) { if ( getThread(url).isEmpty() || getBoard(url).isEmpty() || getHost(url).isEmpty() ) { return false; } return true; }
void Touch(){ //for(Touch_i=4;Touch_i>0;Touch_i--) asm("lda #$04");//20 times asm("sta %b",Touch_i); fori: //getBlock_j = Touch_i-1; asm("lda %b",Touch_i); asm("sta %b",getBlock_j); asm("dec %b",getBlock_j); getNowBottom(); //if(getBlock_ret) asm("lda %b",getBlock_ret); asm("beq %g",else1); { //if(getBlock_ret-1==PosY)goto ret1; asm("ldx %b",getBlock_ret); asm("dex"); asm("cpx %b",PosY); asm("beq %g",ret1); //setBoard_x=PosX+Touch_i-1; asm("lda %b",PosX); asm("clc"); asm("adc %b",Touch_i); asm("tax"); asm("dex"); asm("stx %b",setBoard_x); //setBoard_y=PosY-getBlock_ret; asm("lda %b",PosY); asm("sec"); asm("sbc %b",getBlock_ret); asm("sta %b",setBoard_y); getBoard(); //if(setBoard_val)goto ret1; asm("lda %b",setBoard_val); asm("cmp #$00"); asm("bne %g",ret1); }else1: asm("dec %b",Touch_i); asm("bne %g",fori); //return 0; asm("lda #$00"); asm("sta %b",Touch_ret); asm("rts"); ret1: //return 1; asm("lda #$01"); asm("sta %b",Touch_ret); }
bool tiger :: move ( int dy , int dx ) { if( getBoard() == NULL ) cout << "BOARD NULL ERROR !" <<endl ; else { int x = getPosX() ; int y = getPosY() ; if( y + dy < 0 || y + dy > 8 || x + dx < 0 || x + dx > 8 ) return false ; if( getBoard() -> getItem( getPosY() + dy , getPosX() + dx ) -> getItemNo() == 1 ) { if( dy != 0 && dx == 0) { setX ( this->getPosX() + dx * 4 ) ; setY ( this->getPosY() + dy * 4 ) ; } else if ( dy == 0 && dx != 0 ) { setX ( this->getPosX() + dx * 3 ) ; setY ( this->getPosY() + dy * 3 ) ; } } else if( getBoard() -> getItem( getPosY() + dy , getPosX() + dx ) -> getItemNo() != 1) { setX ( this->getPosX() + dx ) ; setY ( this->getPosY() + dy ) ; } } }
/** @param from The old position. @param to The new position. */ void OnlinePlayer::opponentMoved(Position from, Position to) { // Get the piece perhaps gets captured Piece* piece = getBoard()->getPieceAt(to.x, to.y); Piece* movedPiece = getBoard()->getPieceAt(from.x, from.y); if(piece != NULL) { mGui->addCapture(piece->getColor(), piece->getType()); getBoard()->removePiece(piece); pieceCapturedSound(); } else { // Castling? if(movedPiece->getType() == KING && abs(from.x - to.x) == 2) gSound->playEffect(CASTLE_SOUND); else pieceMovedSound(); } movedPiece->setPos(to.x, to.y); movedPiece->moved(); // No longer waiting for the opponent to do a move mWaitingOnMove = false; // Set the last move position setLastMove(from, to); // Checkmate? if(getBoard()->checkMate(getColor())) { mGui->setStatus("Check mate!", RED, 100.0f); gGame->drawAll(); mCheckMate = true; mGui->displayCheckMate(false); gDatabase->addLoss(getName()); } else mGui->setStatus("Your turn!", GREEN, 300.0f); }
void Driver::start(void) { linked_pointer<Driver::callback> cb = callbacks; dbi::start(); while(is(cb)) { cb->start(); cb.next(); } #ifndef _MSWINDOWS_ unsigned pos; Segment *seg; FILE *fp; remove(env("boards")); if(board_count) { fp = fopen(env("boards"), "w"); pos = 0; while(fp && pos < board_count) { seg = getBoard(pos++); if(seg) { fprintf(fp, "%03d %04d %04d %s\n", seg->getInstance(), seg->getFirst(), seg->getCount(), seg->getDescription()); } } if(fp) fclose(fp); } remove(env("spans")); if(span_count) { fp = fopen(env("spans"), "w"); pos = 0; while(fp && pos < span_count) { seg = getSpan(pos++); if(seg) { fprintf(fp, "%03d %04d %04d %s\n", seg->getInstance(), seg->getFirst(), seg->getCount(), seg->getDescription()); } } if(fp) fclose(fp); } #endif }
bool OrdinaryChessFigure::canMoveTo_incr(boardgame::Coords const& to, CoordsIncr const& incr) const { for(boardgame::Coords i = this->getPosition(); i != to; i = i + incr) { boardgame::Figure const* const pf = getBoard()->get(i); if(NULL == pf) { continue; } // field empty if(pf->getPlayer() == this->getPlayer()) { return false; } // field occupied by figure owned by own player if(i != to) { return false; } // this is an enemy figure blocking our way } return true; }
bool chessGame::tryMove(const boardMove &bm) { if (bm.isLegal(getBoard().getLegalMoves(bm.getStart()))){ state.makeMove(bm); history.append(state); redo.clear(); emit madeMove(bm); cantStep = !getCurrentPlayer()->isHuman(); if (cantStep){ getCurrentPlayer()->think(state); } } return false; }
bool ChessFigure::moveCapture(boardgame::MutableBoardTransaction& move) const { boardgame::Coords const& to = move.getTo(); boardgame::BoardOpVec& boardOps = move.getBoardOps(); if( NULL != getBoard()->get(to) ) { boardgame::BoardOp::Operation* pReplace = new boardgame::BoardOp::Replace(to, NULL); boardOps.push_back(pReplace); } boardgame::BoardOp::Operation* pMove = new boardgame::BoardOp::Move(this->getPosition(), to); boardOps.push_back(pMove); return true; }
bool Knight::canMoveTo(boardgame::Coords const& to) const { int ownX = static_cast<int>(getPosition().getX()); int ownY = static_cast<int>(getPosition().getY()); int toX = static_cast<int>(to.getX()); int toY = static_cast<int>(to.getY()); if( (2 == std::abs(ownX - toX) && 1 == std::abs(ownY - toY)) || (1 == std::abs(ownX - toX) && 2 == std::abs(ownY - toY)) ) {// can move return (getBoard()->get(to)->getPlayer() != this->getPlayer()); }else { return false; } }
void CTable::dealCards(Cring *ring, int numcards) { CCard *tmpCard; CpduDealCommunity pdu; char message[100] = "Community Cards dealt "; char vChar[3] = { '\0' }; char sChar; for (; numcards > 0; numcards--) { tmpCard = deck_.popCard(); memset(vChar, 0x0, sizeof(vChar)); switch (tmpCard->getValue()) { case (10): strcpy(vChar, "10"); break; case (11): vChar[0] = 'J'; break; case (12): vChar[0] = 'Q'; break; case (13): vChar[0] = 'K'; break; case (14): vChar[0] = 'A'; break; default: itoa(tmpCard->getValue(), vChar, 10); break; } switch (tmpCard->getSuit()) { case (1): sChar = 'C'; break; // Clubs case (2): sChar = 'D'; break; // Diamonds case (3): sChar = 'H'; break; // Hearts case (4): sChar = 'S'; break; // Spades } getBoard()->addCard(tmpCard); sprintf(message, "%s [%s%c]", message, vChar, sChar); pdu.sendDealCommunity(ring, tmpCard->getValue(), tmpCard->getSuit(), 500); delete tmpCard; } setLog(message); }
int Touch(){ int i; for(i=0;i<4;i++) { char bottom = getNowBottom(i); if(bottom!=0) { if(bottom==PosY+1) { return 1; } if(getBoard(PosX+i,PosY-bottom)!=0) { return 1; } } } return 0; }
void TicTacToeGame::initializeBoard() { if (!getBoard()) { m_board = new BoardValueType*[BOARD_SIZE]; for (int i=0; i<BOARD_SIZE; ++i) { m_board[i] = new BoardValueType[BOARD_SIZE]; } } for (int i=0; i<BOARD_SIZE; ++i) { for (int j=0; j<BOARD_SIZE; ++j) { setBoardValue(EMPTY, i, j); } } }
Component ArduinoUNO::build() { Component board = getBoard(2,_drills_height,_fill_drills,_fourth_drill); Component micro = Cube(35.5,10,7,false).translate(28.5,11.5,2); Component pins = Cube(42.5,2.5,8,false).translate(22.5,49.5,2) + Cube(33.5,2.5,8,false).translate(31.7,1.5,2) + Cube(5,7.5,8,false).translate(62.5,24.5,2); Component usb = Cube(15.875,11.43,11,false).translate(-6.35,32.385,2); Component power = Cylinder(4,14,int(50),false).rotate(0,-90,0).translate(-1.905 + 14,3.175 + 4 + 0.5,8.5) + Cube(14,9,6.5,false).translate(-1.905,3.175,2) + Cube(3.5,9,10.5,false).translate(-1.905,3.175,2); Component capacitors = Cube(6.5,6.5,5,false).translate(17.5,1.6,2) + Cube(6.5,6.5,5,false).translate(25,1.6,2); Component button = Cube(6,6,3,false).translate(52.5,24.5,2); Component arduino = board.color(0,0,0.6) + pins.color(0.2,0.2,0.2) + micro.color(0.2,0.2,0.2) + usb.color(0.7,0.7,0.7) + power.color(0.7,0.7,0.7) + capacitors.color(0.5,0.5,0.5) + button.color(0.5,0.5,0.5); return arduino; }
void displaySorted(std::vector<t_test_struct> t) { StdOutDisplay d; std::sort(t.begin(), t.end(), [](const t_test_struct & a, const t_test_struct & b) -> bool { return a.calcRes > b.calcRes; }); for (auto f : t) { if (f.res == MAGIC) continue ; std::cout << "expected: " << f.res << " calculated: " << f.calcRes << std::endl; d.displayBoard(*getBoard(f.filename)); std::cout << "------------------" << std::endl; } }
void test_board(t_test_struct &t, bool disp) { StdOutDisplay d; MHeuristic h; auto b = getBoard(t.filename); int res; res = h.eval(b, t.color); t.success = res == t.res; t.runned = true; t.calcRes = res; if (!t.success || disp) { std::cout << "Trying " << t.desc << ":" << std::endl; if (!t.success) std::cout << "Failure" << std::endl; d.displayBoard(*b); std::cout << "Expected: " << t.res << " eval: " << res << std::endl; } }
//! Restart the match. void OnlinePlayer::restartMatch() { // Reset data mCheckMate = false; mWaitingOnAnswer = false; mDelay = 0; setLastMove(); getBoard()->reset(); if(getColor() == WHITE) mWaitingOnMove = false; else mWaitingOnMove = true; mGui->setStatus("Nothing", RED, 0.0f); if(getColor() == WHITE) mGui->setStatus("Your turn!", GREEN, 300.0f); mGui->clearCaptures(); mGui->clearStats(); mGui->initStats(); }