mirror of
https://git.zap.org.au/git/trader.git
synced 2025-02-02 15:08:13 -05:00
Implement the --max-turn command line option
This commit is contained in:
parent
fe65657eda
commit
e7208c72db
@ -381,7 +381,7 @@ void init_game (void)
|
||||
|
||||
// Miscellaneous initialisation
|
||||
interest_rate = INITIAL_INTEREST_RATE;
|
||||
max_turn = DEFAULT_MAX_TURN;
|
||||
max_turn = option_max_turn ? option_max_turn : DEFAULT_MAX_TURN;
|
||||
turn_number = 1;
|
||||
|
||||
// Select who is to go first
|
||||
|
@ -86,3 +86,8 @@ bool quit_selected = false; // Is a player trying to quit the game?
|
||||
bool abort_game = false; // Abort game without declaring winner?
|
||||
|
||||
bool option_no_color = false; // True if --no-color was specified
|
||||
int option_max_turn = 0; // Max. turns if --max-turn was specified
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
// End of file
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
#define NUMBER_MOVES 20 // Number of choices on map per turn
|
||||
#define DEFAULT_MAX_TURN 50 // Default number of turns per game
|
||||
#define MIN_MAX_TURN 10 // Minimum that can be specified for max_turn
|
||||
|
||||
#define MAX_PLAYERS 8 // Maximum number of players
|
||||
#define INITIAL_CASH 6000.00 // Initial cash per player
|
||||
@ -197,6 +198,7 @@ extern bool quit_selected; // Is a player trying to quit the game?
|
||||
extern bool abort_game; // Abort game without declaring winner?
|
||||
|
||||
extern bool option_no_color; // True if --no-color was specified
|
||||
extern int option_max_turn; // Max. turns if --max-turn was specified
|
||||
|
||||
|
||||
#endif /* included_GLOBALS_H */
|
||||
|
25
src/trader.c
25
src/trader.c
@ -43,6 +43,7 @@
|
||||
|
||||
enum options_char {
|
||||
OPTION_NO_COLOR = 1,
|
||||
OPTION_MAX_TURN
|
||||
};
|
||||
|
||||
static const char options_short[] = "hV";
|
||||
@ -50,11 +51,12 @@ static const char options_short[] = "hV";
|
||||
// -V, --version
|
||||
|
||||
static struct option const options_long[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "no-color", no_argument, NULL, OPTION_NO_COLOR },
|
||||
{ "no-colour", no_argument, NULL, OPTION_NO_COLOR },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "no-color", no_argument, NULL, OPTION_NO_COLOR },
|
||||
{ "no-colour", no_argument, NULL, OPTION_NO_COLOR },
|
||||
{ "max-turn", required_argument, NULL, OPTION_MAX_TURN },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
|
||||
@ -187,6 +189,8 @@ int main (int argc, char *argv[])
|
||||
void process_cmdline (int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
char *p;
|
||||
|
||||
|
||||
// Process arguments starting with "-" or "--"
|
||||
opterr = true;
|
||||
@ -211,6 +215,17 @@ void process_cmdline (int argc, char *argv[])
|
||||
option_no_color = true;
|
||||
break;
|
||||
|
||||
case OPTION_MAX_TURN:
|
||||
// --max-turn: specify the maximum turn number
|
||||
option_max_turn = strtol(optarg, &p, 10);
|
||||
|
||||
if (option_max_turn < MIN_MAX_TURN || p == NULL || *p != '\0') {
|
||||
fprintf(stderr, "%s: invalid value for --max-turn: `%s'\n",
|
||||
program_name(), optarg);
|
||||
show_usage(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
show_usage(EXIT_FAILURE);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user