KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to fill a vector with 8 pairs. Each pair represents the moves in x and y coordinates a knight in a game of chess can make. At the moment I'm doing it like this vector<pair<int,int>> moves; pair<int,int> aPair; aPair.first = -2; aPair.second = -1; moves.push_back(aPair); aPair.first = -2; aPair.second = 1; moves.push_back(aPair); aPair.first = -1; aPair.second = -2; moves.push_back(aPair); aPair.first = -1; aPair.second = 2; moves.push_back(aPair); aPair.first = 1; aPair.second = -2; moves.push_back(aPair); aPair.first = 1; aPair.second = 2; moves.push_back(aPair); aPair.first = 2; aPair.second = -1; moves[6].push_back(aPair); aPair.first = 2; aPair.second = 1; moves.push_back(aPair); I'm doing this to learn about the Std library. This seems like a hopelessly inefficient way of solving this problem. Anyone have a more elegant solution?
Tags (comma-separated)
Save Edits
Cancel