~ajpaon/squell

654da4c4866416f49b7bca362e34c144de8d8e9f — Andrew Paon 10 months ago 290c532
remove some code duplication in allowed_moves
1 files changed, 2 insertions(+), 11 deletions(-)

M main.c
M main.c => main.c +2 -11
@@ 147,17 147,8 @@ GridField allowed_moves_in_column(GridField g, struct Piece p, int x) {
GridField allowed_moves(GridField g, struct Piece p) {
  GridField allowed = 0;

  for (int y = 0; y < 9 - p.height + 1; ++y) {
    for (int x = 0; x < 9 - p.width + 1; ++x) {
      int b = y * 9 + x;
      GridField pf = p.field;

      pf <<= b;
      GridField mask = (g & pf) == 0;

      mask <<= b;
      allowed |= mask;
    }
  for (int x = 0; x < 9 - p.width + 1; ++x) {
    allowed |= allowed_moves_in_column(g, p, x);
  }

  return allowed;