I\'m currently making a tic-tac-toe program with AI and i\'m having a bit of a trouble translating this line of code (python) :
RANKS = dict([(4,3),
The C++ equivalent of Python's dict
is std::map
. To initialize a map using a similar syntax, do this:
std::map myMap = {{4,3}, # center = 3
{0,2},{2,2},{6,2},{8,2}, # corners = 2
{1,1},{3,1},{5,1},{7,1}}; # sides = 1
Note that this needs C++11.
If you cannot use C++11, turn to map_list_of in Boost.Assign. The example from their page is:
using namespace boost::assign; // bring 'map_list_of()' into scope
std::map next = map_list_of(1,2)(2,3)(3,4)(4,5)(5,6);