Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node* get_possible_moves(char G[8][8], int do_black) {
- fprintf(logfile, "Call to get_possible_moves(%s)\nConfiguration:\n", do_black ? "black" : "red");
- print_board(logfile, G);
- Node* result = NULL;
- for (int col = 0; col < 8; col++) {
- for (int row = 7; row >= 0; row--) {
- // Check for piece
- fprintf(logfile, "get_possible_moves: Checking %c%c... ", ctoc(col), rtoc(row));
- if (do_black && !is_black(G, row, col) || !do_black && !is_red(G, row, col)) {
- fprintf(logfile, "No %s piece; continue.\n", do_black ? "black" : "red");
- continue;
- }
- fprintf(logfile, "%s piece found.\n", do_black ? "black" : "red");
- print_board(logfile, G);
- fflush(logfile);
- // Check left 2 down 2
- if (move_possible(G, row, col, 2, -2)) {
- char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col - 2), rtoc(row + 2), 0 };
- fprintf(logfile, "Possible. Adding %s\n", move);
- result = movelist_add(result, move);
- } else {
- fprintf(logfile, "Not possible.\n");
- }
- fflush(logfile);
- // Check left 2 up 2
- if (move_possible(G, row, col, -2, -2)) {
- char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col - 2), rtoc(row - 2), 0 };
- fprintf(logfile, "Possible. Adding %s\n", move);
- result = movelist_add(result, move);
- } else {
- fprintf(logfile, "Not possible.\n");
- }
- fflush(logfile);
- // Check left 1 down 1
- if (move_possible(G, row, col, 1, -1)) {
- char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col - 1), rtoc(row + 1), 0 };
- fprintf(logfile, "Possible. Adding %s\n", move);
- result = movelist_add(result, move);
- } else {
- fprintf(logfile, "Not possible.\n");
- }
- fflush(logfile);
- // Check left 1 up 1
- if (move_possible(G, row, col, -1, -1)) {
- char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col - 1), rtoc(row - 1), 0 };
- fprintf(logfile, "Possible. Adding %s\n", move);
- result = movelist_add(result, move);
- } else {
- fprintf(logfile, "Not possible.\n");
- }
- fflush(logfile);
- // Check right 1 down 1
- if (move_possible(G, row, col, 1, 1)) {
- char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col + 1), rtoc(row + 1), 0 };
- fprintf(logfile, "Possible. Adding %s\n", move);
- result = movelist_add(result, move);
- } else {
- fprintf(logfile, "Not possible.\n");
- }
- fflush(logfile);
- // Check right 1 up 1
- if (move_possible(G, row, col, -1, 1)) {
- char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col + 1), rtoc(row - 1), 0 };
- fprintf(logfile, "Possible. Adding %s\n", move);
- result = movelist_add(result, move);
- } else {
- fprintf(logfile, "Not possible.\n");
- }
- fflush(logfile);
- // Check right 2 down 2
- if (move_possible(G, row, col, 2, 2)) {
- char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col + 2), rtoc(row + 2), 0 };
- fprintf(logfile, "Possible. Adding %s\n", move);
- result = movelist_add(result, move);
- } else {
- fprintf(logfile, "Not possible.\n");
- }
- fflush(logfile);
- // Check right 2 up 2
- if (move_possible(G, row, col, -2, 2)) {
- char move[] = { ctoc(col), rtoc(row), '-', '>', ctoc(col + 2), rtoc(row - 2), 0 };
- fprintf(logfile, "Possible. Adding %s\n", move);
- result = movelist_add(result, move);
- } else {
- fprintf(logfile, "Not possible.\n");
- }
- fflush(logfile);
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement