int mobility_list(position_t *p, color_t color, square_t* laser_list, int laser_list_len, full_board_t* board) { int mobility = 0; square_t king_sq = board->pieces[color][0]; mobility++; for (int i = 0; i < laser_list_len-1; i++){ square_t start = laser_list[i]; square_t end = laser_list[i+1]; //check if the square is between laser_list[i] and laser_list[i+1]. if so add to mobility if(between(rnk_of(king_sq), rnk_of(start), rnk_of(end)) && between(fil_of(king_sq), fil_of(start), fil_of(end))) { mobility--; break; } } for (int d = 0; d < 8; ++d) { square_t sq = king_sq + dir_of(d); if (in_bounds(sq)) { mobility++; //decrement if it is in laser path for (int i = 0; i < laser_list_len-1; i++){ //check if the square is between laser_list[i] and laser_list[i+1]. if so add to mobility square_t start = laser_list[i]; square_t end = laser_list[i+1]; if(between(rnk_of(sq), rnk_of(start), rnk_of(end)) && between(fil_of(sq), fil_of(start), fil_of(end))) { mobility--; break; } } } } return mobility; }
// MOBILITY heuristic: safe squares around king of color color. int mobility(position_t *p, color_t color) { char* laser_map; if (color == WHITE) { laser_map = laser_map_black; } else { laser_map = laser_map_white; } int mobility = 0; square_t king_sq = p->kloc[color]; tbassert(ptype_of(p->board[king_sq]) == KING, "ptype: %d\n", ptype_of(p->board[king_sq])); tbassert(color_of(p->board[king_sq]) == color, "color: %d\n", color_of(p->board[king_sq])); if (laser_map[king_sq] == 0) { mobility++; } for (int d = 0; d < 8; ++d) { square_t sq = king_sq + dir_of(d); if (laser_map[sq] == 0) { mobility++; } } return mobility; }
string resolve_path(string path, string base) { if (!path.empty() && path[0] == '/') return path; // Absolute string const base_name = name_of(base); if (base_name == "." || base_name == "..") base += "/"; else if(!base_name.empty()) base = dir_of(base); return base + path; }
std::string local::appdir() { #if defined(_WIN32) || defined(__linux__) return dir_of(app()); #elif defined(__APPLE__) CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); char sz[1024]; CFStringGetCString(path, sz, 1024, CFStringGetSystemEncoding()); CFRelease(url); CFRelease(path); return std::string(sz); #else debugmanager()->fatal("polar::fs::local::appdir: not implemented"); return ""; #endif }
// MOBILITY heuristic: safe squares around king of color color. int mobility(position_t *p, color_t color, char* laser_map, full_board_t* board) { int mobility = 0; square_t king_sq = board->pieces[color][0]; tbassert(ptype_of(board->board[king_sq]) == KING, "ptype: %d\n", ptype_of(board->board[king_sq])); tbassert(color_of(board->board[king_sq]) == color, "color: %d\n", color_of(board->board[king_sq])); if (laser_map[king_sq] == 0) { mobility++; } for (int d = 0; d < 8; ++d) { square_t sq = king_sq + dir_of(d); if (in_bounds(sq) && laser_map[sq] == 0) { mobility++; } } return mobility; }
bool local::write(std::string path, std::istream &is) { createdir(dir_of(path)); std::ofstream file(path, std::ios::out | std::ios::binary | std::ios::trunc); if(file.fail()) { debugmanager()->error(path + ": open"); return false; } file << is.rdbuf(); if(file.fail()) { debugmanager()->error(path + ": write"); return false; } file.close(); if(file.fail()) { debugmanager()->error(path + ": close"); return false; } return true; }