出于某种原因,当我输入变量move
为例如a1
或时c2
,move[1]
打印为1
但在算术中使用时,实际上等于48 + move[1]
?我不知道这48
是从哪里来的,因为其余代码中的最高值是 3。
std::string alphabet = "ABC";
std::vector<std::vector<int>> spaces{{1, 2, 3},{1, 2, 3},{1, 2, 3}};
std::vector<std::vector<int>> taken {{0, 0, 0},{0, 0, 0},{0, 0, 0}};
std::vector<char> symbols {'-','X','O'};
bool ValidateMove(std::string move, int player)
{
std::cout << move[1] << " " << move[1] + 0 << "\n\n";
int a;
switch(toupper(move[0]))
{
case 'A':
a = 0;
break;
case 'B':
a = 1;
break;
case 'C':
a = 2;
break;
}
for (int i = 0; i < spaces[a].size(); i++) // FOR SOME REASON MOVE[1] = 48 + i!!!
{
/* <debugging prints> */
std::cout << "\nspaces[a][i]:" << spaces[a][i] << " move[1]:" << move[1] << "\n"; // outputs as expected
if (spaces[a][i] > move[1]){
std::cout << "greater";
} // shouldn't work and doesn't
if (spaces[a][i] < move[1]){
std::cout << "less than";
std::cout << "\n -= " << move[1]- 0;
} //SHOULDN'T WORK BUT DOES -> move[1] - 0 is 48 + move[1] but when you just std::cout << move[1] you get what you should?
/* </debugging prints> */
if (spaces[a][i] == move[1])
{
if (player == 1)
{
taken[a][i] == 1;
}
else
{
taken[a][i] == 2;
}
for (int f = 0; f < taken.size(); f++)
{
for (int g = 0; g < taken[f].size(); g++)
{
std::cout << taken[f][g] << " ";
}
std::cout << "\n";
}
spaces[a].erase(spaces[i].begin() + i);
return true;
}
}
return false;
}