mirror of
https://gitflic.ru/project/w0lf/bulls-and-cows-cpp.git
synced 2026-03-28 16:02:46 +03:00
Refactored IsEqual() function.
This commit is contained in:
@@ -26,7 +26,7 @@ void CGame::Init(int digits)
|
||||
n = d(e);
|
||||
if (i > 0)
|
||||
{
|
||||
while (IsEqual1(m_uGuessedNumber, n, i))
|
||||
while (IsEqual(m_uGuessedNumber, n, i))
|
||||
{
|
||||
n = d(e);
|
||||
}
|
||||
@@ -125,7 +125,7 @@ int CGame::GetNumber(CStep step)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsEqual2(sNumber, c, i))
|
||||
if (IsEqual(sNumber, c, i))
|
||||
{
|
||||
return -4;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,8 @@ private:
|
||||
int* m_uGuessedNumber;
|
||||
std::vector<CStep> m_Steps;
|
||||
|
||||
bool IsEqual1(const int*, const int, int);
|
||||
|
||||
bool IsEqual2(const std::wstring&, const wchar_t, int);
|
||||
template<typename T, typename N>
|
||||
bool IsEqual(const T, const N, int);
|
||||
|
||||
int GetNumber(CStep);
|
||||
|
||||
@@ -37,3 +36,17 @@ public:
|
||||
|
||||
void Start();
|
||||
};
|
||||
|
||||
template<typename T, typename N>
|
||||
bool CGame::IsEqual(const T number, const N digit, int i)
|
||||
{
|
||||
i--;
|
||||
bool result = false;
|
||||
|
||||
while (i >= 0)
|
||||
{
|
||||
if (digit == number[i]) result = true;
|
||||
i--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user