bool CSymbolEngineMemorySymbols::EvaluateSymbol(const char *name, double *result, bool log /* = false */) {
  // memory-commands
  // "name" = query
  FAST_EXIT_ON_OPENPPL_SYMBOLS(name);
  if (memcmp(name, "me_", 3) == 0) {
    write_log(preferences.debug_memorysymbols(), 
      "[CSymbolEngineMemorySymbols] EvaluateSymbol(%s)\n", name);
    if (memcmp(name, "me_st_", 6) == 0) {  
      Store(name);
      *result = kUndefinedZero;
      return true;
    } else if (memcmp(name, "me_re_", 6) == 0) {
      *result = Recall(name);
      return true;
    } else if (memcmp(name, "me_inc_", 7) == 0) {
      Increment(name);
      *result = kUndefinedZero;
      return true;
    } else {
    // Looks like a memory-command, but is invalid
    return false;
    }
  }
  // Not a memory symbol
  return false;
}
Esempio n. 2
0
void AlignToGridCmd::Align (GraphicView* gv, float refx, float refy) {
    MoveData* md = (MoveData*) Recall(gv->GetGraphicComp());

    if (md == nil) {
        Viewer* v = gv->GetViewer();
        Grid* grid = (v == nil) ? nil : v->GetGrid();

        if (grid == nil) {
            return;
        }

        Graphic* g = gv->GetGraphic();
        Transformer t;
        g->Parent()->TotalTransformation(t);
        t.Invert();

        Coord cx = iv26_round(refx);
        Coord cy = iv26_round(refy);

        grid->Constrain(cx, cy);

        float dx, dy, trefx, trefy;

        t.Transform(float(cx), float(cy), dx, dy);
        t.Transform(refx, refy, trefx, trefy);

        dx -= trefx;
        dy -= trefy;
        Store(gv->GetGraphicComp(), new MoveData(dx, dy));

    }
    Move(gv->GetGraphicComp());
}
Esempio n. 3
0
void AlignToGridCmd::Unmove (GraphicComp* gc) {
    MoveData* md = (MoveData*) Recall(gc);

    if (md != nil) {
        MoveCmd movement(GetEditor(), md->_dx, md->_dy);
        gc->Uninterpret(&movement);
    }
}
Esempio n. 4
0
void cSkillManager::NetworkMsgParse( BYTE Protocol, void* pMsg )
{
	switch(Protocol)
	{
	case MP_SKILL_START_SYN:
		{
			MSG_SKILL_START_SYN* pmsg = ( MSG_SKILL_START_SYN* )pMsg;
				
			CObject* object = g_pUserTable->FindUser( pmsg->Operator );
		
			if( ! object )
			{
				break;
			}

			// 080904 LYW --- SkillManager : 공성전 중 사용할 수 없는 스킬 체크.
			if( SIEGEWARFAREMGR->Is_CastleMap() == FALSE &&
				SIEGEWARFAREMGR->IsSiegeWarfareZone() &&
				SIEGEWARFAREMGR->GetState() > eSiegeWarfare_State_Before )
			{
				if( SIEGEWARFAREMGR->IsFobiddenSkill(pmsg->SkillIdx) ) return ;
			}

			SKILL_RESULT result = SKILL_FAIL_ETC;

			if( object->GetObjectKind() == eObjectKind_Player )
				result = OnSkillStartSyn( pmsg );
			else if( object->GetObjectKind() == eObjectKind_Pet )
				result = OnPetSkillStartSyn( pmsg );

			// 080610 LUJ, 스킬 실패 시 메시지를 반환하도록 함
			if( result != SKILL_SUCCESS )
			{
				CObject* object = g_pUserTable->FindUser( pmsg->Operator );

				if( ! object )
				{
					break;
				}

				MSG_DWORD2 message;
				ZeroMemory( &message, sizeof( message ) );
				message.Category	= MP_SKILL;
				message.Protocol	= MP_SKILL_START_NACK;
				message.dwData1		= pmsg->SkillIdx;
				message.dwData2		= result;

				object->SendMsg( &message, sizeof( message ) );
			}
		}
		break;
	// 080602 LUJ, 전서버 대상 스킬이 전파됨
	case MP_SKILL_START_TO_MAP:
		{
			const MSG_ITEM_SKILL_START_TO_MAP* const receivedMessage = (MSG_ITEM_SKILL_START_TO_MAP*)pMsg;
			const cActiveSkillInfo* const skillInfo = GetActiveInfo( receivedMessage->mSkill.wSkillIdx );

			if(0 == skillInfo ||
				TARGET_KIND_WORLD != skillInfo->GetInfo().Area)
			{
				break;
			}

			typedef std::set< DWORD >	ObjectIndexSet;
			ObjectIndexSet				objectIndexSet;

			switch(skillInfo->GetInfo().AreaTarget)
			{
			case eSkillAreaTargetGuild:
				{
					GUILDMEMBERINFO memberInfo[ MAX_GUILD_MEMBER ] = { 0 };
					CGuild*	guild = GUILDMGR->GetGuild( receivedMessage->dwObjectID );

					if( ! guild )
					{
						break;
					}

					guild->GetTotalMember( memberInfo );

					for(
						DWORD size = sizeof( memberInfo ) / sizeof( *memberInfo );
						size--; )
					{
						objectIndexSet.insert( memberInfo[ size ].MemberIdx );
					}

					break;
				}
			case eSkillAreaTargetFamily:
				{
					const DWORD familyIndex	 = receivedMessage->dwObjectID;
					// 080602 LUJ, 패밀리는 맵 서버에 데이타가 없고, 에이전트에 있다. 번거롭지만
					//				DB에 회원 목록을 쿼리해서 버프를 적용하도록 하자.
					// 081012 LUJ, 일부 로컬은 프로시저 호출 시 대소문자까지 일치해야 한다. 단, dbo는 소문자로 해야함. 이에 모든 프로시저 이름을 수정함
					g_DB.FreeMiddleQuery(
						RSkillAddToFamily,
						skillInfo->GetIndex(),
						"EXEC dbo.MP_FAMILY_MEMBER_LOADINFO %d",
						familyIndex );
					break;
				}
			case eSkillAreaTargetParty:
				{
					const DWORD	partyIndex	= receivedMessage->dwObjectID;
					CParty*		party		= PARTYMGR->GetParty( partyIndex );

					if( ! party )
					{
						break;
					}

					for( DWORD i = 0; i < MAX_PARTY_LISTNUM; ++i )
					{
						objectIndexSet.insert(party->GetMemberID(i));
					}

					break;
				}
			}

			// 080602 LUJ, 선택된 집단을 대상으로 버프 스킬을 적용한다
			for(
				ObjectIndexSet::const_iterator it = objectIndexSet.begin();
				objectIndexSet.end() != it;
				++it )
			{
				CPlayer* player = ( CPlayer* )g_pUserTable->FindUser( *it );

				if( !	player ||
						player->GetObjectKind() != eObjectKind_Player )
				{
					continue;
				}

				AddBuffSkill(
					*player,
					skillInfo->GetInfo());
			}

			break;
		}
	case MP_SKILL_UPDATE_TARGET_SYN:
		{
			MSG_SKILL_UPDATE_TARGET* pmsg = ( MSG_SKILL_UPDATE_TARGET* )pMsg;

			OnSkillTargetUpdate( pmsg );
		}
		break;
	case MP_SKILL_CANCEL_SYN:
		{
			MSG_DWORD* pmsg = ( MSG_DWORD* )pMsg;
			OnSkillCancel( pmsg );
		}
		break;
		// 091127 LUJ, 플레이어를 소환한다
	case MP_SKILL_RECALL_SYN:
		{
			const MSG_NAME_DWORD3* const receivedMessage = (MSG_NAME_DWORD3*)pMsg;
			const DWORD	recallPlayerIndex = receivedMessage->dwObjectID;
			const DWORD	targetPlayerinex = receivedMessage->dwData1;
			const DWORD	skillIndex = receivedMessage->dwData2;
			const MAPTYPE targetMap = MAPTYPE(receivedMessage->dwData3);
			LPCTSTR targetPlayerName = receivedMessage->Name;

			Recall(
				recallPlayerIndex,
				targetPlayerinex,
				targetPlayerName,
				targetMap,
				skillIndex);
		}
		break;
	// 100211 ONS 부활계열 스킬 사용시 대상자에게 부활의사를 묻는 처리 추가
	case MP_SKILL_RESURRECT_ACK:
		{
			MSGBASE* pmsg = ( MSGBASE* )pMsg;
			CPlayer* pPlayer = (CPlayer*)g_pUserTable->FindUser( pmsg->dwObjectID );

			if( ! pPlayer || eObjectKind_Player != pPlayer->GetObjectKind() )
			{
				break;
			}

			const cActiveSkillInfo* const pSkillInfo = GetActiveInfo(
				pPlayer->GetCurResurrectIndex());

			if(0 == pSkillInfo)
			{
				break;
			}
			
			// 부활대상이 수락했을 경우, 부활 처리를 실행한다.
			EXPTYPE exp = pPlayer->OnResurrect();
			exp = (EXPTYPE)(exp * ( pSkillInfo->GetInfo().UnitData / 100.f )) ;
			if( exp )
			{
				pPlayer->AddPlayerExpPoint( exp );
			}
			pPlayer->SetCurResurrectIndex( 0 );	
		}
		break;
	// 부활 스킬에 의한 부활을 거부했을 경우
	case MP_SKILL_RESURRECT_NACK:
		{
			MSGBASE* pmsg = ( MSGBASE* )pMsg;
			CObject* object = g_pUserTable->FindUser( pmsg->dwObjectID );
			if( ! object || eObjectKind_Player != object->GetObjectKind() )
			{
				break;
			}

			CPlayer* pPlayer = (CPlayer*)object;
			pPlayer->SetCurResurrectIndex( 0 );	
		}
		break;
	}
}
int main(int argc, char **argv)
{
    std::cout << "Hello, welcome to NeuralNetwork Testing program!!" << std::endl;

    ThreeLayerNetwork initialNetwork = ThreeLayerNetwork::GetNewNetworkFromFile(); //LoadInitialNetwork();
    ExampleContainer testExamples = LoadTestingExamples();
    std::fstream* outputFile = GetOutputFile();
    (*outputFile).setf(std::ios::fixed);
    (*outputFile) << std::setprecision(3);

    std::list<Example> examples = testExamples.GetExamples();

    std::vector<int> A (testExamples.GetOutputSize(), 0); // expected 1, predicted 1
    std::vector<int> B (testExamples.GetOutputSize(), 0); // expected 0, predicted 1
    std::vector<int> C (testExamples.GetOutputSize(), 0); // expected 1, predicted 0
    std::vector<int> D (testExamples.GetOutputSize(), 0); // expected 0, predicted 0

    std::list<Example>::iterator ex;
    for (ex = examples.begin(); ex != examples.end(); ex++)
    {
        initialNetwork.PropogateForward((*ex));
        std::vector<bool> outputs = initialNetwork.GetOutputs();
        std::vector<bool> expectedOutputs = ex->GetOutputs();
        if (outputs.size() != expectedOutputs.size())
        {
            std::cerr << "Something weird happened - expectedOutputs size is not the same as the outputs size - this should have been ensured elsewhere!" << std::endl;
            exit(-1);
        }
        for (int i = 0; i < outputs.size(); i++)
        {
            if (expectedOutputs[i] == true) //expected 1
            {
                if (outputs[i] == true) // predicted 1
                {
                    A[i]++;
                }
                else // predicted 0
                {
                    C[i]++;
                }
            }
            else // expected 0
            {
                if (outputs[i] == true) // predicted 1
                {
                    B[i]++;
                }
                else // predicted 0
                {
                    D[i]++;
                }
            }
        }
    }

    std::vector<double> OverallAccuracy (testExamples.GetOutputSize(), 0);
    std::vector<double> Precision (testExamples.GetOutputSize(), 0);
    std::vector<double> Recall (testExamples.GetOutputSize(), 0);
    std::vector<double> F1 (testExamples.GetOutputSize(), 0);

    for (int i = 0; i < testExamples.GetOutputSize(); i++)
    {
        OverallAccuracy[i] = ((double) A[i] + D[i])/(A[i] + B[i] + C[i] + D[i]);
        Precision[i] = (double) A[i]/(A[i] + B[i]);
        Recall[i] = (double) A[i]/(A[i] + C[i]);
        F1[i] = (2*Precision[i]*Recall[i])/(Precision[i] + Recall[i]);
    }

    for (int i = 0; i < testExamples.GetOutputSize(); i++)
    {
        (*outputFile) << A[i] << " " << B[i] << " " << C[i] << " " << D[i] << " " << OverallAccuracy[i] << " " << Precision[i]
                      << " " << Recall[i] << " " << F1[i] << std::endl;
    }

    int microA = std::accumulate(A.begin(), A.end(), 0);
    int microB = std::accumulate(B.begin(), B.end(), 0);
    int microC = std::accumulate(C.begin(), C.end(), 0);
    int microD = std::accumulate(D.begin(), D.end(), 0);

    double microOverallAccuracy = ((double) microA + microD)/(microA + microB + microC + microD);
    double microPrecision = (double) microA/(microA + microB);
    double microRecall = (double) microA/(microA + microC);
    double microF1 = (2*microPrecision*microRecall)/(microPrecision + microRecall);

    std::cout << std::accumulate(OverallAccuracy.begin(), OverallAccuracy.end(), 0) << std::endl;

    double macroOverallAccuracy = std::accumulate(OverallAccuracy.begin(), OverallAccuracy.end(), 0.0)/ (double) OverallAccuracy.size();
    double macroPrecision = std::accumulate(Precision.begin(), Precision.end(), 0.0)/ (double) Precision.size();
    double macroRecall = std::accumulate(Recall.begin(), Recall.end(), 0.0)/ (double) Recall.size();
    double macroF1 = (2*macroPrecision*macroRecall)/(macroPrecision + macroRecall);

    (*outputFile) << microOverallAccuracy << " " << microPrecision << " " << microRecall << " " << microF1 << std::endl;
    (*outputFile) << macroOverallAccuracy << " " << macroPrecision << " " << macroRecall << " " << macroF1 << std::endl;

    outputFile->close();
}