void PlaceToken(Param param, T_board *board, Hexa_list **Alive){ int placed=0, i=0, j=0; board->grid[0][0].val=PLAYER_1; board->grid[board->size-1][board->size-1].val=PLAYER_1; AppendList(&(Alive[0]), (vect) {0,0}); AppendList(&(Alive[0]), (vect) {board->size-1, board->size-1}); board->grid[0][board->size-1].val=PLAYER_2; board->grid[board->size-1][0].val=PLAYER_2; AppendList(&(Alive[1]), (vect) {0, board->size-1}); AppendList(&(Alive[1]), (vect) {board->size-1, 0}); while(placed<param.closedHex){ i=rand()%board->size; j=rand()%board->size; if(board->grid[i][j].val==EMPTY){ board->grid[i][j].val=CLOSED; placed++; } } }
static BOOL DirListPopulateControl(datamap *map, HWND dialog, HWND control, windows_options *opts, const char *option_name) { int driver_index, pos, new_pos, current_item; const char *dir_list; TCHAR *t_dir_list; TCHAR *s; LV_COLUMN lvc; RECT r; HRESULT res; BOOL b_res; // access the directory list, and convert to TCHARs driver_index = PropertiesCurrentGame(dialog); dir_list = GetExtraSoftwarePaths(driver_index); t_dir_list = tstring_from_utf8(dir_list); if (!t_dir_list) return FALSE; // delete all items in the list control b_res = ListView_DeleteAllItems(control); // add the column GetClientRect(control, &r); memset(&lvc, 0, sizeof(LVCOLUMN)); lvc.mask = LVCF_WIDTH; lvc.cx = r.right - r.left - GetSystemMetrics(SM_CXHSCROLL); res = ListView_InsertColumn(control, 0, &lvc); // add each of the directories pos = 0; current_item = 0; while(t_dir_list[pos] != '\0') { // parse off this item s = _tcschr(&t_dir_list[pos], ';'); if (s != NULL) { *s = '\0'; new_pos = s - t_dir_list + 1; } else { new_pos = pos + _tcslen(&t_dir_list[pos]); } // append this item AppendList(control, &t_dir_list[pos], current_item); // advance to next item pos = new_pos; current_item++; } // finish up AppendList(control, TEXT(DIRLIST_NEWENTRYTEXT), current_item); ListView_SetItemState(control, 0, LVIS_SELECTED, LVIS_SELECTED); osd_free(t_dir_list); return TRUE; }
bool CSTransform::Scale(std::string scale, bool concatenate) { double matrix[16]; std::vector<std::string> scale_vec = SplitString2Vector(scale, ','); if ((scale_vec.size()>1) && (scale_vec.size()!=3)) std::cerr << "CSTransform::Scale: Warning: Number of arguments for operation: \"Scale\" with arguments: \"" << scale << "\" is larger than expected, skipping unneeded! " << std::endl; else if (scale_vec.size()<1) { std::cerr << "CSTransform::Scale: Error: Number of arguments for operation: \"Scale\" with arguments: \"" << scale << "\" is invalid! Skipping" << std::endl; return false; } if (scale_vec.size()>=3) { ParameterScalar ps_scale[3]; double scale_double_vec[3]; for (int n=0;n<3;++n) { ps_scale[n].SetParameterSet(m_ParaSet); ps_scale[n].SetValue(scale_vec.at(n)); int EC = ps_scale[n].Evaluate(); if (EC!=0) return false; scale_double_vec[n]=ps_scale[n].GetValue(); } if (ScaleMatrix(matrix, scale_double_vec)==false) return false; ApplyMatrix(matrix,concatenate); AppendList(SCALE3,ps_scale,3); return true; } if(scale_vec.size()>=1) { ParameterScalar ps_scale(m_ParaSet, scale); int EC = ps_scale.Evaluate(); if (EC!=0) return false; if (ScaleMatrix(matrix, ps_scale.GetValue())==false) return false; ApplyMatrix(matrix,concatenate); AppendList(SCALE,&ps_scale,1); return true; } std::cerr << "CSTransform::Scale: Error: Number of arguments for operation: \"Scale\" with arguments: \"" << scale << "\" is invalid! Skipping" << std::endl; return false; }
bool CSTransform::RotateOrigin(std::string XYZ_A, bool concatenate) { double matrix[16]; std::vector<std::string> rot_vec = SplitString2Vector(XYZ_A, ','); ParameterScalar ps_rotate[4]; double rot_double_vec[4]; if (rot_vec.size()>4) std::cerr << "CSTransform::RotateOrigin: Warning: Number of arguments for operation: \"RotateOrigin\" with arguments: \"" << XYZ_A << "\" is larger than expected, skipping unneeded! " << std::endl; else if (rot_vec.size()<4) { std::cerr << "CSTransform::RotateOrigin: Error: Number of arguments for operation: \"RotateOrigin\" with arguments: \"" << XYZ_A << "\" is invalid! Skipping" << std::endl; return false; } for (int n=0;n<4;++n) { ps_rotate[n].SetParameterSet(m_ParaSet); ps_rotate[n].SetValue(rot_vec.at(n)); int EC = ps_rotate[n].Evaluate(); if (EC!=0) return false; rot_double_vec[n]=ps_rotate[n].GetValue(); } if (RotateOriginMatrix(matrix, rot_double_vec)==false) return false; ApplyMatrix(matrix,concatenate); AppendList(ROTATE_ORIGIN,ps_rotate,4); return true; }
bool CSTransform::Translate(std::string translate, bool concatenate) { double matrix[16]; std::vector<std::string> tl_vec = SplitString2Vector(translate, ','); ParameterScalar ps_translate[3]; double tl_double_vec[3]; if (tl_vec.size()>3) std::cerr << "CSTransform::Translate: Warning: Number of arguments for operation: \"Translate\" with arguments: \"" << translate << "\" is larger than expected, skipping unneeded! " << std::endl; else if (tl_vec.size()<3) { std::cerr << "CSTransform::Translate: Error: Number of arguments for operation: \"Translate\" with arguments: \"" << translate << "\" is invalid! Skipping" << std::endl; return false; } for (int n=0;n<3;++n) { ps_translate[n].SetParameterSet(m_ParaSet); ps_translate[n].SetValue(tl_vec.at(n)); int EC = ps_translate[n].Evaluate(); if (EC!=0) return false; tl_double_vec[n]=ps_translate[n].GetValue(); } if (TranslateMatrix(matrix, tl_double_vec)==false) return false; ApplyMatrix(matrix,concatenate); AppendList(TRANSLATE,ps_translate,3); return true; }
bool CSTransform::SetMatrix(std::string matrix, bool concatenate) { std::vector<std::string> mat_vec = SplitString2Vector(matrix, ','); ParameterScalar ps_matrix[16]; double d_matrix[16]; if (mat_vec.size()>16) std::cerr << "CSTransform::SetMatrix: Warning: Number of arguments for operation: \"Matrix\" with arguments: \"" << matrix << "\" is larger than expected, skipping unneeded! " << std::endl; else if (mat_vec.size()<16) { std::cerr << "CSTransform::SetMatrix: Error: Number of arguments for operation: \"Matrix\" with arguments: \"" << matrix << "\" is invalid! Skipping" << std::endl; return false; } for (int n=0;n<16;++n) { ps_matrix[n].SetParameterSet(m_ParaSet); ps_matrix[n].SetValue(mat_vec.at(n)); int EC = ps_matrix[n].Evaluate(); if (EC!=0) return false; d_matrix[n]=ps_matrix[n].GetValue(); } ApplyMatrix(d_matrix,concatenate); AppendList(MATRIX,ps_matrix,16); return true; }
void CSTransform::Translate(const double translate[3], bool concatenate) { double matrix[16]; if (TranslateMatrix(matrix, translate)==false) return; ApplyMatrix(matrix,concatenate); AppendList(TRANSLATE,translate,3); }
void CSTransform::Scale(const double scale[3], bool concatenate) { double matrix[16]; if (ScaleMatrix(matrix, scale)==false) return; ApplyMatrix(matrix,concatenate); AppendList(SCALE3,scale,3); }
void CSTransform::RotateOrigin(const double vector[3], double angle, bool concatenate) { double XYZ_A[4]={vector[0],vector[1],vector[2],angle}; double matrix[16]; if (RotateOriginMatrix(matrix, XYZ_A)==false) return; ApplyMatrix(matrix,concatenate); AppendList(ROTATE_ORIGIN,XYZ_A,4); }
void playMove(T_board* board, move mvt, Hexa_list **alivePlAct, vect start, vect end, int player, int *score){ int i=0; if(mvt==DUPLICATE){ board->grid[end.x][end.y].val = player; AppendList(alivePlAct, end); score[player]+=1; } else if(mvt==JUMP){ board->grid[end.x][end.y].val = player; board->grid[start.x][start.y].val = EMPTY; AppendList(alivePlAct, end); } if(mvt==JUMP || mvt==DUPLICATE){ for(i=0; i<6 ; i++){ if(board->grid[end.x][end.y].neighbords[i]!=NULL){ if(board->grid[end.x][end.y].neighbords[i]->val!=player && (board->grid[end.x][end.y].neighbords[i]->val==PLAYER_2 || board->grid[end.x][end.y].neighbords[i]->val==PLAYER_1) ){ board->grid[end.x][end.y].neighbords[i]->val=player; switch(i){ case UP: AppendList(alivePlAct, (vect){end.x-1, end.y-1}); break; case DOWN: AppendList(alivePlAct, (vect){end.x+1, end.y+1}); break; case R_DOWN: AppendList(alivePlAct, (vect){end.x+1, end.y}); break; case L_DOWN: AppendList(alivePlAct, (vect){end.x, end.y+1}); break; case L_UP: AppendList(alivePlAct, (vect){end.x-1, end.y}); break; case R_UP: AppendList(alivePlAct, (vect){end.x, end.y-1}); break; } score[player]+=1; score[(player+1)%2]-=1; } } } } }
void CSTransform::RotateXYZ(int dir, double angle, bool concatenate) { if ((dir<0) || (dir>3)) return; double vec[4]={0,0,0,angle}; vec[dir] = 1; double matrix[16]; if (RotateOriginMatrix(matrix, vec)==false) return; ApplyMatrix(matrix,concatenate); TransformType type = (TransformType)((int)ROTATE_X + dir); AppendList(type,&angle,1); }
static BOOL SoftwareDirectories_OnInsertBrowse(HWND hDlg, BOOL bBrowse, LPCTSTR lpItem) { int nItem; TCHAR inbuf[MAX_PATH]; TCHAR outbuf[MAX_PATH]; HWND hList; LPTSTR lpIn; BOOL res; g_bModifiedSoftwarePaths = TRUE; hList = GetDlgItem(hDlg, IDC_DIR_LIST); nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED); if (nItem == -1) return FALSE; /* Last item is placeholder for append */ if (nItem == ListView_GetItemCount(hList) - 1) { bBrowse = FALSE; } if (!lpItem) { if (bBrowse) { ListView_GetItemText(hList, nItem, 0, inbuf, ARRAY_LENGTH(inbuf)); lpIn = inbuf; } else { lpIn = NULL; } if (!BrowseForDirectory(hDlg, lpIn, outbuf)) return FALSE; lpItem = outbuf; } AppendList(hList, lpItem, nItem); if (bBrowse) res = ListView_DeleteItem(hList, nItem+1); MarkChanged(hDlg); return TRUE; }
bool CSTransform::RotateXYZ(int dir, std::string angle, bool concatenate) { if ((dir<0) || (dir>3)) return false; ParameterScalar ps_angle(m_ParaSet, angle); int EC = ps_angle.Evaluate(); if (EC!=0) return false; double vec[4]={0,0,0,ps_angle.GetValue()}; vec[dir] = 1; double matrix[16]; if (RotateOriginMatrix(matrix, vec)==false) return false; ApplyMatrix(matrix,concatenate); TransformType type = (TransformType)((int)ROTATE_X + dir); AppendList(type,&ps_angle,1); return true; }
//============================================================================ //タイプの判別 //============================================================================ //[input] // pFile:判定するデータ //=========================================================================== void CResourceManager::CheckType( CFileData *pFile ) { TCHAR *pName = (TCHAR *)( pFile->GetFileName().c_str() ); Dix::PathStrAnalizer PSA( pName ); //拡張子を取得 string strExtName = PSA.getExtName(); //音関係の場合 if( strExtName == "wav" || strExtName == "ogg" ) { //音の取得 CSoundObject *pSoundObj = CSoundFactory::GetSound( pFile ); sp<CSoundObject> spSndObj( pSoundObj ); //サウンドリストに追加 CCommonObject::GetSoundMgr()->AppendSoundList( pFile->GetDataName().c_str(), spSndObj ); } //その他オブジェクトの場合 else { //2Dオブジェクトの取得 CGameObject *pObj = CFactory2D::Get2DObject( pFile ); sp<CGameObject> spObj; spObj.SetPtr( pObj ); //リソースの登録 AppendList( pFile->GetDataName(), spObj ); } }
GList::GList(const GList &cpy) { AppendList(&cpy); }
void baggingFn(int j, int bagTokenNo) /*j is the index of the Bagger, i.e. OT[j]*/ { int i; /*For the index of the Customer, i.e. C[i]*/ int x; for ( x=0; x<noCustomers; x++) /*TO GO part*/ if (C[x].toGoWaiting == 1 && C[x].custDoA == 1 && C[x].orderType==1) { Acquire(waitToGoLock[x]); /*Bagger acquires the lock of Customer C[i] for the Bagger -*/ } i=tokenToId[bagTokenNo]; /*Obtained Customer ID from the Bag Token No*/ OT[j].otBagTokenNo=bagTokenNo; /* while (sixBurgerAvailable < C[i].sixBurger || threeBurgerAvailable < C[i].threeBurger || veggieBurgerAvailable < C[i].veggieBurger || frenchFriesAvailable < C[i].frenchFries) currentThread -> Yield();*/ Acquire(cookedLock); sixBurgerAvailable-=C[i].sixBurger; /*The amount of food item of each type available*/ threeBurgerAvailable-=C[i].threeBurger; /*on its respective shelf is decremented by the number*/ veggieBurgerAvailable-=C[i].veggieBurger; /*of items of that type ordered by the Customer C[i]*/ frenchFriesAvailable-=C[i].frenchFries; Release(cookedLock); if (C[i].orderType == 1) { /* ***** Monitor for TO GO Customers Begins ***** */ if (M.mID==j) { Print("\nManager packed the food for Customer %d", i,0, 0); Print("\nManager gives food to Customer %d", i,0, 0); Print("\nCustomer %d receives food from the Manager\n", i, 0,0); Print("\nCustomer %d is leaving the restaurant after Manager packed the food\n", i, 0,0); Acquire(customerCounterLock); customerCounter++; Release(customerCounterLock); } else { Print("\nOrderTaker %d packed the food for Customer %d", j, i,0); Print("\nOrderTaker %d gives food to Customer %d", j, i,0); Print("\nCustomer %d receives food from the OrderTaker %d\n", i, j,0); Print("\nCustomer %d is leaving the restaurant after OrderTaker %d packed the food\n", i, j,0); Acquire(customerCounterLock); customerCounter++; Release(customerCounterLock); } if (C[i].toGoWaiting==1); { Signal(waitToGoCV[i], waitToGoLock[i]); } for (x=0; x < noCustomers; x++) /*For each Customer*/ { /* if(waitToGoLock[x]->isHeldByCurrentThread() && x!=i)*/ if (x !=i) { Release(waitToGoLock[x]); } } Wait(waitToGoCV[i], waitToGoLock[i]); Release(waitToGoLock[i]); return; /*Exits fn*/ } /* ***** Monitor for TO GO Customers Ends ***** */ else { /*If the control reaches here, the order is Eat in type. Therefore, the Token No is appended to the waiterQueue For Eat In Customers */ Print("\nOrderTaker %d gives token number %d to Customer %d", C[i].myOrderTaker, C[i].custTokenNo, i); Acquire(waitQueueLock); /*Ensures that only Bagger or Waiter use the queue at a time*/ AppendList(waiterQueue, bagTokenNo); /*The Order which needs to be bagged, its Token No. is appended to the waiter queue */ itemsInWaiterQueue++; Release(waitQueueLock); } /*return back to orderTakerFn*/ }
void CSTransform::SetMatrix(const double matrix[16], bool concatenate) { ApplyMatrix(matrix,concatenate); AppendList(MATRIX,matrix,16); }
int main(int argc, char* argv[]) { //Check for the number of arguments if(argc != 4){ printf("Invalid Input Argument\n"); printHelp(); exit(1); } //direcotry file path int dirSize = strlen(argv[2]); char dir[dirSize + 1]; dir[0] = '\0'; strcat(dir, argv[2]); int urlSize = strlen(argv[1]); char inputURL[urlSize + 1]; inputURL[0] = '\0'; strcat(inputURL, argv[1]); //Get the max depth number. int inputDepth = atoi(argv[3]); //Check if correct depth is provided. if(inputDepth > 4 || inputDepth < 0){ printf("Invalid [depth]\n"); printHelp(); exit(1); } //Check for URL validity if(!strstr(inputURL,URL_PREFIX)){ printf("Invalid input [seed url]\n"); printHelp(); exit(1); } //checkf for directory location validity DIR* directory = opendir(dir); if(directory){ closedir(directory); } else if(ENOENT == errno){ printf("Directory does not exist\n"); printHelp(); exit(1); } else{ printf("Directory can't be opened\n"); printHelp(); exit(1); } // init curl curl_global_init(CURL_GLOBAL_ALL); // setup seed page WebPage* seedWebPage = calloc(1, sizeof(WebPage));//Memory allocation for seed webpage seedWebPage->url = calloc((strlen(inputURL) + 1), sizeof(char));//Memory allocation to the seedURL seedWebPage->url[0] = '\0'; strcat(seedWebPage->url, inputURL); seedWebPage->depth = 0; seedWebPage->html = NULL; //Initialize data structures HashTable* visitedURLHash = initHashTable(); List* webPageList = initializeList(); webPageList->head->page = seedWebPage; //get seed webpage. if(GetWebPage(seedWebPage)){ // write seed file FILE *fPointer; char* pathVar1 = pathToDirectory(dir, fileNumber); fPointer = fopen(pathVar1, "w"); free(pathVar1); writeHTMLtoFile(fPointer, seedWebPage); //free(fPointer); if(inputDepth == 0){ curl_global_cleanup(); free(seedWebPage->html); free(seedWebPage->url); free(seedWebPage); //free webPageList and hashtable free(webPageList); for(int i = 0; i < MAX_HASH_SLOT; i++){ free(visitedURLHash->table[i]->url); free(visitedURLHash->table[i]); } free(visitedURLHash); return 0; } fileNumber += 1; depth += 1; HashTableInsert(visitedURLHash, seedWebPage->url); //mark as visited // extract urls from seed page char * result; int pos = 0; while((pos = GetNextURL(seedWebPage->html, pos, seedWebPage->url, &result))>0){ if(NormalizeURL(result) && strstr(result,URL_PREFIX)){ strtok(result, "#"); //If not in hashtable, add it to the hashtable and add it to the webPageList. if(HashTableLookup(visitedURLHash, result) == 0){ HashTableInsert(visitedURLHash, result); AppendList(webPageList, webPageInit(result, depth)); free(result); } } } if(webPageList->head->next->next == NULL){ //seed redirect case webPageList->head->next->page->depth = 0; fileNumber = 1; } tempWebPage = PopList(webPageList); // Get rid of visited seedPage } else{ curl_global_cleanup(); tempWebPage = PopList(webPageList); free(seedWebPage->html); free(seedWebPage->url); free(seedWebPage); //free(tempWebPage); free(webPageList); for(int i = 0; i < MAX_HASH_SLOT; i++){ free(visitedURLHash->table[i]->url); free(visitedURLHash->table[i]); } free(visitedURLHash); exit(1); } //while there are urls to crawl while(webPageList->head != NULL && webPageList->tail != NULL){ // get webpage for url tempWebPage = PopList(webPageList); if(GetWebPage(tempWebPage)){ // write page file char* pathVar = pathToDirectory(dir, fileNumber); FILE *fPointer = fopen(pathVar, "w"); free(pathVar); printf("Found link: %s\n",tempWebPage->url); writeHTMLtoFile(fPointer, tempWebPage); fileNumber += 1; if((tempWebPage->depth + 1) <= inputDepth ){ char * resultTemp; int posTemp = 0; while((posTemp = GetNextURL(tempWebPage->html, posTemp, tempWebPage->url, &resultTemp))>0){ if( NormalizeURL(resultTemp) && strstr(resultTemp,URL_PREFIX) ){ strtok(resultTemp, "#"); //insert to the hashtable and the webPageList if not already present if(HashTableLookup(visitedURLHash, resultTemp) == 0){ HashTableInsert(visitedURLHash, resultTemp); AppendList(webPageList, webPageInit(resultTemp, tempWebPage->depth+1)); } } free(resultTemp); } } free(tempWebPage->url); free(tempWebPage->html); free(tempWebPage); } else{ free(tempWebPage->url); free(tempWebPage->html); free(tempWebPage); } sleep(INTERVAL_PER_FETCH); } // cleanup curl curl_global_cleanup(); free(seedWebPage->url); free(seedWebPage->html); free(seedWebPage); free(webPageList); //free the hashtable for(int i = 0; i < MAX_HASH_SLOT; i++){ if(visitedURLHash->table[i]->url != NULL){ HashTableNode* currNode = visitedURLHash->table[i]; while(currNode->next != NULL){ HashTableNode* tempNode = currNode; currNode = currNode->next; free(tempNode->url); free(tempNode); } free(currNode->url); free(currNode); } else{ free(visitedURLHash->table[i]); } } free(visitedURLHash); return 0; }
// Function to crawl a given webpage for links. int CrawlPage(WebPage *wp) { char *result; // variable to hold the url. int pos = 0; // position in each html page. WebPage *newPage; // New webpage. // Check that the depth does not exceed the depth passed. if (wp->depth >= depth) { return 0; } printf("\n"); printf("[crawler]: Crawling - %s\n", wp->url); // Print the url being curled. printf("\n"); // Loop through each html page to get all its urls. while ((pos = GetNextURL(wp->html, pos, wp->url, &result)) >= 0) { // Check that the url has proper domain (old-www). if (strncmp(result, URL_PREFIX, strlen(URL_PREFIX)) != 0) { free(result); continue; } // Normalize the url. if (!NormalizeURL(result)) { free(result); continue; } // Check that the url isn't already in the hash table. if (!InHashTable(result)) { AddToHashTable(result); // Add the url to the hash table. // Setup new page for each url. newPage = calloc(1, sizeof(WebPage)); newPage->depth = wp->depth + 1; newPage->url = (char *)malloc(strlen(result) + 1); if (!newPage->url) { // Check that memory was allocated. continue; } strcpy(newPage->url, result); // Get html for each url. if (!GetWebPage(newPage)) { FreeWebMemory(newPage); free(result); continue; } printf("[crawler]: Parser found link - %s\n", result); // Add to the list of webpages to be visited. if (!AppendList(newPage)) { free(result); return 0; } } free(result); } return 1; }
void GList::operator=(const GList &cpy) { AppendList(&cpy); }