bool CBiship::isValidMove(int BDx, int BDy) { if(tileX == BDx && tileY == BDy) return false; bool ICP = isClearPath(BDx, BDy); if(absolute((BDx-tileX))==absolute((BDy-tileY))) { if (ICP) { return !containsFriendlyPiece(BDx, BDy); } else { return false; }; } else { return false; }; }
int main(void) { double c; double g; double x; printf("hello world!\n"); c=average(5,2); printf("c=%f\n",c); c=absolute(5); printf("c=%f\n",c); c=absolute(-5); printf("c=%f\n",c); printf("------\n"); x=1.0; printf("x=%f\n",x); x=improve(x); printf("x=%f\n",x); x=improve(x); printf("x=%f\n",x); x=improve(x); printf("x=%f\n",x); x=improve(x); printf("x=%f\n",x); x=improve(x); printf("x=%f\n",x); x=improve(x); printf("x=%f\n",x); x=improve(x); printf("x=%f\n",x); x=improve(x); printf("x=%f\n",x); }
bool DBUpdaterUtil::CheckExecutable() { boost::filesystem::path exe(GetCorrectedMySQLExecutable()); if (!exists(exe)) { exe.clear(); if (auto path = Trinity::SearchExecutableInPath("mysql")) { exe = std::move(*path); if (!exe.empty() && exists(exe)) { // Correct the path to the cli corrected_path() = absolute(exe).generic_string(); return true; } } TC_LOG_FATAL("sql.updates", "Didn't find any executable MySQL binary at \'%s\' or in path, correct the path in the *.conf (\"MySQLExecutable\").", absolute(exe).generic_string().c_str()); return false; } return true; }
char *ft_addsubstr(char *a, char *b, int op) { char *abs_a; char *abs_b; char *ret; abs_a = absolute(a); abs_b = absolute(b); ret = NULL; if (op == 1) { ret = (neg(a) && neg(b)) ? operation(abs_a, abs_b, 1, 1) : ret; if ((neg(a) && !neg(b)) || (!neg(a) && neg(b))) { if (ft_strcmp(abs_a, abs_b) >= 0) ret = operation(abs_a, abs_b, 0, -1); else ret = operation(abs_a, abs_b, 1, -1); } ret = (!neg(a) && !neg(b)) ? operation(abs_a, abs_b, 0, 1) : ret; } else ret = addsubstr_next(a, b, abs_a, abs_b); ft_strdel(&abs_a); ft_strdel(&abs_b); return (ret); }
void IGameController::DoTeamBalance() { if(!IsTeamplay() || !g_Config.m_SvTeambalanceTime || absolute(m_aTeamSize[TEAM_RED]-m_aTeamSize[TEAM_BLUE]) < NUM_TEAMS) return; GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "Balancing teams"); float aTeamScore[NUM_TEAMS] = {0}; float aPlayerScore[MAX_CLIENTS] = {0.0f}; // gather stats for(int i = 0; i < MAX_CLIENTS; i++) { if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) { aPlayerScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/ (Server()->Tick()-GameServer()->m_apPlayers[i]->m_ScoreStartTick); aTeamScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPlayerScore[i]; } } int BiggerTeam = (m_aTeamSize[TEAM_RED] > m_aTeamSize[TEAM_BLUE]) ? TEAM_RED : TEAM_BLUE; int NumBalance = absolute(m_aTeamSize[TEAM_RED]-m_aTeamSize[TEAM_BLUE]) / NUM_TEAMS; // balance teams do { CPlayer *pPlayer = 0; float ScoreDiff = aTeamScore[BiggerTeam]; for(int i = 0; i < MAX_CLIENTS; i++) { if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i)) continue; // remember the player whom would cause lowest score-difference if(GameServer()->m_apPlayers[i]->GetTeam() == BiggerTeam && (!pPlayer || absolute((aTeamScore[BiggerTeam^1]+aPlayerScore[i]) - (aTeamScore[BiggerTeam]-aPlayerScore[i])) < ScoreDiff)) { pPlayer = GameServer()->m_apPlayers[i]; ScoreDiff = absolute((aTeamScore[BiggerTeam^1]+aPlayerScore[i]) - (aTeamScore[BiggerTeam]-aPlayerScore[i])); } } // move the player to the other team if(pPlayer) { int Temp = pPlayer->m_LastActionTick; DoTeamChange(pPlayer, BiggerTeam^1); pPlayer->m_LastActionTick = Temp; pPlayer->Respawn(); GameServer()->SendGameMsg(GAMEMSG_TEAM_BALANCE_VICTIM, pPlayer->GetTeam(), pPlayer->GetCID()); } } while(--NumBalance); m_UnbalancedTick = TBALANCE_OK; GameServer()->SendGameMsg(GAMEMSG_TEAM_BALANCE, -1); }
int main(){ //need to use double notation here otherwise we get extremely weird printouts !NaN double num1= 1.5; double numneg1= -1.5; double num2= 1; double numneg2= -1; double num3= 69; double num4= 100; double numneg4= -100; double num5= 3.45; double num0= 0; printf("Absolute:\n"); printf("abs(1.5) = %16.8lf\n", absolute(num1)); printf("abs(-1.5) = %16.8lf\n", absolute(numneg1)); printf("abs(69) = %16.8lf\n", absolute(num3)); printf("abs(-100) = %16.8lf\n\n", absolute(numneg4)); printf("Modulo(remainder of x/y where(x,y)):\n"); printf( "modulo(0, 1) = %16.8lf\n", modulo(num0, num2)); //returns 0 printf( "modulo(1, 0) = %16.8lf\n", modulo(num2, num0)); //returns NaN printf( "modulo(1, 1) = %16.8lf\n", modulo(num2, num2)); printf( "modulo(-1.5, 1) = %16.8lf\n", modulo(numneg1, num2)); //should be positive?! printf( "modulo(-1, -1.5) = %16.8lf\n", modulo(numneg2, numneg1)); printf( "modulo(100, 69) = %16.8lf\n", modulo(num4, num3)); printf( "modulo(3.45, 1.5) = %16.8lf\n\n", modulo(num5, num1)); //not allowed to pass in negative values, so return 0 printf("Factorial:\n"); printf( "1! = %16.8lf\n", factorial(1)); printf( "-1! = %16.8lf\n", factorial(-1)); printf( "3! = %16.8lf\n", factorial(3)); printf( "-3! = %16.8lf\n", factorial(-3)); printf( "5! = %16.8lf\n", factorial(5)); printf( "10! = %16.8lf\n\n", factorial(10)); //printf( "1.5! = %16.8lf\n", factorial(1.5)); //no testing for float exponents because unsigned int is passed in printf("Power:\n"); //no testing for float exponents because unsigned int is passed in printf("%d ^ %d = %16.8lf\n", 0, 2, power(0,2)); printf("%d ^ %d = %16.8lf\n", 1, 1, power(1,1)); printf("%d ^ %d = %16.8lf\n", 3, 3, power(3.0,3.0)); printf("%d ^ %d = %16.8lf\n", -1, 1, power(-1,1)); printf("%d ^ %d = %16.8lf\n", -4, 2, power(-4,2)); printf("%d ^ %d = %16.8lf\n\n", -1, -1, power(-1,-1)); //negative exponents and negative bases have not been fully worked out yet, really need to do additional testing(test cases) //test cases even though didn't finish sine printf( "sine(0): %16.8lf\n", sine(0)); printf( "sine(pi/2): %16.8lf\n", sine(M_PI/2)); printf( "sine(pi/3): %16.8lf\n", sine(M_PI/3)); printf( "sine(pi/4): %16.8lf\n", sine(M_PI/4)); printf( "sine(pi/6): %16.8lf\n", sine(M_PI/6)); printf( "sine(pi): %16.8lf\n", sine(M_PI)); printf( "sine(-pi): %16.8lf\n", sine(-M_PI)); printf( "sine(-1.5): %16.8lf\n\n", sine(-1.5)); return 0; }
void visit(Point const &point) { auto x = absolute(point.x); auto y = absolute(point.y); assert(x >= 0 && x < rows() && "Out of bounds"); assert(y >= 0 && y < cols() && "Out of bounds"); visited_[x][y] = true; }
bool visited(Point const &point) const { auto x = absolute(point.x); auto y = absolute(point.y); assert(x >= 0 && x < rows() && "Out of bounds"); assert(y >= 0 && y < cols() && "Out of bounds"); return visited_[x][y]; }
bool intersect(const Complex& a, const Complex& b, const Transform& a2w, const Transform& b2w, Vector& v) { Transform b2a, a2b; b2a.multInverseLeft(a2w, b2w); a2b.invert(b2a); Matrix abs_b2a = absolute(b2a.getBasis()); Matrix abs_a2b = absolute(a2b.getBasis()); return intersect(a.root, b.root, b2a, abs_b2a, a2b, abs_a2b, v); }
bool common_point(const Complex& a, const Complex& b, const Transform& a2w, const Transform& b2w, Vector& v, Point& pa, Point& pb) { Transform b2a, a2b; b2a.multInverseLeft(a2w, b2w); a2b.invert(b2a); Matrix abs_b2a = absolute(b2a.getBasis()); Matrix abs_a2b = absolute(a2b.getBasis()); return common_point(a.root, b.root, b2a, abs_b2a, a2b, abs_a2b, v, pa, pb); }
bool find_prim(const Complex& a, const Complex& b, const Transform& a2w, const Transform& b2w, Vector& v, ShapePtr& pa, ShapePtr& pb) { Transform b2a, a2b; b2a.multInverseLeft(a2w, b2w); a2b.invert(b2a); Matrix abs_b2a = absolute(b2a.getBasis()); Matrix abs_a2b = absolute(a2b.getBasis()); return find_prim(a.root, b.root, b2a, abs_b2a, a2b, abs_a2b, v, pa, pb); }
int Game::naive_bird_h() { int score = -10; std::vector<std::vector<int>> birds_pos = bird_positions; std::vector<int> larva_pos = larva_position; for(int i=0; i<birds_pos.size(); i++) { std::vector<int> temp = birds_pos.at(i); int row_diff = absolute(larva_pos.at(0)-temp.at(0)); score += row_diff; int col_diff = absolute(larva_pos.at(1)-temp.at(1)); score += col_diff; } return score; }
AssetHandler::AssetHandler( const Project& project, const char* filepath, const Mode mode) : m_project(project) , m_project_old_root_path(absolute(project.get_path())) , m_project_new_root_path(absolute(filepath)) , m_project_old_root_dir(m_project_old_root_path.parent_path()) , m_project_new_root_dir(m_project_new_root_path.parent_path()) , m_mode(mode) { }
//ベジェ曲線上の点列を作成 void getBezier3( const point2<int> & p0, const point2<int> & p1, const point2<int> & p2, const point2<int> & p3, list< point2<int> > & points ) { // p0 - p3による三次ベジェ曲線の点列を作成する. points.release(); point2<int> current = p0; points.push_back( current ); double d = 0.125; double t = d; while ( current != p3 ) { const double t2 = t * t; const double t3 = t2 * t; const double u = 1 - t; const double u2 = u * u; const double u3 = u2 * u; double x = p0.x * u3 + 3 * p1.x * u2 * t + 3 * p2.x * u * t2 + p3.x * t3; double y = p0.y * u3 + 3 * p1.y * u2 * t + 3 * p2.y * u * t2 + p3.y * t3; point2<int> next( round<int,double>( x ), round<int,double>( y ) ); int step = maximum<int>( absolute( next.x - current.x ), absolute( next.y - current.y ) ); if ( step == 0 ) { t = clamp<double>( 0, t + d, 1 ); } else if ( step == 1 ) { points.push_back( next ); current = next; t = clamp<double>( 0, t + d, 1 ); } else { d /= 2; t = clamp<double>( 0, t - d, 1 ); } } //八連結に直せる個所をさがす bool cont = true; while ( cont ) { bool removed = false; for ( list< point2<int> >::iterator it( points ); it; ++it ) { list< point2<int> >::iterator previt = it.prev(); list< point2<int> >::iterator nextit = it.next(); if ( previt && nextit ) { const point2<int> & prev = previt(); const point2<int> & next = nextit(); const point2<int> & now = it(); int step = maximum<int>( absolute( next.x - prev.x ), absolute( next.y - prev.y ) ); if ( step == 1 ) { removed = true; points.pop( it ); break; } } } if ( ! removed ) return;//終了 } }
int main() { union dp_item Test; Test.drep = -3.000000000000E+00; union dp_item Test1; Test1.drep = +1.875000000000E+00; union dp_item Test2; Test2.drep = 5.1; union dp_item Test3; Test3.drep = 3.1; double number = absolute(Test.drep); printf("Testing absolute of -3.0: %08x\n", number); double number1 = absolute(Test1.drep); printf("Testing absolute of 1.875: %08x\n", number1); double number2 = modulo(Test2.drep, Test3.drep); printf("Testing 5.1 mod 3.1: %f\n", number2); double Test51 = -20.0; double Test52 = 3.0; double number52 = modulo(Test51, Test52); printf("Testing -20 mod 3: %f\n", number52); unsigned int Test4 = 4; double number3 = factorial(Test4); printf("Testing 4! : %f\n", number3); unsigned int Test5 = 9; double number4 = factorial(Test5); printf("Testing 9! : %f\n", number4); double Test6 = 3.0; unsigned int power1 = 3; double number5 = power(Test6, power1); printf("Testing 3.0^(3): %f\n", number5); double Test7 = 4.25; unsigned int power2 = 5; double number6 = power(Test7, power2); printf("Testing 4.25^(5): %f\n", number6); double Test8 = 8.1; double number7 = cosine(Test8); printf("Testing cos(8.1): %f\n", number7); }
int main() { village v1[100001], v2[100001]; int i,t,z1,z2,n,x; long long int sum; scanf("%d",&t); while(t--) { z1=0;z2=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&x); if(x>=0) { v1[z1++].num=x; v1[z1-1].index=i+1; } else { v2[z2++].num=x; v2[z2-1].index=i+1; } } sum=0;z2=0; for(i=0;i<z1;i++) { if(v1[i].num==0) continue; if(v1[i].num<=-v2[z2].num) { sum+=v1[i].num*absolute(v1[i].index-v2[z2].index); // printf("%d x %d(%d)",v1[i].num,(int)fabs(v1[i].index-v2[z2].index),v1[i].num*(int)fabs(v1[i].index-v2[z2].index)); // printf(" + "); v2[z2].num+=v1[i].num; } else { sum+=-v2[z2].num*absolute(v1[i].index-v2[z2].index); // printf("%d x %d(%d)", -v2[z2].num,(int)fabs(v1[i].index-v2[z2].index),v1[i].num*(int)fabs(v1[i].index-v2[z2].index)); // printf(" + "); v1[i].num+=v2[z2].num; z2++;i--; } } printf("%lld\n",sum); } return 0; }
int CEntity::NetworkClipped(int SnappingClient, vec2 CheckPos) { if(SnappingClient == -1) return 0; float dx = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.x-CheckPos.x; float dy = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.y-CheckPos.y; if(absolute(dx) > 1000.0f || absolute(dy) > 800.0f) return 1; if(distance(GameServer()->m_apPlayers[SnappingClient]->m_ViewPos, CheckPos) > 1100.0f) return 1; return 0; }
//Returns x / y //It is assumed that y != 0 int divide(int x, int y) { int count = 0; int absx = absolute(x); int absy = absolute(y); int product = 0; while (product + absy <= absx) { product += absy; count++; } if ((x < 0 && y < 0) || (x > 0 && y > 0)) return count; else return negate(count); }
//------------------------------------------------------------- BigInteger BigInteger::operator + (BigInteger b) { BigInteger addition; if( getSign() == b.getSign() ) // both +ve or -ve { addition.setNumber( add(getNumber(), b.getNumber() ) ); addition.setSign( getSign() ); } else // sign different { if( absolute() > b.absolute() ) { addition.setNumber( subtract(getNumber(), b.getNumber() ) ); addition.setSign( getSign() ); } else { addition.setNumber( subtract(b.getNumber(), getNumber() ) ); addition.setSign( b.getSign() ); } } if(addition.getNumber() == "0") // avoid (-0) problem addition.setSign(false); return addition; }
char *FileName::searchPath(Strings *path, const char *name, int cwd) { if (absolute(name)) { return exists(name) ? (char *)name : NULL; } if (cwd) { if (exists(name)) return (char *)name; } if (path) { unsigned i; for (i = 0; i < path->dim; i++) { char *p = path->tdata()[i]; char *n = combine(p, name); if (exists(n)) return n; } } return NULL; }
const char *FileName::replaceName(const char *path, const char *name) { char *f; char *n; size_t pathlen; size_t namelen; if (absolute(name)) return name; n = FileName::name(path); if (n == path) return name; pathlen = n - path; namelen = strlen(name); f = (char *)mem.malloc(pathlen + 1 + namelen + 1); memcpy(f, path, pathlen); #if POSIX if (path[pathlen - 1] != '/') { f[pathlen] = '/'; pathlen++; } #elif _WIN32 if (path[pathlen - 1] != '\\' && path[pathlen - 1] != '/' && path[pathlen - 1] != ':') { f[pathlen] = '\\'; pathlen++; } #else assert(0); #endif memcpy(f + pathlen, name, namelen + 1); return f; }
bool IGameController::CheckTeamBalance() { if(!IsTeamplay() || !g_Config.m_SvTeambalanceTime) return true; int aT[2] = {0, 0}; for(int i = 0; i < MAX_CLIENTS; i++) { CPlayer *pP = GameServer()->m_apPlayers[i]; if(pP && pP->GetTeam() != -1) aT[pP->GetTeam()]++; } if(absolute(aT[0]-aT[1]) >= 2) { dbg_msg("game", "Team is NOT balanced (red=%d blue=%d)", aT[0], aT[1]); if(GameServer()->m_pController->m_UnbalancedTick == -1) GameServer()->m_pController->m_UnbalancedTick = Server()->Tick(); return false; } else { dbg_msg("game", "Team is balanced (red=%d blue=%d)", aT[0], aT[1]); GameServer()->m_pController->m_UnbalancedTick = -1; return true; } }
const char *FileName::searchPath(Strings *path, const char *name, int cwd) { if (absolute(name)) { return exists(name) ? name : NULL; } if (cwd) { if (exists(name)) return name; } if (path) { for (size_t i = 0; i < path->dim; i++) { const char *p = (*path)[i]; const char *n = combine(p, name); if (exists(n)) return n; } } return NULL; }
void MaterialItem::slot_export() { const char* project_path = m_editor_context.m_project.get_path(); const filesystem::path project_root_path = filesystem::path(project_path).parent_path(); const filesystem::path file_path = absolute("material.dmt", project_root_path); const filesystem::path file_root_path = file_path.parent_path(); QString filepath = get_save_filename( 0, "Export...", "Disney Materials (*.dmt)", m_editor_context.m_settings, SETTINGS_FILE_DIALOG_PROJECTS); if (!filepath.isEmpty()) { if (QFileInfo(filepath).suffix().isEmpty()) filepath += ".dmt"; filepath = QDir::toNativeSeparators(filepath); ParamArray parameters = m_entity->get_parameters(); parameters.insert("__name", m_entity->get_name()); parameters.insert("__model", m_entity->get_model()); SettingsFileWriter writer; if (!writer.write(filepath.toStdString().c_str(), parameters)) { show_error_message_box( "Exporting Error", "Failed to export the Disney Material file " + filepath.toStdString() + "."); } } }
bool RLogMill::findRepository(boost::filesystem::path& dir, std::string& log_format) { dir = absolute(dir); //fprintf(stderr, "find repository from initial path: %s\n", dir.string().c_str()); while(is_directory(dir)) { if(is_directory(dir / ".git")) log_format = "git"; else if(is_directory(dir / ".hg")) log_format = "hg"; else if(is_directory(dir / ".bzr")) log_format = "bzr"; else if(is_directory(dir / ".svn")) log_format = "svn"; if(!log_format.empty()) { //fprintf(stderr, "found '%s' repository at: %s\n", log_format.c_str(), dir.string().c_str()); return true; } if(!dir.has_parent_path()) return false; dir = dir.parent_path(); } return false; }
float CPU_blockmatching(char2 candidate, uint type, uint w, uint h, uint width, uint height, TYPE* previous_frame, TYPE* current_frame) { // Perform the SAD computation float difference = 0; for (uint hl=0;hl<BLOCKSIZE;hl++) { uint hgc = hl+h+candidate.y; uint hg = hl+h; if (hg > 0 && hg < height && hgc > 0 && hgc < height) { for (uint wl=0;wl<BLOCKSIZE;wl++) { uint wgc = wl+w+candidate.x; uint wg = wl+w; if (wg > 0 && wg < width && wgc > 0 && wgc < width) { uint pc = hgc+wgc*height; uint p = hg+wg*height; difference = difference + absolute((int)previous_frame[p] - (int)current_frame[pc]); } else { difference = difference + 128; } } } else { difference = difference + 128*BLOCKSIZE; } } // Set the penalty float penalty = 0; #ifdef PENALTIES if (type == 3 || type == 5 || type == 6 || type == 7 || type == 8) { penalty = 0.5*BLOCKSIZE*BLOCKSIZE; } if (type == 9) { penalty = 2*BLOCKSIZE*BLOCKSIZE; } #endif return difference + penalty; }
bool IGameController::CheckTeamBalance() { if(!IsTeamplay() || !g_Config.m_SvTeambalanceTime) return true; int aT[2] = {0, 0}; for(int i = 0; i < MAX_CLIENTS; i++) { CPlayer *pP = GameServer()->m_apPlayers[i]; if(pP && pP->GetTeam() != TEAM_SPECTATORS) aT[pP->GetTeam()]++; } char aBuf[256]; if(absolute(aT[0]-aT[1]) >= 2) { str_format(aBuf, sizeof(aBuf), "Teams are NOT balanced (red=%d blue=%d)", aT[0], aT[1]); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); if(GameServer()->m_pController->m_UnbalancedTick == -1) GameServer()->m_pController->m_UnbalancedTick = Server()->Tick(); return false; } else { str_format(aBuf, sizeof(aBuf), "Teams are balanced (red=%d blue=%d)", aT[0], aT[1]); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); GameServer()->m_pController->m_UnbalancedTick = -1; return true; } }
void junction ( string target, const string& alias ) { // Reparse-points must *absolutely* use full paths. target = absolute(target); // Create an empty folder. Folder::create(alias); try { // Get the new folder's handle. ReparsePoint folder(alias); // Morph the folder into a reparse point. ::ReparseDataBuffer buffer(target); ::DWORD written = 0; const ::BOOL result = ::DeviceIoControl( folder.handle(), FSCTL_SET_REPARSE_POINT, &buffer, buffer.size(), 0, 0, &written, 0 ); if ( result == FALSE ) { const ::DWORD error = ::GetLastError(); UNCHECKED_WIN32C_ERROR(DeviceIoControl, error); } } // Remove the empty directory. catch ( ... ) { unlink(alias); throw; } }
bool IGameController::CanChangeTeam(CPlayer *pPlayer, int JoinTeam) { int aT[2] = {0, 0}; if (!IsTeamplay() || JoinTeam == TEAM_SPECTATORS || !g_Config.m_SvTeambalanceTime) return true; for(int i = 0; i < MAX_CLIENTS; i++) { CPlayer *pP = GameServer()->m_apPlayers[i]; if(pP && pP->GetTeam() != TEAM_SPECTATORS) aT[pP->GetTeam()]++; } // simulate what would happen if changed team aT[JoinTeam]++; if (pPlayer->GetTeam() != TEAM_SPECTATORS) aT[JoinTeam^1]--; // there is a player-difference of at least 2 if(absolute(aT[0]-aT[1]) >= 2) { // player wants to join team with less players if ((aT[0] < aT[1] && JoinTeam == TEAM_RED) || (aT[0] > aT[1] && JoinTeam == TEAM_BLUE)) return true; else return false; } else return true; }
void setSpeedMotorB(int spd){ int speed; speed = absolute(spd); if(speed > 255) speed = 255; OCR1B = 255 - speed; }