Files
itgmania212121/stepmania/src/PlayerAI.cpp
T

107 lines
3.5 KiB
C++
Raw Normal View History

2003-04-07 22:07:44 +00:00
#include "global.h"
#include "PlayerAI.h"
#include "RageUtil.h"
#include "IniFile.h"
#include "RageException.h"
#include "GameState.h"
2003-07-22 07:47:27 +00:00
#include "arch/arch.h"
#include "PlayerState.h"
2003-04-07 22:07:44 +00:00
2003-12-10 09:02:55 +00:00
#define AI_PATH "Data/AI.ini"
2003-04-07 22:07:44 +00:00
struct TapScoreDistribution
{
2003-04-22 04:54:04 +00:00
float fPercent[NUM_TAP_NOTE_SCORES];
TapNoteScore GetTapNoteScore()
2003-04-07 22:07:44 +00:00
{
float fRand = randomf(0,1);
2003-04-22 04:54:04 +00:00
float fCumulativePercent = 0;
for( int i=0; i<=TNS_MARVELOUS; i++ )
{
fCumulativePercent += fPercent[i];
2003-05-08 22:17:22 +00:00
if( fRand <= fCumulativePercent+1e-4 ) /* rounding error */
2003-04-07 22:07:44 +00:00
return (TapNoteScore)i;
2003-04-22 04:54:04 +00:00
}
ASSERT(0); // the fCumulativePercents must sum to 1.0, so we should never get here!
2003-04-07 22:07:44 +00:00
return TNS_MARVELOUS;
}
2003-04-07 22:07:44 +00:00
};
TapScoreDistribution g_Distributions[NUM_SKILL_LEVELS];
void PlayerAI::InitFromDisk()
2003-04-07 22:07:44 +00:00
{
IniFile ini;
2004-05-23 02:27:51 +00:00
ini.ReadFile( AI_PATH );
for( int i=0; i<NUM_SKILL_LEVELS; i++ )
2003-04-07 22:07:44 +00:00
{
CString sKey = ssprintf("Skill%d", i);
if( ini.GetKey(sKey)==NULL )
2003-04-25 00:01:35 +00:00
RageException::Throw( "AI.ini: '%s' doesn't exist.", sKey.c_str() );
2003-04-07 22:07:44 +00:00
TapScoreDistribution& dist = g_Distributions[i];
2003-04-22 04:54:04 +00:00
dist.fPercent[TNS_NONE] = 0;
2003-10-02 02:03:29 +00:00
ini.GetValue ( sKey, "MissWeight", dist.fPercent[TNS_MISS] );
ini.GetValue ( sKey, "BooWeight", dist.fPercent[TNS_BOO] );
ini.GetValue ( sKey, "GoodWeight", dist.fPercent[TNS_GOOD] );
ini.GetValue ( sKey, "GreatWeight", dist.fPercent[TNS_GREAT] );
ini.GetValue ( sKey, "PerfectWeight", dist.fPercent[TNS_PERFECT] );
ini.GetValue ( sKey, "MarvelousWeight", dist.fPercent[TNS_MARVELOUS] );
2003-04-22 04:54:04 +00:00
float fSum = 0;
2004-09-21 07:53:39 +00:00
for( int j=0; j<NUM_TAP_NOTE_SCORES; j++ )
2003-04-22 04:54:04 +00:00
fSum += dist.fPercent[j];
2004-09-21 07:53:39 +00:00
for( int j=0; j<NUM_TAP_NOTE_SCORES; j++ )
2003-04-22 04:54:04 +00:00
dist.fPercent[j] /= fSum;
}
}
2003-04-07 22:07:44 +00:00
TapNoteScore PlayerAI::GetTapNoteScore( const PlayerState* pPlayerState )
2003-04-07 22:07:44 +00:00
{
int iCpuSkill = pPlayerState->m_iCpuSkill;
2004-01-12 03:47:55 +00:00
int iSumOfAttackLevels =
pPlayerState->m_fSecondsUntilAttacksPhasedOut > 0 ?
pPlayerState->m_iLastPositiveSumOfAttackLevels :
2004-01-12 03:47:55 +00:00
0;
ASSERT_M( iCpuSkill>=0 && iCpuSkill<NUM_SKILL_LEVELS, ssprintf("%i", iCpuSkill) );
ASSERT_M( pPlayerState->m_PlayerController == PC_CPU, ssprintf("%i", pPlayerState->m_PlayerController) );
2004-01-12 03:47:55 +00:00
iCpuSkill -= iSumOfAttackLevels*3;
CLAMP( iCpuSkill, 0, NUM_SKILL_LEVELS-1 );
TapScoreDistribution& distribution = g_Distributions[iCpuSkill];
return distribution.GetTapNoteScore();
}
2004-05-31 21:55:14 +00:00
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/