Skip to content
Snippets Groups Projects
util.h 809 B
Newer Older
#ifndef UTIL_H
#define UTIL_H

#include <stdint.h>

#define max(x, y) ({ \
	typeof (x) _x = x; \
	typeof (y) _y = y; \
	_x > _y ? _x : _y; \
})

#define min(x, y) ({ \
	typeof (x) _x = x; \
	typeof (y) _y = y; \
	_x < _y ? _x : _y; \
})

/**
 * Generate a random number between min and max, inclusive
**/
int randrange(int min, int max);

/**
 * Probability generator
 */
int randchance(double prob);

/**
 * Returns the sign of a number
 * Or zero if the input is zero
 */
int sign(int x);

class args {
 public:
	int load;
	int save;
	int seed;
	int nummon;
class position {
 public:

/**
 * Parses command line arguments
 * Provides default values for arguments that do not exist
 */
void parse_args(int argc, char *argv[], args *args);
void print_args(args *args);