Advertisement
Guest User

JellyRekt

a guest
Nov 13th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.34 KB | None | 0 0
  1. Node* get_possible_moves(char G[8][8], int do_black) {
  2.     fprintf(logfile, "Call to get_possible_moves(%s)\nConfiguration:\n", do_black ? "black" : "red");
  3.     print_board(logfile, G);
  4.     Node* result = NULL;
  5.     for (int col = 0; col < 8; col++) {
  6.         for (int row = 7; row >= 0; row--) {
  7.             // Check for piece
  8.             fprintf(logfile, "get_possible_moves: Checking %c%c... ", ctoc(col), rtoc(row));
  9.             if (do_black && !is_black(G, row, col) || !do_black && !is_red(G, row, col)) {
  10.                 fprintf(logfile, "No %s piece; continue.\n", do_black ? "black" : "red");
  11.                 continue;
  12.             }
  13.             fprintf(logfile, "%s piece found.\n", do_black ? "black" : "red");
  14.             print_board(logfile, G);
  15.             fflush(logfile);
  16.             // Check left 2 down 2
  17.             if (move_possible(G, row, col, 2, -2)) {
  18.                 char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col - 2), rtoc(row + 2), 0 };
  19.                 fprintf(logfile, "Possible. Adding %s\n", move);
  20.                 result = movelist_add(result, move);
  21.             } else {
  22.                 fprintf(logfile, "Not possible.\n");
  23.             }
  24.             fflush(logfile);
  25.             // Check left 2 up 2
  26.             if (move_possible(G, row, col, -2, -2)) {
  27.                 char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col - 2), rtoc(row - 2), 0 };
  28.                 fprintf(logfile, "Possible. Adding %s\n", move);
  29.                 result = movelist_add(result, move);
  30.             } else {
  31.                 fprintf(logfile, "Not possible.\n");
  32.             }
  33.             fflush(logfile);
  34.             // Check left 1 down 1
  35.             if (move_possible(G, row, col, 1, -1)) {
  36.                 char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col - 1), rtoc(row + 1), 0 };
  37.                 fprintf(logfile, "Possible. Adding %s\n", move);
  38.                 result = movelist_add(result, move);
  39.             } else {
  40.                 fprintf(logfile, "Not possible.\n");
  41.             }
  42.             fflush(logfile);
  43.             // Check left 1 up 1
  44.             if (move_possible(G, row, col, -1, -1)) {
  45.                 char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col - 1), rtoc(row - 1), 0 };
  46.                 fprintf(logfile, "Possible. Adding %s\n", move);
  47.                 result = movelist_add(result, move);
  48.             } else {
  49.                 fprintf(logfile, "Not possible.\n");
  50.             }
  51.             fflush(logfile);
  52.             // Check right 1 down 1
  53.             if (move_possible(G, row, col, 1, 1)) {
  54.                 char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col + 1), rtoc(row + 1), 0 };
  55.                 fprintf(logfile, "Possible. Adding %s\n", move);
  56.                 result = movelist_add(result, move);
  57.             } else {
  58.                 fprintf(logfile, "Not possible.\n");
  59.             }
  60.             fflush(logfile);
  61.             // Check right 1 up 1
  62.             if (move_possible(G, row, col, -1, 1)) {
  63.                 char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col + 1), rtoc(row - 1), 0 };
  64.                 fprintf(logfile, "Possible. Adding %s\n", move);
  65.                 result = movelist_add(result, move);
  66.             } else {
  67.                 fprintf(logfile, "Not possible.\n");
  68.             }
  69.             fflush(logfile);
  70.             // Check right 2 down 2
  71.             if (move_possible(G, row, col, 2, 2)) {
  72.                 char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col + 2), rtoc(row + 2), 0 };
  73.                 fprintf(logfile, "Possible. Adding %s\n", move);
  74.                 result = movelist_add(result, move);
  75.             } else {
  76.                 fprintf(logfile, "Not possible.\n");
  77.             }
  78.             fflush(logfile);
  79.             // Check right 2 up 2
  80.             if (move_possible(G, row, col, -2, 2)) {
  81.                 char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col + 2), rtoc(row - 2), 0 };
  82.                 fprintf(logfile, "Possible. Adding %s\n", move);
  83.                 result = movelist_add(result, move);
  84.             } else {
  85.                 fprintf(logfile, "Not possible.\n");
  86.             }
  87.             fflush(logfile);
  88.         }
  89.     }
  90.     return result;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement