/** * Cuando el robot impacta con otro tras moverse. * * @param int dir, Dirección en donde se encuentra el enemigo * @return void */ void onHitRobot(int dir) { if (getActionsLeft() > 0) { wallerFire(dir, wallerFireDmg()); } // si se encuentra con alguien mientras gira por la pared, // comenzar a girar hacia el otro lado y dispararle if (wallReached) { movingType = movingType == 1 ? 0 : 1; } else { // si choca con alguien mientras busca el borde -> esquivarlo diagonalmente switch (dir) { case 8: doMove(7); break; case 6: doMove(9); break; case 2: doMove(3); break; case 4: doMove(1); break; } } }
void QSplitterPrivate::doMove(bool backwards, int hPos, int index, int delta, bool mayCollapse, int *positions, int *widths) { if (index < 0 || index >= list.count()) return; #ifdef QSPLITTER_DEBUG qDebug() << "QSplitterPrivate::doMove" << backwards << hPos << index << delta << mayCollapse; #endif QSplitterLayoutStruct *s = list.at(index); QWidget *w = s->widget; int nextId = backwards ? index - delta : index + delta; if (w->isHidden()) { doMove(backwards, hPos, nextId, delta, collapsible(nextId), positions, widths); } else { int hs =s->handle->isHidden() ? 0 : s->getHandleSize(orient); int ws = backwards ? hPos - pick(s->rect.topLeft()) : pick(s->rect.bottomRight()) - hPos -hs + 1; if (ws > 0 || (!s->collapsed && !mayCollapse)) { ws = qMin(ws, pick(w->maximumSize())); ws = qMax(ws, pick(qSmartMinSize(w))); } else { ws = 0; } positions[index] = backwards ? hPos - ws : hPos + hs; widths[index] = ws; doMove(backwards, backwards ? hPos - ws - hs : hPos + hs + ws, nextId, delta, collapsible(nextId), positions, widths); } }
void wallerMove() { if (!wallReached) { return; } int x = getX(), y = getY(); if (!movingType) { if (x >= 0 && 7 > x && y == 0) { doMove(6); } else if (x > 0 && 7 >= x && y == 7) { doMove(4); } else if (y > 0 && 7 >= y && x == 0) { doMove(2); } else if (y >= 0 && 7 > y && x == 7) { doMove(8); } } else { if (x > 0 && 7 >= x && y == 0) { doMove(4); } else if (x >= 0 && 7 > x && y == 7) { doMove(6); } else if (y >= 0 && 7 > y && x == 0) { doMove(8); } else if (y > 0 && 7 >= y && x == 7) { doMove(2); } } }
bool Fighter::hurt(int x, int d) { bool blocked = blocking; if (((dir - d <= 1) and (dir - d >= -1)) or (dir - d == 5) or (dir - d == -5)) blocked = false; if (blocked) //if it was blocked... { if (blockHitCooldown <= 0) { sp -= 75; blockHitCooldown = 1; if (sp < 0) { //go prone sp = 0; stunTimer = 1.6; spRegen = 1.6; invincible = .3; currentMove = MOVE_NONE; doMove(MOVE_PRONE); } } return false; //report that the attack was blocked } else { //successful hit //take damage (if not temporarily invincible) if (invincible <= 0) { hp -= x; } //get stunned (if not already prone) if (currentMove != MOVE_PRONE) { currentMove = MOVE_NONE; doMove(MOVE_STUN); stunTimer = .6; } else { invincible = .3; } //DEATH if (hp <= 0) { active = false; frame = Frame(0, 0, 0, 0, 0, 0, 0, 0, 0, SHEET_KNIGHT); } return true; //report that the attack was successful } }
bool BoardItem::reposition(PieceItem* piece) { QList<QGraphicsItem *> items = piece->collidingItems(); QMap<double , SquareItem *> rects; { SquareItem *currentSquareItem = d->squares[piece->currentSquare()]; foreach(QGraphicsItem *it, items) { if(SquareItem*square = qgraphicsitem_cast<SquareItem*>(it)) { // if( square == currentSquareItem ) continue; QRectF intersect = square->sceneBoundingRect().intersect(piece->sceneBoundingRect()); rects.insert( intersect.height() * intersect.width(), square ); } } } QList<double> heights = rects.keys(); double max = -1; foreach(double p, heights) { if( p > max ) { max = p; } } if( max > 0 ) { Game::Board board = d->game->board(); Game::Square from = piece->currentSquare(); Game::Square to = rects[max]->logicalIndex(); Game::Move move(board, from, to); if ((to < 8 || to > 55) && (board.at(from) == Game::WhitePawn || board.at(from) == Game::BlackPawn)) { qWarning("PROMOTION!!!!!!"); } if (board.isLegal(move)) { doMove(piece, move); emit moved(board.moveToSAN(move)); return true; } } return false; }
void threadStarter(char thread) { char newSuperBoardSpot = doMove(tData[thread].subBoard, tData[thread].superBoard, tData[thread].opPlayer, tData[thread].move); long result = minimax(tData[thread].subBoard, tData[thread].superBoard, newSuperBoardSpot, MINIMIZE, tData[thread].opPlayer, tData[thread].levels, -9999999999, 9999999999); //undoMove(tData[thread].subBoard, tData[thread].superBoard, tData[thread].move); trData[thread].score = result; trData[thread].move = tData[thread].move; }
void TicTacToe::play() { //player array is 0 indexed, so player 1 is at index 0. int current_player = 0; //resets the board. reset(); printBoard(); while(!isDone()) { std::cout << "Player " << current_player + 1 << "'s turn. \n"; //getCoordinateFromUser is a BoardGame function Coordinate nextMove(getCoordinateFromUser()); while(!isLegalMove(nextMove, player_list_[current_player].getSymbol())) { std::cout << "Invalid move. Please try again.\n"; nextMove = getCoordinateFromUser(); } doMove(nextMove, player_list_[current_player].getSymbol()); printBoard(); if(current_player == 0) current_player = 1; else current_player = 0; } results(); }
void BasicScreenObject::_update(ofEventArgs &e){ if(!isupdating) return; if(age == 1) firstUpdate(); // TODO: use Animation elements equal to Positioners Animator.h // Update Animations based on Tweening if (isMoveTweening) setPosition(tweenx, tweeny, tweenz); if (isScaleTweening) setScale(tweenscalex, tweenscaley, tweenscalez); if (isColorTweening) setColor(tweenr,tweeng,tweenb); if (isSizeTweening) setSize(tweenWidth, tweenHeight); if (isRotationTweening) { ofQuaternion nowquat=getOrientationQuat(); nowquat.slerp(tweenrotslerp, startquat, endquat); setOrientation(nowquat); } // Animations based on Forces and Attractionpoints doRotate(); doMove(); if(isorderbyz) doOrderChildrenByZ(); update(); if(positioners.size()>0){ for(positioner = positioners.begin(); positioner != positioners.end(); positioner++) { IPositioner* p = positioner->second; p->restrict(this); } } age++; }
Move getBestMove(board Game, Piece piece, Point point) { Move possibleMoves[26]; int possibleMovesNumber = getPossibleMoves(Game, piece, possibleMoves, point); Move result = NULL; int bestValue = -INFINITY; for (int i = 0; i < possibleMovesNumber; i++) { doMove(Game, possibleMoves[i]); int moveValue = evaluatePosition(Game, aiPlayerNumber, possibleMoves[i]); if (moveValue > bestValue) { result = possibleMoves[i]; bestValue = moveValue; } undoMove(Game, possibleMoves[i]); } for (int i=0; i<possibleMovesNumber; i++) { if (result != possibleMoves[i]) { cleanMoveData(possibleMoves[i]); } } return result; }
PositionStatus AbstractGame::getPositionStatus() { if(!POSITION_DEFINED()) { if(m_bricksOnBoard <= 1) { DEFINE_POSITION(m_bricksOnBoard == 0, m_bricksOnBoard); } else { bool winnerMoveFound = false; int pliesToWin = 30; int pliesToLoose = 0; for(Move m = firstMove(); m && !winnerMoveFound; m = nextMove(m)) { doMove(m); const PositionStatus status = getPositionStatus(); if(IS_LOOSERSTATUS(status)) { winnerMoveFound = true; if(PLIESTOEND(status) < pliesToWin) { pliesToWin = PLIESTOEND(status); } } else if(!winnerMoveFound) { if(PLIESTOEND(status) > pliesToLoose) { pliesToLoose = PLIESTOEND(status); } } undoMove(m); } if(winnerMoveFound) { DEFINE_POSITION(true , pliesToWin + 1); } else { DEFINE_POSITION(false, pliesToLoose + 1); } } } return m_statusTable[m_board]; }
bool VirtualizeXor(CodeChunk *code, DISASM *disasm) { pushCalculateScaledAddress(code, disasm, &disasm->Argument1); pushCalculateScaledAddress(code, disasm, &disasm->Argument2); doNand(code, disasm); pushCalculateScaledAddress(code, disasm, &disasm->Argument1); doNand(code, disasm); pushCalculateScaledAddress(code, disasm, &disasm->Argument1); pushCalculateScaledAddress(code, disasm, &disasm->Argument2); doNand(code, disasm); pushCalculateScaledAddress(code, disasm, &disasm->Argument2); doNand(code, disasm); doNand(code, disasm); if ((disasm->Argument1.ArgType & MEMORY_TYPE) != 0) { doMove(code, disasm); } else if ((disasm->Argument1.ArgType & REGISTER_TYPE) != 0) { doVmPopReg(code, disasm, getSingleRegister(disasm->Argument1.ArgType)); } return true; }
void OSInterface::doMove(std::string &src, std::string &dst){ std::stringstream ss; if(isDir(src)){ OSInterface os; os.getDirInfo(src, "*"); if(mkdir(dst.c_str(), 0755) == -1) throw new OSException(src, strerror(errno)); for(auto &a : os.dirs){ std::string nsrc, ndst; nsrc = src; nsrc.push_back(dir_sep); nsrc.append(a->name); ndst = dst; ndst.push_back(dir_sep); ndst.append(a->name); doMove(nsrc, ndst); } if(rmdir(src.c_str()) == -1) throw new OSException(src, strerror(errno)); }else{ ss << "Move " << src << " to: " << dst << std::endl; if(((link(src.c_str(), dst.c_str())) == -1) || (unlink(src.c_str()) == -1)) throw new OSException(ss.str(), strerror(errno)); } }
void solveCommand(field f, location to) { location robot[4]; move moves[100]; moves->c = 0; moves->d = 0; for (int i = 1; i <= 4; i++) { int r = findColor(f, i); if (r<0) { printf("could not find robot %d\n", i); exit(-1); } robot[i - 1] = r; } for (int depth = 1; depth < 20; depth++) { if (solve(f, robot, to, depth, moves)) { for (move *m = moves + 1; m->d; m++) { printf("%d: %s\n%s\n", m->c, prettyDirection(m->d), prettyPrint(f)); doMove(f, findColor(f, m->c), m->d); } printf("Final position:\n%s\n", prettyPrint(f)); break; } else { printf("No solution at depth %d!\n", depth); } } }
bool MoveObjectVisitor::visit(UiObjectBinding *ast) { if (didRewriting()) return false; if (ast->qualifiedTypeNameId->identifierToken.offset == objectLocation) { TextModifier::MoveInfo moveInfo; moveInfo.objectStart = objectLocation; moveInfo.objectEnd = ast->lastSourceLocation().end(); // remove leading indentation and property name: int start = ast->firstSourceLocation().offset; int end = moveInfo.objectEnd; includeSurroundingWhitespace(start, end); includeLeadingEmptyLine(start); moveInfo.leadingCharsToRemove = objectLocation - start; // remove trailing indentation moveInfo.trailingCharsToRemove = end - moveInfo.objectEnd; doMove(moveInfo); } return !didRewriting(); }
void Move::doMove(int threadStart, Sphere& target) { int i = 0; while (i < threadStart) { doMove(target); i++; } }
/** * Método principal invocado al comenzar cada turno. * * @return void */ void robotMain() { int movingTo = 0; debug drawAmmo(); debug drawLife(); if (getY() == 7 || getY() == 0 || getX() == 0 || getX() == 7) { wallReached = 1; } if (!wallReached) { movingTo = closestWallDir(); debug printf("[Robot %d] moviendo a: %d\n", getpid(), movingTo); doMove(movingTo); } else { if (look) { look = 0; wallerScan(); // escanea en la dirección opuesta } else { look = 1; wallerMove(); } } }
int solve(field f, location *robot, location to, unsigned max, move *moves) { // printf("max: %d, to: %d, ls: %d,%d,%d,%d\n%s", max, (int)to, (int)robot[0], (int)robot[1], (int)robot[2], (int)robot[3], prettyPrint(f)); if (robot[0] == to) { (moves+1)->d = 0; return 1; } if (max < 1 || lookup(robot, max)) return 0; for (int i = 0; i < 4; ++i) { for (int d = 0; d < 4; ++d) { if (moves->c == i + 1 && moves->d == oppositeDirection(1 << d)) continue; field f2 = cloneField(f); location from = robot[i]; int target = doMove(f2, from, 1 << d); if (target >= 0) { (moves+1)->c = i + 1; (moves+1)->d = 1<<d; robot[i] = target; if (solve(f2, robot, to, max - 1, moves + 1)) { free(f2); return 1; } } free(f2); robot[i] = from; } } return 0; }
/*! Moves the block at (x,y) in the specified direction. Returns the number of blocks moved. */ unsigned Rodent::doMove(unsigned x, unsigned y, direction_t dir) { int xoff = 0; int yoff = 0; unsigned retVal = 0; getOffset(dir, xoff, yoff); switch (blockAt(x+xoff,y+yoff)) { case movable: retVal += doMove(x+xoff, y+yoff, dir); setBlockAt(x+xoff, y+yoff, blockAt(x, y)); setBlockAt(x, y, empty); return retVal+1; case cheese: points += 100; std::cout << "Score: " << points << "\n"; case empty: case mouse: setBlockAt(x+xoff, y+yoff, blockAt(x, y)); setBlockAt(x, y, empty); return retVal+1; default: return retVal; } }
bool VirtualizeAddSub(CodeChunk *code, DISASM *disasm, bool isAdd) { pushCalculateScaledAddress(code, disasm, &disasm->Argument2); if ((disasm->Argument2.ArgType & MEMORY_TYPE) != 0) { doDeref(code, disasm); } pushCalculateScaledAddress(code, disasm, &disasm->Argument1); if ((disasm->Argument1.ArgType & MEMORY_TYPE) != 0) { doDeref(code, disasm); } if (isAdd) { doAdd(code, disasm); } else { doSub(code, disasm); } if ((disasm->Argument1.ArgType & MEMORY_TYPE) != 0) { pushCalculateScaledAddress(code, disasm, &disasm->Argument1); doMove(code, disasm); } else if ((disasm->Argument1.ArgType & REGISTER_TYPE) != 0) { doVmPopReg(code, disasm, getSingleRegister(disasm->Argument1.ArgType)); } return true; }
void BoardItem::doMove(const QString &san) { Game::Board board = d->game->board(); Game::Move move = board.singleMove(san); doMove(d->squares[move.from()]->currentPiece(), move); }
/* * This functions gets the move request (from a board click) * and displays the resulting stone (if valid) */ void qGoBoard::localMoveRequest(StoneColor c, int x, int y) { if (doMove(c,x,y)) { boardwindow->getBoardHandler()->updateMove(tree->getCurrent()); sendMoveToInterface(c,x,y); } }
bool GameState::executeMove(int who, int fieldIndex) { Move m; if(!checkMove(who,fieldIndex,m)) { return false; } doMove(who,m); return true; }
void AbstractGame::executeMove(PositionSet markedPositions) { Move m = findMove(markedPositions); if(m == NULL) { showError(_T("Illegal move:%s"), sprintbin(markedPositions).cstr()); return; } doMove(m); m_playerInTurn = GETOPPONENT(m_playerInTurn); }
HighlightScrollBarOverlay(HighlightScrollBarController *scrollBarController) : QWidget(scrollBarController->scrollArea()) , m_scrollBar(scrollBarController->scrollBar()) , m_highlightController(scrollBarController) { setAttribute(Qt::WA_TransparentForMouseEvents); m_scrollBar->parentWidget()->installEventFilter(this); doResize(); doMove(); show(); }
void Fly::move() { switch(state) { case Reborn: default: pixel.p=corners[id]; state = Living; break; case Living: { doMove(pixel.p.row); doMove(pixel.p.col); } break; } LedMatrix.setPixel(pixel); }
/** * unitTest * * This subroutine emulates a Roomba in the grid world defined by world * It receives an action from the supervisor and updates the world map with its * location. This allows us to determine the next set of sensor data to return * to the supervisor. * * @arg command This is a command from the supervisor * @arg needCleanup Use as Boolean, if TRUE then test is over and need to free memory * * @return char* a string containing fake sensor data */ char* unitTest(int command, int needCleanup) { // Check if we've completed the unit test and need to clean up if(needCleanup) { freeWorld(); return NULL; }//if return doMove(command); }//unitTest
Move AbstractGame::findBestMove(MoveResultArray &moveArray, PlayLevel level) { moveArray.clear(); for(Move m = firstMove(); m; m = nextMove(m)) { doMove(m); const PositionStatus status = getPositionStatus(); moveArray.add(MoveWithResult(m, MAKE_STATUS(IS_LOOSERSTATUS(status),PLIESTOEND(status)+1))); undoMove(m); } moveArray.sort(); return moveArray.selectBestMove(level, m_bricksOnBoard); }
char getBestMove(char subBoard[], char superBoard[], char superBoardSpot, char opPlayer, char levels) { long best = -9999999999; char move; char start, end; char j = 0; char lastSuperBoardState; if (superBoardSpot == -1) { //search all spots on the board start = 0; end = SUB_BOARD_SIZE; } else { start = superBoardSpot * 9; end = start + 9; } threadpool thpool = thpool_init(THREADS); //search within the superboard for (char i = start; i < end; i++) { if (isOpenSpot(subBoard, superBoard, i)) { //Take the winning move is available lastSuperBoardState = superBoard[(i - (i % 9)) / 9]; char newSuperBoardSpot = doMove(subBoard, superBoard, opPlayer, i); if (superBoardWon(superBoard) == opPlayer) { undoMove(subBoard, superBoard, i, lastSuperBoardState); return i; } undoMove(subBoard, superBoard, i, lastSuperBoardState); ThreadData data; data.subBoard = copyBoard(subBoard, SUB_BOARD_SIZE); data.superBoard = copyBoard(superBoard, SUPER_BOARD_SIZE); data.opPlayer = opPlayer; data.levels = levels; data.move = i; tData[j] = data; thpool_add_work(thpool, (void*)threadStarter, j++); } } numThreads = j; thpool_wait(thpool); for (char i = 0; i < numThreads; i++) { if (trData[i].score > best) { best = trData[i].score; move = trData[i].move; } } return move; }
// ----------------------------------------------------------------- // Name : update // ----------------------------------------------------------------- void Character::update(double delta) { MovingObject::update(delta); if (bHasMoveTarget && bCanMove) { doMove(delta * SPEED_CONVERT(speed)); } if (hungryRealTimer <= 0) { checkHungry(); hungryRealTimer = DELTA_HUNGRY_CHECK; } else { hungryRealTimer -= delta; } }
/** * Constructs a board which is the result of applying move \p pMove to board \p pRH * * \param pRH the starting board position * \param pMove the movement to perform * \sa DoMove() */ GameState::GameState(const GameState &pRH,const Move &pMove) { // Copy board memcpy(mCell, pRH.mCell, sizeof(mCell)); // Copy move status mMovesUntilDraw = pRH.mMovesUntilDraw; mNextPlayer = pRH.mNextPlayer; mLastMove = pRH.mLastMove; // Perform move doMove(pMove); }