/** * Init the players, between 2 and nb_max_players * * @return void */ void game_select_players(s_board *b, s_player *players, const uint8_t nb_max_players, const uint16_t nb_pawns_per_player) { int p; p = 0; char player_name[PLAYER_NAME_LEN]; char name_prompt[19], names_informations[96]; sprintf(names_informations, "Please select between 2 and %d players.\n\ Validate an empty name when you have enough players.", nb_max_players); ui_info(names_informations); while (p < nb_max_players) { // @TODO loop on each player, ask if the player is an AI or a human // @TODO ask for the player name and the strategy if AI sprintf(name_prompt, "Name of player %d: ", p+1); ui_prompt(name_prompt, player_name, (size_t) PLAYER_NAME_LEN); if (strlen(player_name) > 0) { init_player(&players[p], p+1, player_name, 1, STRATEGY_NONE, nb_pawns_per_player); board_add_player(b, &players[p]); p++; } else if (p >= 2) { break; } } }
// Process a line. static void ui_command(char *cmd) { char *tok; MyTime tm = MyTime(); int n = 1, incHr = 1; int phaseOff, d, u, tmp; myflush(); myprintln(); switch (cmd[0]) { case 'M': tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) { n = 10; } else { n = in_range(1, 200, atoi(tok)); } moon_halfTable(n); break; case 'C': phase_calibrate(); break; case '!': error_mess = NULL; PHASE_BROKEN = false; TILT_BROKEN =false; BREAK = false; servo_retry_count = 0; break; case 'H': phase_halt(); RUNNING = false; break; case 'T': // tilt override. tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; ui_tilt = in_range(-80, 80, atoi(tok)); if (RUNNING) myprintf(F("*!* Halt system to take effect \n")); break; case 'D': { MyTime t1; if (t1.parseStr(&cmd[2])) { t1.writeRTC(); delay(1500); MyTime t2 = MyTime(); t2.print(F("\n check me : ")); myprintln(); } else { myprintf(F(" Error in date time input \n")); } } break; case 'P': // phase tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; ui_phase = in_range(-180, 180, atoi(tok)); if (RUNNING) myprintf(F("*!* Halt system to take effect \n")); else phase_set(ui_phase); break; case 'O': // phase offset tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; phaseOff = in_range(-360, 360, atoi(tok)); phase_setOffset(phaseOff); if (!RUNNING) phase_set(ui_phase); break; case 't': tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; d = in_range(SERVO_MIN, SERVO_MID, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; u = in_range(SERVO_MID, SERVO_MAX, atoi(tok)); tilt_setLimits(d, u); break; case 'p': tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; tilt_parity = atoi(tok) ; break; case 'S': tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; mytime_setSpeed(in_range(-100, 100, atoi(tok))); RUNNING=true; break; case 'W': eeprom_write(); break; case 'R': BREAK = false; RUNNING = true; error_mess = NULL; mytime_setSpeed(0); break; case '?': ui_welcome(); break; case 'L': { int Minute = tm.getMinute(); int Second = tm.getSecond(); int Year = tm.getYear(); int Month = tm.getMonth(); int Day = tm.getDay(); int Hour = tm.getHour(); tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; n = in_range(1, 200, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; incHr = in_range(1, 366 * 24, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Year = in_range(2016, 2200, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Month = in_range(1, 12, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Day = in_range(1, mytime_daysInMonth(Month, Year), atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Hour = in_range(0, 23, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Minute = in_range(0, 59, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Second = in_range(0, 59, atoi(tok)); OK2: MyTime tt = MyTime(Year, Month, Day, Hour, Minute, Second); moon_printTable(tt, n, incHr); } break; } ui_prompt(); return; INVALID: myprintf(F("\n Command error \n>"), cmd); ui_prompt(); return; }