From 3de177458e8ca38cdae100f8bf5d6d75bcce0d14 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 12 Mar 2018 13:55:19 +0100 Subject: Fix bishop movement --- board.cpp | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/board.cpp b/board.cpp index 69a7094..5425d7b 100644 --- a/board.cpp +++ b/board.cpp @@ -160,33 +160,41 @@ vector Board::subsequents() const { break; case BISHOP: - for (int i2 = i - 9; i2 >= 0; i2 -= 9) { - if (at(i2) == EMPTY || colour(at(i2)) != clr) { - subs.push_back(newWith(SHIFTER(i, i2))); + if (i % 8 != 0) { + for (int i2 = i - 9; i2 >= 0; i2 -= 9) { + if (at(i2) == EMPTY || colour(at(i2)) != clr) { + subs.push_back(newWith(SHIFTER(i, i2))); + } + if (at(i2) != EMPTY) break; + if (i2 % 8 == 0) break; } - if (at(i2) != EMPTY) break; - if (i2 % 8 == 0) break; } - for (int i2 = i - 7; i2 >= 0; i2 -= 7) { - if (at(i2) == EMPTY || colour(at(i2)) != clr) { - subs.push_back(newWith(SHIFTER(i, i2))); + if (i % 8 != 7) { + for (int i2 = i - 7; i2 >= 0; i2 -= 7) { + if (at(i2) == EMPTY || colour(at(i2)) != clr) { + subs.push_back(newWith(SHIFTER(i, i2))); + } + if (at(i2) != EMPTY) break; + if (i2 % 8 == 7) break; } - if (at(i2) != EMPTY) break; - if (i2 % 8 == 7) break; } - for (int i2 = i + 7; i2 < 64; i2 += 7) { - if (at(i2) == EMPTY || colour(at(i2)) != clr) { - subs.push_back(newWith(SHIFTER(i, i2))); + if (i % 8 != 0) { + for (int i2 = i + 7; i2 < 64; i2 += 7) { + if (at(i2) == EMPTY || colour(at(i2)) != clr) { + subs.push_back(newWith(SHIFTER(i, i2))); + } + if (at(i2) != EMPTY) break; + if (i2 % 8 == 0) break; } - if (at(i2) != EMPTY) break; - if (i2 % 8 == 0) break; } - for (int i2 = i + 9; i2 < 64; i2 += 9) { - if (at(i2) == EMPTY || colour(at(i2)) != clr) { - subs.push_back(newWith(SHIFTER(i, i2))); + if (i % 8 != 7) { + for (int i2 = i + 9; i2 < 64; i2 += 9) { + if (at(i2) == EMPTY || colour(at(i2)) != clr) { + subs.push_back(newWith(SHIFTER(i, i2))); + } + if (at(i2) != EMPTY) break; + if (i2 % 8 == 7) break; } - if (at(i2) != EMPTY) break; - if (i2 % 8 == 7) break; } break; -- cgit v1.2.3-70-g09d2