Files
itgmania212121/stepmania/src/PlayerAI.cpp
T

89 lines
2.3 KiB
C++
Raw Normal View History

2003-04-07 22:07:44 +00:00
#include "global.h"
/*
-----------------------------------------------------------------------------
Class: PlayerAI
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "PlayerAI.h"
#include "RageUtil.h"
#include "IniFile.h"
#include "RageException.h"
#include "GameState.h"
2003-04-07 22:07:44 +00:00
#include <math.h>
2003-07-22 07:47:27 +00:00
#include "arch/arch.h"
2003-04-07 22:07:44 +00:00
2003-07-22 07:47:27 +00:00
#define AI_PATH BASE_PATH "Data" SLASH "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;
2003-07-22 07:47:27 +00:00
ini.SetPath( AI_PATH );
ini.ReadFile();
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;
int j;
for( j=0; j<NUM_TAP_NOTE_SCORES; j++ )
fSum += dist.fPercent[j];
for( j=0; j<NUM_TAP_NOTE_SCORES; j++ )
dist.fPercent[j] /= fSum;
}
}
2003-04-07 22:07:44 +00:00
TapNoteScore PlayerAI::GetTapNoteScore( int iCpuSkill, int iSumOfAttackLevels )
2003-04-07 22:07:44 +00:00
{
// shouldn't call this unless we're CPU controlled
ASSERT( iCpuSkill>=0 && iCpuSkill<NUM_SKILL_LEVELS );
iCpuSkill -= iSumOfAttackLevels;
CLAMP( iCpuSkill, 0, NUM_SKILL_LEVELS-1 );
TapScoreDistribution& distribution = g_Distributions[iCpuSkill];
return distribution.GetTapNoteScore();
}