|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include<stlib.h>
|
| 2 |
+
#include<stdio.h>
|
| 3 |
+
|
| 4 |
+
#include"stlib.h"
|
| 5 |
+
|
| 6 |
+
void aff_tab(char * T1, int indx, char *T2){
|
| 7 |
+
T1[0]=T1[indx-1];
|
| 8 |
+
T1[0]=T1[indx];
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
int test(char * T1, char * T2){
|
| 12 |
+
for (int i = 0; i<15 ; ++i){
|
| 13 |
+
if !strcmp(T1, T2[i])
|
| 14 |
+
T2[i]="00";
|
| 15 |
+
return 1;
|
| 16 |
+
}
|
| 17 |
+
return 0;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
int count(char * T_final)
|
| 21 |
+
{
|
| 22 |
+
int c = 0;
|
| 23 |
+
int i = 1;
|
| 24 |
+
char * T_prov = "aa";
|
| 25 |
+
char * T_verif[]={"BG","BO","BV","GB","GO","GV","GG","OB","OO","OV","VB","VG","VO","VV"};
|
| 26 |
+
while (T_final[i]!=0) {
|
| 27 |
+
aff_tab(T_prov, i, T_final);
|
| 28 |
+
if test(T_prov, T_verif)
|
| 29 |
+
++c;
|
| 30 |
+
++i;
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef __DEDALE_DIR_H__
|
| 2 |
+
#define __DEDALE_DIR_H__
|
| 3 |
+
|
| 4 |
+
int count(char * T_final);
|
| 5 |
+
|
| 6 |
+
void aff_tab(char * T1, int indx, char * T2);
|
| 7 |
+
|
| 8 |
+
int test(char * T1, char * T2);
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
#endif //__DEDALE_DIR_H__
|
|
@@ -10,6 +10,7 @@
|
|
| 10 |
void print_usage(const char *program_name) {
|
| 11 |
printf("Usage: %s [options]\n", program_name);
|
| 12 |
printf("Options:\n");
|
|
|
|
| 13 |
printf(" -g Mode graphique \n");
|
| 14 |
printf(" -T Mode texte simplifié \n");
|
| 15 |
printf(" -s SEED Initialiser la graine aléatoire\n");
|
|
@@ -29,8 +30,11 @@ void parse_arguments(int argc, char *argv[], struct game_options_t *options){
|
|
| 29 |
// Réinitialiser optind au cas où getopt a déjà été utilisé
|
| 30 |
optind = 0;
|
| 31 |
|
| 32 |
-
while((opt= getopt(argc, argv, "
|
| 33 |
switch(opt){
|
|
|
|
|
|
|
|
|
|
| 34 |
case 'g': // AJOUTÉ: mode graphique
|
| 35 |
options->use_got = 1;
|
| 36 |
break;
|
|
|
|
| 10 |
void print_usage(const char *program_name) {
|
| 11 |
printf("Usage: %s [options]\n", program_name);
|
| 12 |
printf("Options:\n");
|
| 13 |
+
printf(" -c color mode");
|
| 14 |
printf(" -g Mode graphique \n");
|
| 15 |
printf(" -T Mode texte simplifié \n");
|
| 16 |
printf(" -s SEED Initialiser la graine aléatoire\n");
|
|
|
|
| 30 |
// Réinitialiser optind au cas où getopt a déjà été utilisé
|
| 31 |
optind = 0;
|
| 32 |
|
| 33 |
+
while((opt= getopt(argc, argv, "gTcs:t:n:h"))!= -1){
|
| 34 |
switch(opt){
|
| 35 |
+
case 'c':
|
| 36 |
+
options->color_mode=1;
|
| 37 |
+
break;
|
| 38 |
case 'g': // AJOUTÉ: mode graphique
|
| 39 |
options->use_got = 1;
|
| 40 |
break;
|
|
@@ -182,7 +182,44 @@ int perform_player_movement(struct game_t* game,struct location_t new_loc){
|
|
| 182 |
printf("to (%d,%d) ", new_loc.x, new_loc.y);
|
| 183 |
printf("via %s ", dir_to_string(dir));
|
| 184 |
if(dest_tile && !tile_is_empty(dest_tile)){
|
| 185 |
-
printf("(%s)",tile_name(dest_tile));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
printf("\n");
|
| 188 |
|
|
@@ -233,6 +270,45 @@ int choose_and_perform_action(struct game_t* game){
|
|
| 233 |
}
|
| 234 |
|
| 235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
}
|
| 237 |
|
| 238 |
//Displays the victory message when player reaches the exit.
|
|
|
|
| 182 |
printf("to (%d,%d) ", new_loc.x, new_loc.y);
|
| 183 |
printf("via %s ", dir_to_string(dir));
|
| 184 |
if(dest_tile && !tile_is_empty(dest_tile)){
|
| 185 |
+
printf("(%s)\n",tile_name(dest_tile));
|
| 186 |
+
}
|
| 187 |
+
printf("\n");
|
| 188 |
+
|
| 189 |
+
// execute
|
| 190 |
+
if(game_move_player(game, new_loc)){
|
| 191 |
+
printf(GREEN" Success\n"RESET);
|
| 192 |
+
return 1;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
check_movement_failure(game, new_loc);
|
| 196 |
+
return 0;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
int perform_player_movement_c(struct game_t* game,struct location_t new_loc, char* buffer){
|
| 200 |
+
if(!game) return 0;
|
| 201 |
+
|
| 202 |
+
enum dir_t dir;
|
| 203 |
+
if(new_loc.y > game->p_location.y) dir=NORTH;
|
| 204 |
+
else if(new_loc.y < game->p_location.y) dir=SOUTH;
|
| 205 |
+
else if(new_loc.x > game->p_location.x) dir=EAST;
|
| 206 |
+
else dir=WEST;
|
| 207 |
+
|
| 208 |
+
struct tile_t* dest_tile=manor_get_tile(&game->p_manor,new_loc);
|
| 209 |
+
|
| 210 |
+
//display action
|
| 211 |
+
|
| 212 |
+
// Display action
|
| 213 |
+
printf(BLUE "▶" RESET " ");
|
| 214 |
+
printf(CYAN "Move" RESET " ");
|
| 215 |
+
printf("to (%d,%d) ", new_loc.x, new_loc.y);
|
| 216 |
+
printf("via %s ", dir_to_string(dir));
|
| 217 |
+
if(dest_tile && !tile_is_empty(dest_tile)){
|
| 218 |
+
printf("(%s)\n",tile_name(dest_tile));
|
| 219 |
+
printf("COLOR -%s\n", tile_color(dest_tile));
|
| 220 |
+
buffer = tile_color(dest_tile);
|
| 221 |
+
//printf("%s", buffer);
|
| 222 |
+
|
| 223 |
}
|
| 224 |
printf("\n");
|
| 225 |
|
|
|
|
| 270 |
}
|
| 271 |
|
| 272 |
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
int choose_and_perform_action_colors(struct game_t* game, char* path){
|
| 276 |
+
if(!game) return 0;
|
| 277 |
+
|
| 278 |
+
// get empty adjacent locations
|
| 279 |
+
struct location_t empty_locs[4];
|
| 280 |
+
int empty_count=game_empty_adjacent_locations(game, empty_locs);
|
| 281 |
+
|
| 282 |
+
// get open adjacent locations
|
| 283 |
+
struct location_t open_locs[4];
|
| 284 |
+
int open_count=game_get_open_adjacent_locations(game, open_locs);
|
| 285 |
+
|
| 286 |
+
// calculate total available action
|
| 287 |
+
unsigned int total_actions= empty_count + open_count;
|
| 288 |
+
|
| 289 |
+
if(total_actions==0){
|
| 290 |
+
printf(RED" No possible actions\n"RESET);
|
| 291 |
+
return 0;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
char* buffer;
|
| 295 |
+
// get player random choice
|
| 296 |
+
int choice=get_random_choice(total_actions);
|
| 297 |
+
|
| 298 |
+
if (choice<=empty_count){
|
| 299 |
+
// tile placement action
|
| 300 |
+
struct location_t selected_loc=empty_locs[choice-1];
|
| 301 |
+
return perform_tile_placement(game, selected_loc);
|
| 302 |
+
}else{
|
| 303 |
+
//movement action
|
| 304 |
+
int move_index = choice - empty_count -1 ;
|
| 305 |
+
struct location_t selected_loc= open_locs[move_index];
|
| 306 |
+
return perform_player_movement_c(game, selected_loc, buffer);
|
| 307 |
+
path = buffer;
|
| 308 |
+
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
|
| 312 |
}
|
| 313 |
|
| 314 |
//Displays the victory message when player reaches the exit.
|
|
@@ -12,6 +12,7 @@
|
|
| 12 |
|
| 13 |
|
| 14 |
|
|
|
|
| 15 |
//Performs the action of placing a new tile at the specified location.
|
| 16 |
//Handles tile drafting, selection, placement, and cost payment.
|
| 17 |
int perform_tile_placement(struct game_t* game,struct location_t loc);
|
|
@@ -20,10 +21,13 @@ int perform_tile_placement(struct game_t* game,struct location_t loc);
|
|
| 20 |
//Handles direction calculation, cost payment, and position update.
|
| 21 |
int perform_player_movement(struct game_t* game,struct location_t new_loc);
|
| 22 |
|
|
|
|
| 23 |
// Allows the player to choose and perform an action.
|
| 24 |
//Displays available actions, gets player choice, and executes it.
|
| 25 |
int choose_and_perform_action(struct game_t* game);
|
| 26 |
|
|
|
|
|
|
|
| 27 |
//Displays the victory message when player reaches the exit.
|
| 28 |
void show_victory_message();
|
| 29 |
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
+
|
| 16 |
//Performs the action of placing a new tile at the specified location.
|
| 17 |
//Handles tile drafting, selection, placement, and cost payment.
|
| 18 |
int perform_tile_placement(struct game_t* game,struct location_t loc);
|
|
|
|
| 21 |
//Handles direction calculation, cost payment, and position update.
|
| 22 |
int perform_player_movement(struct game_t* game,struct location_t new_loc);
|
| 23 |
|
| 24 |
+
int perform_player_movement_c(struct game_t* game,struct location_t new_loc,char* buffer);
|
| 25 |
// Allows the player to choose and perform an action.
|
| 26 |
//Displays available actions, gets player choice, and executes it.
|
| 27 |
int choose_and_perform_action(struct game_t* game);
|
| 28 |
|
| 29 |
+
int choose_and_perform_action_colors(struct game_t* game, char* path);
|
| 30 |
+
|
| 31 |
//Displays the victory message when player reaches the exit.
|
| 32 |
void show_victory_message();
|
| 33 |
|
|
@@ -77,7 +77,7 @@ void game_loop_text(struct game_t *game,unsigned int max_turns){
|
|
| 77 |
printf("=== DÉBUT DE LA PARTIE ===\n");
|
| 78 |
printf("Manoir: %dx%d, \n", BOARD_WIDTH, BOARD_HEIGHT);
|
| 79 |
printf("Position départ: (%d,%d)\n", manor_get_startloc().x, manor_get_startloc().y);
|
| 80 |
-
printf("Position sortie: (%d,%d)\n
|
| 81 |
|
| 82 |
while (1) {
|
| 83 |
printf("=== TOUR %d/%d ===\n", game->current_turn + 1, max_turns);
|
|
@@ -100,6 +100,7 @@ void game_loop_text(struct game_t *game,unsigned int max_turns){
|
|
| 100 |
if (exit_reached(game)) {
|
| 101 |
printf("\n=== VICTOIRE ===\n");
|
| 102 |
printf("Le joueur a atteint la sortie en %d tours!\n", game->current_turn);
|
|
|
|
| 103 |
break;
|
| 104 |
}
|
| 105 |
|
|
@@ -260,6 +261,208 @@ void game_loop_text(struct game_t *game,unsigned int max_turns){
|
|
| 260 |
// Légende
|
| 261 |
printf("\nLégende P=YOU S=START E=EXIT C=CLOISTER T=TERRACE NS=CORRIDOR_NS WE=CORRIDOR_WE .=EMPTY\n");
|
| 262 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
void game_loop(struct game_options_t options){
|
| 265 |
// initialiser le générateur aléatoire
|
|
@@ -274,6 +477,9 @@ void game_loop(struct game_options_t options){
|
|
| 274 |
if (options.use_got){
|
| 275 |
game_loop_g(&game, options.max_turns);
|
| 276 |
}else{
|
|
|
|
|
|
|
|
|
|
| 277 |
game_loop_text(&game, options.max_turns);
|
| 278 |
}
|
| 279 |
|
|
|
|
| 77 |
printf("=== DÉBUT DE LA PARTIE ===\n");
|
| 78 |
printf("Manoir: %dx%d, \n", BOARD_WIDTH, BOARD_HEIGHT);
|
| 79 |
printf("Position départ: (%d,%d)\n", manor_get_startloc().x, manor_get_startloc().y);
|
| 80 |
+
printf("Position sortie: (%d,%d)\n", manor_get_exitloc().x, manor_get_exitloc().y);
|
| 81 |
|
| 82 |
while (1) {
|
| 83 |
printf("=== TOUR %d/%d ===\n", game->current_turn + 1, max_turns);
|
|
|
|
| 100 |
if (exit_reached(game)) {
|
| 101 |
printf("\n=== VICTOIRE ===\n");
|
| 102 |
printf("Le joueur a atteint la sortie en %d tours!\n", game->current_turn);
|
| 103 |
+
|
| 104 |
break;
|
| 105 |
}
|
| 106 |
|
|
|
|
| 261 |
// Légende
|
| 262 |
printf("\nLégende P=YOU S=START E=EXIT C=CLOISTER T=TERRACE NS=CORRIDOR_NS WE=CORRIDOR_WE .=EMPTY\n");
|
| 263 |
}
|
| 264 |
+
// version avec couleurs
|
| 265 |
+
void game_loop_text_colors(struct game_t *game,unsigned int max_turns){
|
| 266 |
+
|
| 267 |
+
/*char buffer[max_turns];
|
| 268 |
+
buffer[0]='B';
|
| 269 |
+
int i=1;*/
|
| 270 |
+
printf("=== DÉBUT DE LA PARTIE ===\n");
|
| 271 |
+
printf("Manoir: %dx%d, \n", BOARD_WIDTH, BOARD_HEIGHT);
|
| 272 |
+
printf("Position départ: (%d,%d)\n", manor_get_startloc().x, manor_get_startloc().y);
|
| 273 |
+
printf("Position sortie: (%d,%d)\n", manor_get_exitloc().x, manor_get_exitloc().y);
|
| 274 |
+
printf("COLOR -B\n");
|
| 275 |
+
|
| 276 |
+
while (1) {
|
| 277 |
+
|
| 278 |
+
printf("=== TOUR %d/%d ===\n", game->current_turn + 1, max_turns);
|
| 279 |
+
printf("Position joueur: (%d,%d)\n", game->p_location.x, game->p_location.y);
|
| 280 |
+
|
| 281 |
+
// Afficher les ressources
|
| 282 |
+
printf("Ressources: ");
|
| 283 |
+
int first = 1;
|
| 284 |
+
for (int i = STEP; i <= NUM_RESOURCES; i++) {
|
| 285 |
+
if (game->p_stash.r[i] > 0 && game->p_stash.r[i] != UINT_MAX) {
|
| 286 |
+
if (!first) printf(", ");
|
| 287 |
+
printf("%s:%u", resource_to_string(i), game->p_stash.r[i]);
|
| 288 |
+
first = 0;
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
if (first) printf("aucune");
|
| 292 |
+
printf("\n");
|
| 293 |
+
|
| 294 |
+
// Vérifier la victoire
|
| 295 |
+
if (exit_reached(game)) {
|
| 296 |
+
printf("\n=== VICTOIRE ===\n");
|
| 297 |
+
printf("Le joueur a atteint la sortie en %d tours!\n", game->current_turn);
|
| 298 |
+
printf("COLOR -B\n\n");
|
| 299 |
+
|
| 300 |
+
break;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// Vérifier la défaite
|
| 304 |
+
if (game->current_turn >= max_turns) {
|
| 305 |
+
printf("\n=== DÉFAITE ===\n");
|
| 306 |
+
printf("Limite de tours atteinte (%d)\n", max_turns);
|
| 307 |
+
break;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
// Vérifier les ressources
|
| 311 |
+
int has_resources = 0;
|
| 312 |
+
for (int i = STEP; i <= NUM_RESOURCES; i++) {
|
| 313 |
+
if (game->p_stash.r[i] > 0) {
|
| 314 |
+
has_resources = 1;
|
| 315 |
+
break;
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
if (!has_resources) {
|
| 320 |
+
printf("\n=== DÉFAITE ===\n");
|
| 321 |
+
printf("Plus de ressources disponibles\n");
|
| 322 |
+
break;
|
| 323 |
+
}
|
| 324 |
+
char* path;
|
| 325 |
+
// Effectuer une action
|
| 326 |
+
printf("\nAction: ");
|
| 327 |
+
if (!choose_and_perform_action_colors(game, path)){
|
| 328 |
+
printf("\n=== DÉFAITE ===\n");
|
| 329 |
+
printf("Aucune action possible\n");
|
| 330 |
+
break;
|
| 331 |
+
}
|
| 332 |
+
/*buffer[i] = *path;
|
| 333 |
+
printf("%s", buffer[i]);
|
| 334 |
+
i++;*/
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
game->current_turn++;
|
| 339 |
+
printf("\n");
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
// Afficher le manoir final (identique à la version graphique)
|
| 344 |
+
printf("\n=== ÉTAT FINAL DU MANOIR ===\n");
|
| 345 |
+
|
| 346 |
+
// coordonnées x
|
| 347 |
+
printf(" ");
|
| 348 |
+
for(int x=0; x<BOARD_WIDTH; x++){
|
| 349 |
+
printf(" %d ", x);
|
| 350 |
+
}
|
| 351 |
+
printf("\n");
|
| 352 |
+
|
| 353 |
+
// bordure supérieure
|
| 354 |
+
printf(" ┌");
|
| 355 |
+
for (int x = 0; x < BOARD_WIDTH; x++) {
|
| 356 |
+
printf("─────");
|
| 357 |
+
if (x < BOARD_WIDTH - 1) printf("┬");
|
| 358 |
+
}
|
| 359 |
+
printf("┐\n");
|
| 360 |
+
|
| 361 |
+
//Grille
|
| 362 |
+
for (int y=BOARD_HEIGHT-1; y>=0; y-- ){
|
| 363 |
+
printf("%2d │", y); // Row number with left border
|
| 364 |
+
|
| 365 |
+
for(int x=0;x<BOARD_WIDTH;x++){
|
| 366 |
+
struct location_t loc={x, y};
|
| 367 |
+
struct tile_t* tile=manor_get_tile(&game->p_manor, loc);
|
| 368 |
+
|
| 369 |
+
// POUR LES SYMBOLES DE 3 CARATÈRES (N_S ET W_E)
|
| 370 |
+
char symbol[4];
|
| 371 |
+
symbol[0] = ' ';
|
| 372 |
+
symbol[1] = ' ';
|
| 373 |
+
symbol[2] = ' ';
|
| 374 |
+
symbol[3] = '\0'; // Default empty symbol
|
| 375 |
+
|
| 376 |
+
if(location_equal(loc,game->p_location)){
|
| 377 |
+
symbol[0] = ' ';
|
| 378 |
+
symbol[1]= 'P';
|
| 379 |
+
symbol[2] = ' ';
|
| 380 |
+
symbol[3] = '\0';
|
| 381 |
+
} else if (location_equal(loc, manor_get_startloc())) {
|
| 382 |
+
symbol[0] = ' ';
|
| 383 |
+
symbol[1]= 'S';
|
| 384 |
+
symbol[2] = ' ';
|
| 385 |
+
symbol[3] = '\0';
|
| 386 |
+
} else if (location_equal(loc, manor_get_exitloc())) {
|
| 387 |
+
symbol[0] = ' ';
|
| 388 |
+
symbol[1]= 'E';
|
| 389 |
+
symbol[2] = ' ';
|
| 390 |
+
symbol[3] = '\0';
|
| 391 |
+
} else if (tile && !tile_is_empty(tile)) {
|
| 392 |
+
const char* name = tile_name(tile);
|
| 393 |
+
if (name){
|
| 394 |
+
if(strcmp(name,"Cloister")==0){
|
| 395 |
+
symbol[0] = ' ';
|
| 396 |
+
symbol[1]= 'C';
|
| 397 |
+
symbol[2] = ' ';
|
| 398 |
+
symbol[3] = '\0';
|
| 399 |
+
}else if (strcmp(name,"Terrace")==0){
|
| 400 |
+
symbol[0] = ' ';
|
| 401 |
+
symbol[1]= 'T';
|
| 402 |
+
symbol[2] = ' ';
|
| 403 |
+
symbol[3] = '\0';
|
| 404 |
+
}else if (strcmp(name,"Corridor_NS")==0){
|
| 405 |
+
symbol[0]= 'N';
|
| 406 |
+
symbol[1]= 'S';
|
| 407 |
+
symbol[2]= ' ';
|
| 408 |
+
symbol[3] = '\0';
|
| 409 |
+
}else if (strcmp(name,"Corridor_WE")==0){
|
| 410 |
+
symbol[0]= 'W';
|
| 411 |
+
symbol[1]= 'E';
|
| 412 |
+
symbol[2]= ' ';
|
| 413 |
+
symbol[3] = '\0';
|
| 414 |
+
}else if (strcmp(name,"start")==0){
|
| 415 |
+
symbol[0] = ' ';
|
| 416 |
+
symbol[1]= 'S';
|
| 417 |
+
symbol[2] = ' ';
|
| 418 |
+
symbol[3] = '\0';
|
| 419 |
+
}else if (strcmp(name,"exit")==0){
|
| 420 |
+
symbol[0] = ' ';
|
| 421 |
+
symbol[1]= 'E';
|
| 422 |
+
symbol[2] = ' ';
|
| 423 |
+
symbol[3] = '\0';
|
| 424 |
+
}else{
|
| 425 |
+
symbol[0] = ' ';
|
| 426 |
+
symbol[1] = name[0];
|
| 427 |
+
symbol[2] = ' ';
|
| 428 |
+
symbol[3] = '\0';
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
} else {
|
| 432 |
+
symbol[0] = ' ';
|
| 433 |
+
symbol[1] = '.';
|
| 434 |
+
symbol[2] = ' ';
|
| 435 |
+
symbol[3] = '\0';
|
| 436 |
+
}
|
| 437 |
+
// Print the cell without colors
|
| 438 |
+
printf("%s", symbol);
|
| 439 |
+
if (x < BOARD_WIDTH - 1) printf(" │"); // Column separator
|
| 440 |
+
}
|
| 441 |
+
printf(" │\n"); // Right border
|
| 442 |
+
|
| 443 |
+
// Draw horizontal separators between rows (except after last row)
|
| 444 |
+
if (y > 0) {
|
| 445 |
+
printf(" ├");
|
| 446 |
+
for (int x = 0; x < BOARD_WIDTH; x++) {
|
| 447 |
+
printf("─────");
|
| 448 |
+
if (x < BOARD_WIDTH - 1) printf("┼");
|
| 449 |
+
}
|
| 450 |
+
printf("┤\n");
|
| 451 |
+
}
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
// Draw bottom border of the grid
|
| 455 |
+
printf(" └");
|
| 456 |
+
for (int x = 0; x < BOARD_WIDTH; x++) {
|
| 457 |
+
printf("─────");
|
| 458 |
+
if (x < BOARD_WIDTH - 1) printf("┴");
|
| 459 |
+
}
|
| 460 |
+
printf("┘\n");
|
| 461 |
+
|
| 462 |
+
printf("COLOR : score=");
|
| 463 |
+
// Légende
|
| 464 |
+
printf("\nLégende P=YOU S=START E=EXIT C=CLOISTER T=TERRACE NS=CORRIDOR_NS WE=CORRIDOR_WE .=EMPTY\n");
|
| 465 |
+
}
|
| 466 |
|
| 467 |
void game_loop(struct game_options_t options){
|
| 468 |
// initialiser le générateur aléatoire
|
|
|
|
| 477 |
if (options.use_got){
|
| 478 |
game_loop_g(&game, options.max_turns);
|
| 479 |
}else{
|
| 480 |
+
if(options.color_mode){
|
| 481 |
+
game_loop_text_colors(&game,options.max_turns);
|
| 482 |
+
}
|
| 483 |
game_loop_text(&game, options.max_turns);
|
| 484 |
}
|
| 485 |
|
|
@@ -10,6 +10,7 @@ struct game_options_t{
|
|
| 10 |
unsigned int seed; // graine aléatoire
|
| 11 |
unsigned int tile_seed; // grine pour init_tiles
|
| 12 |
unsigned int max_turns; // nombre maximum de turns
|
|
|
|
| 13 |
};
|
| 14 |
|
| 15 |
void game_loop(struct game_options_t);
|
|
|
|
| 10 |
unsigned int seed; // graine aléatoire
|
| 11 |
unsigned int tile_seed; // grine pour init_tiles
|
| 12 |
unsigned int max_turns; // nombre maximum de turns
|
| 13 |
+
int color_mode;
|
| 14 |
};
|
| 15 |
|
| 16 |
void game_loop(struct game_options_t);
|
|
@@ -14,6 +14,7 @@ struct tile_t {
|
|
| 14 |
struct stash_t cost_thrgh;
|
| 15 |
struct stash_t cost_op[4];
|
| 16 |
int weight;
|
|
|
|
| 17 |
};
|
| 18 |
|
| 19 |
static struct tile_t empty_tile ={
|
|
@@ -27,14 +28,16 @@ static struct tile_t start_tile ={
|
|
| 27 |
.name = "start",
|
| 28 |
.cost_thrgh= ONE_STEP_STASH ,
|
| 29 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=ONE_STEP_STASH ,[SOUTH]=ONE_STEP_STASH , [WEST]=ONE_STEP_STASH },
|
| 30 |
-
.weight=0
|
|
|
|
| 31 |
};
|
| 32 |
|
| 33 |
static struct tile_t exit_tile ={
|
| 34 |
.name = "exit",
|
| 35 |
.cost_thrgh= ONE_STEP_STASH ,
|
| 36 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=ONE_STEP_STASH ,[SOUTH]=ONE_STEP_STASH , [WEST]=ONE_STEP_STASH },
|
| 37 |
-
.weight=0
|
|
|
|
| 38 |
};
|
| 39 |
|
| 40 |
|
|
@@ -42,28 +45,32 @@ static struct tile_t Corridor_NS={
|
|
| 42 |
.name = "Corridor_NS",
|
| 43 |
.cost_thrgh = ONE_STEP_STASH,
|
| 44 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=INFINITE_STEP_STASH, [SOUTH]=ONE_STEP_STASH , [WEST]=INFINITE_STEP_STASH },
|
| 45 |
-
.weight=1
|
|
|
|
| 46 |
};
|
| 47 |
|
| 48 |
static struct tile_t Corridor_WE={
|
| 49 |
.name = "Corridor_WE",
|
| 50 |
.cost_thrgh = ONE_STEP_STASH,
|
| 51 |
.cost_op = {[NORTH]=INFINITE_STEP_STASH, [EAST]=ONE_STEP_STASH ,[SOUTH]=INFINITE_STEP_STASH , [WEST]=ONE_STEP_STASH },
|
| 52 |
-
.weight=1
|
|
|
|
| 53 |
};
|
| 54 |
|
| 55 |
static struct tile_t Terrace={
|
| 56 |
.name = "Terrace",
|
| 57 |
.cost_thrgh = ONE_STEP_STASH,
|
| 58 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=INFINITE_STEP_STASH ,[SOUTH]=INFINITE_STEP_STASH , [WEST]=INFINITE_STEP_STASH },
|
| 59 |
-
.weight=1
|
|
|
|
| 60 |
};
|
| 61 |
|
| 62 |
static struct tile_t Cloister={
|
| 63 |
.name = "Cloister",
|
| 64 |
.cost_thrgh = ONE_STEP_STASH,
|
| 65 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=ONE_STEP_STASH ,[SOUTH]=ONE_STEP_STASH , [WEST]=ONE_STEP_STASH },
|
| 66 |
-
.weight=2
|
|
|
|
| 67 |
};
|
| 68 |
|
| 69 |
static struct tile_t * available_tiles[]={
|
|
@@ -243,3 +250,8 @@ int tile_can_open(const struct tile_t* tile, enum dir_t d){
|
|
| 243 |
struct stash_t empty = EMPTY_STASH;
|
| 244 |
return !stash_contains(&empty,&cost);
|
| 245 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
struct stash_t cost_thrgh;
|
| 15 |
struct stash_t cost_op[4];
|
| 16 |
int weight;
|
| 17 |
+
char color[4];
|
| 18 |
};
|
| 19 |
|
| 20 |
static struct tile_t empty_tile ={
|
|
|
|
| 28 |
.name = "start",
|
| 29 |
.cost_thrgh= ONE_STEP_STASH ,
|
| 30 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=ONE_STEP_STASH ,[SOUTH]=ONE_STEP_STASH , [WEST]=ONE_STEP_STASH },
|
| 31 |
+
.weight=0,
|
| 32 |
+
.color="B"
|
| 33 |
};
|
| 34 |
|
| 35 |
static struct tile_t exit_tile ={
|
| 36 |
.name = "exit",
|
| 37 |
.cost_thrgh= ONE_STEP_STASH ,
|
| 38 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=ONE_STEP_STASH ,[SOUTH]=ONE_STEP_STASH , [WEST]=ONE_STEP_STASH },
|
| 39 |
+
.weight=0,
|
| 40 |
+
.color="B"
|
| 41 |
};
|
| 42 |
|
| 43 |
|
|
|
|
| 45 |
.name = "Corridor_NS",
|
| 46 |
.cost_thrgh = ONE_STEP_STASH,
|
| 47 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=INFINITE_STEP_STASH, [SOUTH]=ONE_STEP_STASH , [WEST]=INFINITE_STEP_STASH },
|
| 48 |
+
.weight=1,
|
| 49 |
+
.color="V"
|
| 50 |
};
|
| 51 |
|
| 52 |
static struct tile_t Corridor_WE={
|
| 53 |
.name = "Corridor_WE",
|
| 54 |
.cost_thrgh = ONE_STEP_STASH,
|
| 55 |
.cost_op = {[NORTH]=INFINITE_STEP_STASH, [EAST]=ONE_STEP_STASH ,[SOUTH]=INFINITE_STEP_STASH , [WEST]=ONE_STEP_STASH },
|
| 56 |
+
.weight=1,
|
| 57 |
+
.color="V"
|
| 58 |
};
|
| 59 |
|
| 60 |
static struct tile_t Terrace={
|
| 61 |
.name = "Terrace",
|
| 62 |
.cost_thrgh = ONE_STEP_STASH,
|
| 63 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=INFINITE_STEP_STASH ,[SOUTH]=INFINITE_STEP_STASH , [WEST]=INFINITE_STEP_STASH },
|
| 64 |
+
.weight=1,
|
| 65 |
+
.color="G"
|
| 66 |
};
|
| 67 |
|
| 68 |
static struct tile_t Cloister={
|
| 69 |
.name = "Cloister",
|
| 70 |
.cost_thrgh = ONE_STEP_STASH,
|
| 71 |
.cost_op = {[NORTH]=ONE_STEP_STASH , [EAST]=ONE_STEP_STASH ,[SOUTH]=ONE_STEP_STASH , [WEST]=ONE_STEP_STASH },
|
| 72 |
+
.weight=2,
|
| 73 |
+
.color="O"
|
| 74 |
};
|
| 75 |
|
| 76 |
static struct tile_t * available_tiles[]={
|
|
|
|
| 250 |
struct stash_t empty = EMPTY_STASH;
|
| 251 |
return !stash_contains(&empty,&cost);
|
| 252 |
}
|
| 253 |
+
|
| 254 |
+
char* tile_color(struct tile_t *tile){
|
| 255 |
+
if (tile==NULL) return "NULL";
|
| 256 |
+
return tile->color;
|
| 257 |
+
}
|
|
@@ -69,4 +69,5 @@ int tile_is_empty(const struct tile_t* tile);
|
|
| 69 |
* opening cost in the direction `d`. */
|
| 70 |
int tile_can_open(const struct tile_t* tile, enum dir_t d);
|
| 71 |
|
|
|
|
| 72 |
#endif // __DEDALE_TILE_H__
|
|
|
|
| 69 |
* opening cost in the direction `d`. */
|
| 70 |
int tile_can_open(const struct tile_t* tile, enum dir_t d);
|
| 71 |
|
| 72 |
+
char* tile_color(struct tile_t *tile);
|
| 73 |
#endif // __DEDALE_TILE_H__
|