예제 #1
0
파일: CpuLogic.c 프로젝트: yu-tam/Reversi
/******************************************************** 
 *! @brief 関数
	-
@param[out]     -
@param[in]      -
@par            -
@return         -
@note      
*********************************************************/
PRIVATE void SearchNextNode( BEST_TABLE_INFO_T	*pBestInfo,
							 EVALUATE_TREE_T	*pCurrentNode,
							 PLAYER_T			CurrentPlayer )
{
	EVALUATE_TREE_T		pSearchNode;
	BEST_TABLE_INFO_T	ReturnedBestInfo;

	/* 再起探索終了 */
	if ( pCurrentNode->pNextNode == NULL ) {
		pBestInfo->Score	= pCurrentNode->Score;
		pBestInfo->h		= pCurrentNode->DiscInfo.h;
		pBestInfo->v		= pCurrentNode->DiscInfo.v;
			
		/* 末尾Nodeなので領域を解放する */
		FREE( pCurrentNode->pEvaluatReversiTable );
		FREE( pCurrentNode );
		return;
		
	} else {
  
		/* 再起探索開始 */
		SearchNextNode( &ReturnedBestInfo, pCurrentNode->pNextNode, CurrentPlayer );
		if ( CurrentPlayer == pCurrentNode->DiscInfo.CurrentPlayer ) {
			/* 自分のターンの盤面は最大評価値(自分にとって最も有利)となる選択肢を選択する */
			if ( pCurrentNode->Score < ReturnedBestInfo.Score ) {
				pBestInfo->Score	= ReturnedBestInfo.Score;
				pBestInfo->h		= ReturnedBestInfo.h;
				pBestInfo->v		= ReturnedBestInfo.v;
			} else {
				pBestInfo->Score	= pCurrentNode->Score;
				pBestInfo->h		= pCurrentNode->DiscInfo.h;
				pBestInfo->v		= pCurrentNode->DiscInfo.v;
			}
		} else {
			/* 相手のターンの盤面は最低評価値(自分にとって最も不利)となる選択肢を選択する */
			if ( pCurrentNode->Score > ReturnedBestInfo.Score ) {
				pBestInfo->Score	= ReturnedBestInfo.Score;
				pBestInfo->h		= ReturnedBestInfo.h;
				pBestInfo->v		= ReturnedBestInfo.v;
			} else {
				pBestInfo->Score	= pCurrentNode->Score;
				pBestInfo->h		= pCurrentNode->DiscInfo.h;
				pBestInfo->v		= pCurrentNode->DiscInfo.v;
			}
		}
		
		FREE( pCurrentNode->pEvaluatReversiTable );
		FREE( pCurrentNode );
		
		return;
	}
	
}
예제 #2
0
파일: CpuLogic.c 프로젝트: yu-tam/Reversi
/******************************************************** 
 *! @brief 関数
	-
@param[out]     -
@param[in]      -
@par            -
@return         -
@note      
*********************************************************/
PRIVATE void SearchNextDepthNode( BEST_TABLE_INFO_T	*pBestInfo,
										 EVALUATE_TREE_T	*pCurrentNode,
										 PLAYER_T			CurrentPlayer )
{
	EVALUATE_TREE_T		*pSearchNode;
	EVALUATE_TREE_T		*pDeleteNode;
	BEST_TABLE_INFO_T	ReturnedBestInfo;
	ERROR_CHECK			Result;
	
	/* 評価木の最深部に達した場合の処理 */
	if ( pCurrentNode->pNextDepthNode == NULL ) {
	
		if ( pCurrentNode->pNextNode == NULL ) {
			
			/* NextDepthNodeもNextNodeもNULLなのでCurrentNodeのスコア情報を返す */
			pBestInfo->Score	= pCurrentNode->Score;
			pBestInfo->h		= pCurrentNode->DiscInfo.h;
			pBestInfo->v		= pCurrentNode->DiscInfo.v;
			
			/* 末尾Nodeなので領域を解放する */
			FREE( pCurrentNode->pEvaluatReversiTable );
			FREE( pCurrentNode );
			return;
			
		} else {
			
			/* NextDepthNodeがNULLなのでNextNodeを探索して最善手を算出する */
			SearchNextNode( &ReturnedBestInfo, pCurrentNode->pNextNode, CurrentPlayer );
			if ( CurrentPlayer == pCurrentNode->pNextNode->DiscInfo.CurrentPlayer ) {
				/* 自分のターンの盤面は最大評価値(自分にとって最も有利)となる選択肢を選択する */
				if ( pCurrentNode->Score < ReturnedBestInfo.Score ) {
					pBestInfo->Score	= ReturnedBestInfo.Score;
					pBestInfo->h		= ReturnedBestInfo.h;
					pBestInfo->v		= ReturnedBestInfo.v;
				} else {
					pBestInfo->Score	= pCurrentNode->Score;
					pBestInfo->h		= pCurrentNode->DiscInfo.h;
					pBestInfo->v		= pCurrentNode->DiscInfo.v;
				}
			} else {
				/* 相手のターンの盤面は最低評価値(自分にとって最も不利)となる選択肢を選択する */
				if ( pCurrentNode->Score > ReturnedBestInfo.Score ) {
					pBestInfo->Score	= ReturnedBestInfo.Score;
					pBestInfo->h		= ReturnedBestInfo.h;
					pBestInfo->v		= ReturnedBestInfo.v;
				} else {
					pBestInfo->Score	= pCurrentNode->Score;
					pBestInfo->h		= pCurrentNode->DiscInfo.h;
					pBestInfo->v		= pCurrentNode->DiscInfo.v;
				}
			}
			
			FREE( pCurrentNode->pEvaluatReversiTable );
			FREE( pCurrentNode );
			return;
		}
	}
	
	/* 評価木に次の深さが存在する場合の処理 */
	else {
	
		/* 深さ探索を実行する */
		SearchNextDepthNode( &ReturnedBestInfo, pCurrentNode->pNextDepthNode, CurrentPlayer );
		pBestInfo->Score	= ReturnedBestInfo.Score;
		pBestInfo->h		= ReturnedBestInfo.h;
		pBestInfo->v		= ReturnedBestInfo.v;
		
		/* 深さ探索が終わったらNextNodeの探索を実行していく */
		pSearchNode = pCurrentNode->pNextNode;
		
		while (1) {
			
			if ( pSearchNode == NULL ) {
				/* NextNodeがNULLであればCurrentNode領域を解放してNextNode探索終了 */
				FREE( pCurrentNode->pEvaluatReversiTable );
				FREE( pCurrentNode );
				return;
			} else {
				/* NextNodeが存在する場合はNextNodeに対して深さ探索を実行する */
				SearchNextDepthNode( &ReturnedBestInfo, pSearchNode, CurrentPlayer );
				
				if ( CurrentPlayer == pSearchNode->DiscInfo.CurrentPlayer ) {
					/* 自分のターンの盤面は最大評価値(自分にとって最も有利)となる選択肢を選択する */
					if ( pBestInfo->Score < ReturnedBestInfo.Score ) {
						pBestInfo->Score	= ReturnedBestInfo.Score;
						pBestInfo->h		= ReturnedBestInfo.h;
						pBestInfo->v		= ReturnedBestInfo.v;
					} else {
						;
					}
				} else {
					/* 相手のターンの盤面は最低評価値(自分にとって最も不利)となる選択肢を選択する */
					if ( pBestInfo->Score > ReturnedBestInfo.Score ) {
						pBestInfo->Score	= ReturnedBestInfo.Score;
						pBestInfo->h		= ReturnedBestInfo.h;
						pBestInfo->v		= ReturnedBestInfo.v;
					} else {
						;
					}
				}
				
				/* SearchNodeのポインタを繋ぎ直す */
				pDeleteNode = pSearchNode;
				pSearchNode = pSearchNode->pNextNode;
				/* 探索完了したNodeは領域を解放する */
				FREE( pDeleteNode->pEvaluatReversiTable );
				FREE( pDeleteNode );
			}
		}
		
	}
	
}
예제 #3
0
int GetProcInfo ()
{
	struct tm *pre;
	long clock = 0;
	char sCPU[100], sMEM[100];
	char sProcName[PROCESS_NAME_LEN];   
	int iTmpBillFlowID=-1, iTmpProcessID=-1; //已经显示的最大ID
	
	int iTmpAppID = -1;
	int iSelecetdPos = -2;

	int iListPos=0;
	
	//  
	char tmp[128] = {0};
	int ret = 0;
	InitList();
/*
	Control *pEdit = GetCtlByID(process_handle, 13);
	gStr2Arr(pEdit->sData);	
    */
    g_iflowid[0] = 0;
	
	Control *pEdit1 = GetCtlByID(process_handle, 15);
	gStr2Appid(pEdit1->sData);

	DetachShm ();

	if (AttachShm (0, (void **)&pInfoHead) >= 0) {
	    pProcInfoHead = &pInfoHead->ProcInfo;
	} else {
	    return -1;
	}

	time ((time_t *)&clock);
	    
	memset(aiProcessID, 0, MAX_APP_NUM*sizeof(int));

   iSelecetdPos = -1;

	while (iListPos < pInfoHead->iProcNum)
	{
	    int iSelecetdPos = SearchNextNode(&iTmpBillFlowID, &iTmpProcessID,&iTmpAppID);
	    //iSelecetdPos=6;//= SearchNextNode(&iTmpBillFlowID, &iTmpProcessID,&iTmpAppID);
	 
	    if (iSelecetdPos < 0)
	        break;

	//
	//	if( g_iflowid[0] && iTmpBillFlowID != g_iflowid )
	//		continue;
	
			if( ((g_iflowid[0] && !IsInArr( iTmpBillFlowID )))||((g_iappid[0] && !IsInAppid( iTmpAppID ))) || 
				!(pProcInfoHead+iSelecetdPos)->iBillFlowID || !(pProcInfoHead+iSelecetdPos)->iProcessID )
				continue;
			
	    strncpy( sProcName, (pProcInfoHead+iSelecetdPos)->sName, PROCESS_NAME_LEN);
	    sProcName[PROCESS_NAME_LEN] ='\0';
	    
	    if ((pProcInfoHead+iSelecetdPos)->iState == ST_RUNNING) {
					memset(sCPU,0,sizeof(sCPU));
					memset(sMEM,0,sizeof(sMEM));
	        pre = localtime ((const time_t *)&(pProcInfoHead+iSelecetdPos)->lLoginTime);
	        GetSysProcInfo ((pProcInfoHead+iSelecetdPos)->iSysPID, sMEM, sCPU);
			memset( proc_list_data[iListPos],0,strlen(proc_list_data[iListPos]) );
	        sprintf (proc_list_data[iListPos], 
	        "%-4d %6d %-20s %02d%02d%02d%02d %11d %-4s %5s %3s%\0",
	        (pProcInfoHead+iSelecetdPos)->iAppID,
	        (pProcInfoHead+iSelecetdPos)->iProcessID,
	        sProcName, 
	        pre->tm_mon+1,
	        pre->tm_mday,
	        pre->tm_hour,
	        pre->tm_min,
	        (pProcInfoHead+iSelecetdPos)->iAllTickets,
	        gsState[(pProcInfoHead+iSelecetdPos)->iState], 
	        sMEM, 
	        sCPU
	        );
	    }
	    else {
	        sprintf (proc_list_data[iListPos], 
	        "%-4d %6d %-20s -------- %11d %-4s %5d %3d%\0",
	        (pProcInfoHead+iSelecetdPos)->iAppID,
	        (pProcInfoHead+iSelecetdPos)->iProcessID,
	        sProcName,
	        (pProcInfoHead+iSelecetdPos)->iAllTickets,
	        gsState[(pProcInfoHead+iSelecetdPos)->iState], 
	        0,
	        0
	        );
	    }
	    proc_list_index[iListPos] = proc_list_data[iListPos];
	    aiProcessID[iListPos] = (pProcInfoHead+iSelecetdPos)->iProcessID;
	    
	    iListPos++;

		//插入InfoList
		InfoList[ret] = pProcInfoHead+iSelecetdPos;

		
	    ret ++;
	    //iSelecetdPos = -1;
	}
	l_lprocnum = ret;
	return ret;
}