src/main.cpp
/** Read recipes from a CSV file located at @p path
 * 
 * @param path Path to a file with recipes
 * 
 * @returns list of recipes
 */
Read recipes from a CSV file located at @p path

@param path Path to a file with recipes

@returns list of recipes
Read recipes from a CSV file located at @p path @param path Path to a file with recipes @returns list of recipes
std::vector<recap::recipe> read_recipes(const std::string& path)
{
    using namespace recap;
    io::CSVReader<8> input(path);
    input.read_header(io::ignore_extra_column, "fire", "cold", "lightning", "chaos", "value_min", "value_max", "cost", "slot");
    std::vector<recipe> result;
    result.push_back(recipe{ resistance{ 0, 0, 0, 0 }, 0, recipe::SLOT_ALL });
    resistance::item_t fire, cold, lightning, chaos, value_min, value_max;
    recipe::cost_t cost = 0;
    std::string slot_name;
    while (input.read_row(fire, cold, lightning, chaos, value_min, value_max, cost, slot_name))
    {
        if (fire > 1)
        {
            throw invalid_input_error{ 
                input.get_file_line(), 
                "fire value has to be 0 or 1." };
        }
        if (cold > 1)
        {
            throw invalid_input_error{ 
                input.get_file_line(), 
                "cold value has to be 0 or 1." };
        }
        if (lightning > 1)
        {
            throw invalid_input_error{ 
                input.get_file_line(), 
                "lightning value has to be 0 or 1." };
        }
        if (chaos > 1)
        {
            throw invalid_input_error{ 
                input.get_file_line(), 
                "chaos value has to be 0 or 1." };
        }
        if (value_min > value_max)
        {
            throw invalid_input_error{ 
                input.get_file_line(), 
                "minimal value must not be greater than maximal value." };
        }
        recipe::slot_t slot_value = parse_slot(slot_name);
        if (slot_value == recipe::SLOT_NONE)
        {
            throw invalid_input_error{ 
                input.get_file_line(), 
                "invalid slot: " + slot_name };
        }
        for (resistance::item_t i = value_min; i <= value_max; ++i)
        {
            double instance_cost = cost * (value_max - value_min + 1.0) / (value_max - i + 1.0);
            result.push_back(recipe{
                resistance{
                    static_cast<resistance::item_t>(fire * i),
                    static_cast<resistance::item_t>(cold * i),
                    static_cast<resistance::item_t>(lightning * i),
                    static_cast<resistance::item_t>(chaos * i)
                }, 
                static_cast<recipe::cost_t>(instance_cost),
                slot_value
            });
        }
    }
    return result;
}
std :: vector < recap :: recipe > read_recipes ( const std :: string & path ) { using namespace recap ; io :: CSVReader < 8 > input ( path ) ; input . read_header ( io :: ignore_extra_column , " " , " " , " " , " " , " " , " " , " " , " " ) ; std :: vector < recipe > result ; result . push_back ( recipe { resistance { 0 , 0 , 0 , 0 } , 0 , recipe :: SLOT_ALL } ) ; resistance :: item_t fire , cold , lightning , chaos , value_min , value_max ; recipe :: cost_t cost = 0 ; std :: string slot_name ; while ( input . read_row ( fire , cold , lightning , chaos , value_min , value_max , cost , slot_name ) ) { if ( fire > 1 ) { throw invalid_input_error { input . get_file_line ( ) , " " } ; } if ( cold > 1 ) { throw invalid_input_error { input . get_file_line ( ) , " " } ; } if ( lightning > 1 ) { throw invalid_input_error { input . get_file_line ( ) , " " } ; } if ( chaos > 1 ) { throw invalid_input_error { input . get_file_line ( ) , " " } ; } if ( value_min > value_max ) { throw invalid_input_error { input . get_file_line ( ) , " " } ; } recipe :: slot_t slot_value = parse_slot ( slot_name ) ; if ( slot_value == recipe :: SLOT_NONE ) { throw invalid_input_error { input . get_file_line ( ) , " " + slot_name } ; } for ( resistance :: item_t i = value_min ; i <= value_max ; ++ i ) { double instance_cost = cost * ( value_max - value_min + 1.0 ) / ( value_max - i + 1.0 ) ; result . push_back ( recipe { resistance { static_cast < resistance :: item_t > ( fire * i ) , static_cast < resistance :: item_t > ( cold * i ) , static_cast < resistance :: item_t > ( lightning * i ) , static_cast < resistance :: item_t > ( chaos * i ) } , static_cast < recipe :: cost_t > ( instance_cost ) , slot_value } ) ; } } return result ; }
Read recipes from a CSV file located at @p path
Read recipes from a CSV file located at @p path
// read file header // add a null recipe to index 0 // read recipes from file // generate recipes // compute expected cost of rolling these values