bool Pawn::canMove(int x, int y, int move_x, int move_y) { if(isPromoted()) { return move_x == 0 || move_y == 0 || abs(move_x)==abs(move_y); } int dir = getSide()==0?-1:1; if(move_x == 0) { if(board_->get(x,y+dir) != NULL) { return false; } if(move_y == dir) { return true; } if(!isMoved() && move_y==dir*2) { return board_->get(x,y+move_y)==NULL; } return false; } if(move_y != dir) { return false; } if(abs(move_x) != 1) { return false; } Man *target = board_->get(x+move_x,y+move_y); return target?target->getSide()!=getSide():false; }
int Search::search(bool smp, int depth, int alpha, int beta) { ASSERT_RANGE(depth, 0, MAX_PLY); if (smp) { return getSide() ? search<WHITE, SMP_YES>(depth, alpha, beta, &pvLine, bitCount(getBitmap<WHITE>() | getBitmap<BLACK>()), &mainMateIn) : search<BLACK, SMP_YES>(depth, alpha, beta, &pvLine, bitCount(getBitmap<WHITE>() | getBitmap<BLACK>()), &mainMateIn); } else { return getSide() ? search<WHITE, SMP_NO>(depth, alpha, beta, &pvLine, bitCount(getBitmap<WHITE>() | getBitmap<BLACK>()), &mainMateIn) : search<BLACK, SMP_NO>(depth, alpha, beta, &pvLine, bitCount(getBitmap<WHITE>() | getBitmap<BLACK>()), &mainMateIn); } }
double calcCrArea(point dot1, point dot2, point dot3) { double side1 = getSide(dot1, dot2); double side2 = getSide(dot2, dot3); double side3 = getSide(dot3, dot1); double halfP = (side1 + side2 + side3) / 2; return 3.14 * (halfP - side1) * (halfP - side2) * (halfP - side3) / halfP; }
double calcTrArea(point dot1, point dot2, point dot3) { double side1 = getSide(dot1, dot2); double side2 = getSide(dot2, dot3); double side3 = getSide(dot3, dot1); double halfP = (side1 + side2 + side3) / 2; return sqrt( halfP*(halfP - side1) * (halfP - side2) * (halfP - side3) ); }
SEXP Dsymm(SEXP ENV, SEXP A, SEXP B, SEXP C, SEXP ALPHA, SEXP BETA, SEXP SIDE, SEXP UPLO) { cl_env *env = get_env(ENV); int allocated = 0; MATRIXCHECK(A, REALSXP); MATRIXCHECK(B, REALSXP); SCALARCHECK(ALPHA, REALSXP); SCALARCHECK(BETA, REALSXP); clblasSide side = getSide(SIDE); clblasUplo uplo = getUplo(UPLO); double alpha = SCALARREAL(ALPHA), beta = SCALARREAL(BETA); int ar = nrows(A), ac = ncols(A), br = nrows(B), bc = ncols(B), cr, cc; if (isNull(C) || LENGTH(C) == 0) { cr = br, cc = bc; C = PROTECT(allocMatrix(REALSXP, cr, cc)); beta = 0; allocated = 1; } else { MATRIXCHECK(C, REALSXP); cr = nrows(C), cc = ncols(C); } int size_a = LENGTH(A) * sizeof(double); int size_b = LENGTH(B) * sizeof(double); int size_c = LENGTH(C) * sizeof(double); double *ap = REAL(A), *bp = REAL(B), *cp = REAL(C); cl_int err = Dsymm_internal( env, ap, bp, cp, alpha, beta, side, uplo, ar, ac, br, bc, cr, cc, size_a, size_b, size_c); CHECK(err); UNPROTECT(allocated); return C; }
bool CFBTeam::canShootDirectly(CFBPlayer* player) { auto side = getSide(); auto pitch = FBMATCH->getPitch(); auto otherSide = pitch->getOtherSide(side); auto gp = pitch->getGoalPos(otherSide); auto otherTeam = FBMATCH->getTeam(otherSide); auto teamMember = otherTeam->getTeamMembers(); for (auto t : teamMember) { if (FBDefs::isPointOnTheWay(player->getPosition(), gp, t->getPosition())) { return false; } } teamMember = getTeamMembers(); for (auto t : teamMember) { if (t != player && FBDefs::isPointOnTheWay(player->getPosition(), gp, t->getPosition())) { return false; } } return true; }
void CX3DCylinderNode::print(int indent) { FILE *fp = CX3DParser::getDebugLogFp(); char *nodeName = getNodeName(); if (nodeName) { CX3DParser::printIndent(indent); fprintf(fp, "%s (%s)\n", nodeName, CX3DNode::getNodeTypeString(getNodeType())); CX3DParser::printIndent(indent+1); fprintf(fp, "solid : %s\n", getSolid()->getValue() ? "TRUE" : "FALSE"); CX3DParser::printIndent(indent+1); fprintf(fp, "radius : (%f)\n", getRadius()->getValue()); CX3DParser::printIndent(indent+1); fprintf(fp, "height : (%f)\n", getHeight()->getValue()); CX3DParser::printIndent(indent+1); fprintf(fp, "bottom : %s\n", getBottom()->getValue() ? "TRUE" : "FALSE"); CX3DParser::printIndent(indent+1); fprintf(fp, "side : %s\n", getSide()->getValue() ? "TRUE" : "FALSE"); CX3DParser::printIndent(indent+1); fprintf(fp, "top : %s\n", getTop()->getValue() ? "TRUE" : "FALSE"); } }
// 进攻方对方禁区拿球,强制触发一次空中遭遇。 void CFBMatch::checkEncounterInPenaltyArea() { // TODO: 仅当传球,二过一,随机球 刚刚结束,否则直接返回。二过一和随机球还未做判断 if (m_recentEndedFlow != FBDefs::MATCH_FLOW_TYPE::PASSBALL) return; if (m_menuType != FBDefs::MENU_TYPE::NONE) return; auto team = this->getAttackingTeam(); auto side = team->getSide(); auto ballPos = getBallPosition(); if (m_pitch->isInPenaltyArea(ballPos, m_pitch->getOtherSide(side))) { m_encounterTime = -1; m_isAir = true; auto conTeam = getControlSideTeam(); if (conTeam->isAttacking()) { m_menuType = FBDefs::MENU_TYPE::ENCOUNTER_ATK_OPPSITE_A; m_involvePlayerIds.clear(); m_involvePlayerIds.push_back(conTeam->getHilightPlayerId()); } else { m_menuType = FBDefs::MENU_TYPE::ENCOUNTER_DEF_SELF_A; m_involvePlayerIds.clear(); for (auto p : m_defendPlayerIds) { m_involvePlayerIds.push_back(p); } } } }
void kore::Camera::moveSideways(float fSpeed) { if (!_sceneNode) { return; } _sceneNode->translate(getSide() * fSpeed, SPACE_WORLD); }
public: void free(){ for(int iside=0; iside<4; iside++){ Side* side = getSide(iside); if(side != NULL) for(int jrib=0; jrib<4; jrib++){ if(this == side->getRib(jrib)){ side->setRib(NULL, jrib); break; } } } for(int icell=0; icell<4; icell++){ Cell* cell = getCell(icell); if(cell != NULL) for(int jrib=0; jrib<4; jrib++){ if(this == cell->getRib(getAxis(), jrib)){ cell->setRib(getAxis(), jrib, NULL); break; } } } for(int i=0; i<4; i++){ setSide(i, NULL); setCell(i, NULL); } //cout << "delete " << this << endl;; delete this; }
void SettingsWindow::on_finishKegButton_clicked() { int choice = getSide(); bool confirmed = false; if (choice == LEFT_TAP && Keg::LeftKeg != NULL) confirmed = QMessageBox::question(this, "Finish Keg", "Are you sure you want to finish the left keg?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes; if (choice == CENTER_TAP && Keg::CenterKeg != NULL) confirmed = QMessageBox::question(this, "Finish Keg", "Are you sure you want to finish the center keg?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes; if (choice == RIGHT_TAP && Keg::RightKeg != NULL) confirmed = QMessageBox::question(this, "Finish Keg", "Are you sure you want to finish the right keg?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes; if (confirmed) { if (choice == LEFT_TAP) Keg::LeftKeg = NULL; if (choice == CENTER_TAP) Keg::CenterKeg = NULL; if (choice == RIGHT_TAP) Keg::RightKeg = NULL; Keg::SaveKegs(); QMessageBox::information(this, QString("Keg Finished"), QString("%1 keg marked finished!").arg(choice == LEFT_TAP ? "Left" : choice == CENTER_TAP ? "center" : "Right"), QMessageBox::Ok); } }
//this function corrects the position of a rectangle if it is colliding with another rectangle void CollisionDetection::correctPosition(Rect* _player, Rect* _platform) { //left = 1, bottom = 2, right = 3, top = 4 if (!_player->getFixed() && CheckRectangleIntersect(_player, _platform)) { switch (getSide(_player, _platform)) { case 1: if (_player->getxVel() > 0) { _player->setxVel(0); } _player->setX(_platform->getX() - _player->getWidth()); break; case 3: if (_player->getxVel() < 0) { _player->setxVel(0); } _player->setX(_platform->getX() + _platform->getWidth()); break; case 2: if (_player->getyVel() < 0) { _player->setyVel(0); } _player->setY(_platform->getY() + _platform->getHeight()); break; case 4: if (_player->getyVel() > 0) { _player->setyVel(0); } _player->setY(_platform->getY() - _player->getHeight()); break; } } }
void CollisionDetection::correctPositionParticle(Particle* _particle, Rect* _platform) { //left = 1, bottom = 2, right = 3, top = 4 Rect* _player = new Rect(_particle->getPosition(), _particle->getWidth(), _particle->getHeight(), 0, 0, false, player, false, new Graphics); if (!_player->getFixed() && CheckRectangleIntersect(_player, _platform)) { switch (getSide(_player, _platform)) { case 1: if (_particle->getxVel() > 0) { _particle->setxVel(0); } _particle->setX(_platform->getX() - _particle->getWidth()); break; case 3: if (_particle->getxVel() < 0) { _particle->setxVel(0); } _particle->setX(_platform->getX() + _platform->getWidth()); break; case 2: if (_particle->getyVel() < 0) { _particle->setyVel(0); } _particle->setY(_platform->getY() + _platform->getHeight()); break; case 4: if (_particle->getyVel() > 0) { _particle->setyVel(_particle->getyVel()*-0.5); } _particle->setY(_platform->getY() - _particle->getHeight()); break; } } delete _player; }
void initializeCellSpace(int size) { auto cs = CellNodeSpace<DIMS>(); cs.initWithOneCell(size); CHECK("Has only one cell", cs.countCells() == 1); auto bounds = cs.getBounds(); CHECK("Is cube", bounds.isCube()); CHECK("Has correct size", bounds.getSide() == 1<<size); }
//----------------------------------------------------------------------- Plane::Side Plane::getSide (const AxisAlignedBox& box) const { if (box.isNull()) return NO_SIDE; if (box.isInfinite()) return BOTH_SIDE; return getSide(box.getCenter(), box.getHalfSize()); }
//----------------------------------------------------------------------- DiPlane::Side DiPlane::getSide (const DiAABB& box) const { if (box.IsNull()) return NO_SIDE; if (box.IsInfinite()) return BOTH_SIDE; return getSide(box.GetCenter(), box.GetHalfSize()); }
//------------------------------------------------------------------------------ // updatePhysicalEntity() -- (Output support) // -- sets the PhysicalEntity attribute values that need to be updated // // -- We send all published PhysicalEntity attributes every time. // The function isPlayerStateUpdateRequired() check if the player's state // needs to be re-sent. Therefore, we're not checking the individual update // required flags with isAttributeUpdateRequired(), but we do clear them // with setAttributeUpdateRequiredFlag(). // // (Also handles the host to network byte swapping) //------------------------------------------------------------------------------ void Nib::updatePhysicalEntity( RTI::AttributeHandleValuePairSet* attrs, const double) { // PhysicalEntity?? PhysicalEntity* physicalEntity = dynamic_cast<PhysicalEntity*>(baseEntity); if (physicalEntity != nullptr) { // Our handler NetIO* netIO = static_cast<NetIO*>(getNetIO()); // Force Identifier if (isAttributeUpdateEnabled(NetIO::FORCE_IDENTIFIER_AI)) { // Force ID: When mapping Player side to force IDs ... if (getSide() == simulation::Player::BLUE) { // blue's are friendly, ... physicalEntity->forceIdentifier = FRIENDLY; } else if (getSide() == simulation::Player::RED) { // red's are not, ... physicalEntity->forceIdentifier = OPPOSING; } else if (getSide() == simulation::Player::WHITE) { // white is neutral, ... physicalEntity->forceIdentifier = NEUTRAL; } else { // and everyone else is type OTHER. physicalEntity->forceIdentifier = OTHER; } //std::cout << "Send force: " << physicalEntity->forceIdentifier << std::endl;; unsigned char netBuffer = static_cast<unsigned char>(physicalEntity->forceIdentifier); // 8 bits enum type (ForceIdentifierEnum8) attrs->add(netIO->getObjectAttributeHandle( NetIO::FORCE_IDENTIFIER_AI), reinterpret_cast<char*>(&netBuffer), sizeof(netBuffer) ); setAttributeUpdateRequiredFlag(NetIO::FORCE_IDENTIFIER_AI, false); } } }
// A function used by library function qsort() to sort an array of // points with respect to the first point int compare(const void *vp1, const void *vp2) { PointI *p1 = (PointI *)vp1; PointI *p2 = (PointI *)vp2; int side = getSide(p0, *p2, *p1); if (side == 0) return (dist(p0, *p2) >= dist(p0, *p1)) ? -1 : 1; return side; }
bool containtPoints(unsigned char v){ unsigned char j; for(j=0;j<8;j++){ //if(getBit(v,j)) if(getSide(j)==0){ return true; } } return false; }
void CylinderNode::recomputeDisplayList() { unsigned int nCurrentDisplayList = getDisplayList(); if (0 < nCurrentDisplayList) glDeleteLists(nCurrentDisplayList, 1); unsigned int nNewDisplayList = glGenLists(1); glNewList(nNewDisplayList, GL_COMPILE); GLUquadricObj *quadObj; glFrontFace(GL_CCW); glPushMatrix (); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glRotatef (180.0, 0.0, 1.0, 0.0); glMatrixMode(GL_MODELVIEW); glRotatef (180.0, 0.0, 1.0, 0.0); glRotatef (90.0, 1.0, 0.0, 0.0); glTranslatef (0.0, 0.0, -getHeight()/2.0f); if (getSide()) { quadObj = gluNewQuadric (); gluQuadricDrawStyle(quadObj, GLU_FILL); gluQuadricNormals(quadObj, GLU_SMOOTH); gluQuadricTexture(quadObj, GL_TRUE); gluCylinder(quadObj, getRadius(), getRadius(), getHeight(), 12, 2); gluDeleteQuadric(quadObj); } if (getTop()) { glPushMatrix (); glRotatef (180.0, 1.0, 0.0, 0.0); quadObj = gluNewQuadric (); gluQuadricTexture(quadObj, GL_TRUE); gluDisk(quadObj, 0.0, getRadius(), 12, 2); gluDeleteQuadric(quadObj); glPopMatrix (); } if (getBottom()) { glTranslatef (0.0, 0.0, getHeight()); quadObj = gluNewQuadric (); gluQuadricTexture(quadObj, GL_TRUE); gluDisk(quadObj, 0.0, getRadius(), 12, 2); gluDeleteQuadric(quadObj); } glPopMatrix (); glEndList(); setDisplayList(nNewDisplayList); };
void MesherFixedEvenStem::calcIndices(otTriangles* triangles) { if (circleRes <= 2) circleRes = 3; if (curveRes <= 0) curveRes = 1; getCap(triangles, false); for (int j = -1; j<curveRes+1; j++) { getSide(j, j+1, triangles); } getCap(triangles, true); }
void kore::Camera::rotateFromMouseMove(float dx, float dy) { // Ugly hack incoming here... static bool bFistTime = true; if (bFistTime) { bFistTime = false; return; } rotateViewQuat(dx, glm::vec3(0.0f, 1.0f, 0.0f)); rotateViewQuat(dy, getSide()); }
int Search::printDtm() { int side = getSide(); u64 friends = side == WHITE ? getBitmap<WHITE>() : getBitmap<BLACK>(); u64 enemies = side == BLACK ? getBitmap<WHITE>() : getBitmap<BLACK>(); display(); int res = side ? getGtb().getDtm<WHITE, true>(chessboard, chessboard[RIGHT_CASTLE_IDX], 100) : getGtb().getDtm<BLACK, true>(chessboard, chessboard[RIGHT_CASTLE_IDX], 100); cout << " res: " << res; incListId(); generateCaptures(side, enemies, friends); generateMoves(side, friends | enemies); _Tmove *move; u64 oldKey = 0; cout << "\n succ. \n"; int best = -_INFINITE; for (int i = 0; i < getListSize(); i++) { move = &gen_list[listId].moveList[i]; makemove(move, false, false); cout << "\n" << decodeBoardinv(move->type, move->from, getSide()) << decodeBoardinv(move->type, move->to, getSide()) << " "; res = side ? -getGtb().getDtm<BLACK, true>(chessboard, chessboard[RIGHT_CASTLE_IDX], 100) : getGtb().getDtm<WHITE, true>(chessboard, chessboard[RIGHT_CASTLE_IDX], 100); if (res != -INT_MAX) { cout << " res: " << res; } cout << "\n"; takeback(move, oldKey, false); if (res > best) { best = res; } } if (best > 0) { best = _INFINITE - best; } else if (best < 0) { best = -(_INFINITE - best); } cout << endl; decListId(); return best; }
unsigned char getN(){ unsigned char n=0; int j; for(j=0;j<8;j++){ unsigned char temp=1; if(getSide(j)==1){//lado derecho temp=1; temp=1<<j; }else{// lado izquierdo temp=0; } n=n|temp; } return n; }
void OpenSteer::SimpleVehicle::measurePathCurvature (const float elapsedTime) { if (elapsedTime > 0) { const Vector3 dP = _lastPosition - getPosition(); const Vector3 dF = (_lastForward - getForward()) / dP.length(); const Vector3 lateral = Vec3Utils::perpendicularComponent(dF, getForward()); const float sign = (lateral.dotProduct(getSide()) < 0) ? 1.0f : -1.0f; _curvature = lateral.length() * sign; blendIntoAccumulator (elapsedTime * 4.0f, _curvature, _smoothedCurvature); _lastForward = getForward(); _lastPosition = getPosition(); } }
public: void free(){ /* if(isSplitted()){ for(int i=0; i<2; i++){ subribs[i]->free(); } } */ for(int iside=0; iside<4; iside++){ Side* side = getSide(iside); for(int jrib=0; jrib>4; jrib++){ if(side != NULL && this == side->getRib(jrib)){ side->setRib(NULL, jrib); break; } } } for(int icell=0; icell<4; icell++){ Cell* cell = getCell(icell); for(int jrib=0; jrib>4; jrib++){ if(cell != NULL && this == cell->getRib(getAxis(), jrib)){ cell->setRib(getAxis(), jrib, NULL); break; } } } /* if(getParent() != NULL){ for(int i=0; i<2; i++){ if(this == getParent()->getSubRib(i)){ getParent()->setSubRib(i, NULL); break; } } } */ for(int i=0; i<4; i++){ setSide(i, NULL); setCell(i, NULL); } delete this; }
void kore::Camera::setPosition(const glm::vec3& v3Pos) { // Directly set the position to the inverse view-matirx m_matViewInverse[ 3 ] = glm::vec4(v3Pos, 1.0f); // Now calculate the inverse translation for the // view-matrix as a linear combination of the rotational basis-vectors glm::vec3 v3Side = getSide(); glm::vec3 v3Up = getUp(); glm::vec3 v3Forward = getForward(); glm::vec3 v3ViewSide = glm::vec3(v3Side.x, v3Up.x, v3Forward.x); glm::vec3 v3ViewUp = glm::vec3(v3Side.y, v3Up.y, v3Forward.y); glm::vec3 v3ViewForward = glm::vec3(v3Side.z, v3Up.z, v3Forward.z); m_matView[ 3 ] = glm::vec4(v3ViewSide * -v3Pos.x + v3ViewUp * -v3Pos.y + v3ViewForward * -v3Pos.z, 1.0f); paramsChanged(); }
int CFBTeam::getNumberOfDefenderBetweenPlayerAndBall(CFBPlayer* player) { int num = 0; auto side = getSide(); auto pitch = FBMATCH->getPitch(); auto otherSide = pitch->getOtherSide(side); auto& ballPos = FBMATCH->getBallPosition(); auto otherTeam = FBMATCH->getTeam(otherSide); auto teamMember = otherTeam->getTeamMembers(); for (auto t : teamMember) { if (FBDefs::isPointOnTheWay(player->getPosition(), ballPos, t->getPosition())) { num++; } } return num; }
void NewOrderRequestMessage::reject(const std::string &reason) const { LOG4CXX_INFO(logger_, "Sending an order reject response"); FIX42::ExecutionReport execReport( FIX::OrderID(getClOrdId()), FIX::ExecID(exchange_->getIdGenerator()->nextExecutionId()), FIX::ExecTransType(FIX::ExecTransType_NEW), FIX::ExecType(FIX::ExecType_REJECTED), FIX::OrdStatus(FIX::ExecType_REJECTED), FIX::Symbol(getSymbol()), getSide(), FIX::LeavesQty(0), FIX::CumQty(0), FIX::AvgPx(0)); execReport.set(FIX::ClOrdID(getClOrdId())); execReport.set(FIX::Text(reason)); ExecutionReportMessage *msg = new ExecutionReportMessage(exchange_, execReport); if(exchange_->getOutgoingSessionManager()->send(msg, getSenderCompId()) == -1) { delete msg; msg = 0; } }
void d_trsm(SEXP rside, SEXP ruplo, SEXP rtrans, SEXP rdiag, SEXP ralpha, SEXP ra, SEXP rlda, SEXP rb, SEXP rldb) { char trans = getTranspose(rtrans), diag = getUnitTri(rdiag), side = getSide(rside), uplo = getSymLoc(ruplo); double alpha = asReal(ralpha), * a, * b; int rowsa, colsa, lda = asInteger(rlda), rowsb, colsb, ldb = asInteger(rldb); unpackMatrix(ra, &rowsa, &colsa, &a); unpackMatrix(rb, &rowsb, &colsb, &b); cublasDtrsm(side, uplo, trans, diag, rowsb, colsb, alpha, a, lda, b, ldb); checkCublasError("d_trsm"); }