(define-module (game-board)
  #:export (on-same-row?
            on-same-col?
            squares-between
            col-squares-between
            get-coord
            get-coords-of-trues
            index->board-coords))


(define (on-same-row? start-pos end-pos)
  (eq? (get-row-part start-pos)
       (get-row-part end-pos)))


(define (on-same-col? start-pos end-pos)
  (eq? (get-col-part start-pos)
       (get-col-part end-pos)))


(define (squares-between board start-pos end-pos)
  (define (row-squares-between board start-pos end-pos)
    (let ([col-idxs (number-range-exclusive (get-col-part start-pos) (get-col-part end-pos))]
          [row-idx (get-row-part start-pos)])
      (map (λ (col-idx) (make-coords row-idx col-idx))
           col-idxs)))

  (define (col-squares-between board start-pos end-pos)
    (let ([row-idxs (number-range-exclusive (get-row-part start-pos) (get-row-part end-pos))]
          [col-idx (get-col-part start-pos)])
      (map (λ (row-idx) (make-coords row-idx col-idx))
           row-idxs)))

  (cond [(equal? start-pos end-pos) '()]
        [(on-same-row? start-pos end-pos) (row-squares-between board start-pos end-pos)]
        [(on-same-col? start-pos end-pos) (col-squares-between board start-pos end-pos)]
        [else (throw 'logic-error
                     "squares not on same row or column"
                     board start-pos end-pos)]))
