Advertisement
Guest User

viande

a guest
Feb 27th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. /*
  2. ** EPITECH PROJECT, 2020
  3. ** navy
  4. ** File description:
  5. ** map
  6. */
  7.  
  8. #include "../include/navy.h"
  9. #include "../include/util.h"
  10.  
  11. void print_map(char *map)
  12. {
  13. int x = 0;
  14.  
  15. my_putstr(" |");
  16. for (char i = 'A'; i <= 'H'; ++i) {
  17. my_putchar(i, 1);
  18. my_putchar(' ' - (22 * (i == 'H')), 1);
  19. }
  20. for (int i = 1; i <= 17; ++i)
  21. my_putchar('-' - (2 * (i == 2)), 1);
  22. my_putchar('\n', 1);
  23. for (int i = 1; i <= 8; ++i) {
  24. my_putchar(48 + i, 1);
  25. my_putchar('|', 1);
  26. for (int j = 1; j <= 8; ++j) {
  27. my_putchar(map[x], 1);
  28. my_putchar(' ' - (22 * (j == 8)), 1);
  29. ++x;
  30. }
  31. }
  32. }
  33.  
  34. void print_maps(map_t *maps)
  35. {
  36. my_putstr("my positions:\n");
  37. print_map(maps->m);
  38. my_putstr("\nenemy's positions:\n");
  39. print_map(maps->e);
  40. my_putchar('\n', 1);
  41. }
  42.  
  43. char *read_map_file(char *path)
  44. {
  45.  
  46. }
  47.  
  48. int fill_map(map_t *map, char *s)
  49. {
  50. int *in = malloc(sizeof(int) * 3);
  51. int x = 0;
  52. char *ln;
  53.  
  54. while ((ln = get_line(s, x++)) != NULL) {
  55. if (ln[2] != ln[5] && ln[3] != ln[6])
  56. return (0);
  57. in[0] = ln[0] - '0';
  58. in[1] = ((ln[3] - 48) * 8) - (8 - (ln[2] - 64)) - 1;
  59. in[2] = ((ln[6] - 48) * 8) - (8 - (ln[5] - 64)) - 1;
  60. if (in[2] - in[1] > 7) {
  61. if (((in[2] - in[1]) / 8) + 1 != in[0])
  62. return (0);
  63. } else if (in[2] - in[1] + 1 != in[0])
  64. return (0);
  65. for (int i = in[1]; i <= in[2]; i += ((in[2] - in[1] > 7) * 7) + 1)
  66. if (map->m[i] == '.')
  67. map->m[i] = (char) (in[0] + '0');
  68. else
  69. return (0);
  70. free(ln);
  71. }
  72. return (1);
  73. }
  74.  
  75. map_t *get_maps(char *path)
  76. {
  77. map_t *map = malloc(sizeof(map_t));
  78. char *s = "8:A1:H1\n2:B2:B3";
  79.  
  80. map->m = malloc(sizeof(char) * 64);
  81. map->e = malloc(sizeof(char) * 64);
  82. for (int i = 0; i < 64; ++i)
  83. map->e[i] = '.';
  84. for (int i = 0; i < 64; ++i)
  85. map->m[i] = '.';
  86. if (fill_map(map, s) == 0)
  87. return (NULL);
  88. return (map);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement