etintel wrote:
I would like to add function immediateneighbors(...) in universe.cpp to the python API. What do I have to do?
If you want to return a std::map<double, int> to Python, you'll need to use the map_indexing_suite to expose that class to Python, similar to how the vector_indexing_suite is used in PythonAI.cpp (section titled in comments: STL Containers) to expose the vectors of int and std::string. Then you should be able to add the function to the Universe class in PythonUniverseWrapper.cpp using .def, similar to:
Code:
.def("systemHasStarlane", &Universe::SystemHasVisibleStarlanes)
.def("systemsConnected", &Universe::SystemsConnected)
I don't know whether you'd need to do anything with return value policies for this function, but if you did, return by value would seem appropriate.
Quote:
Also how do you loop through an array that has a double as an index?
It's a map, not an array. You can use
Code:
std::map<double, int>::iterator it = map.begin(); it != map.end(); ++it) { ... }
to iterate through it in C++. In Python, I'm not sure exactly how the resulting data structure would appear and function, but presumably it would be similar to a Python dict.