doasku

Sudoku solver
git clone git://git.dimitrijedobrota.com/doasku.git
Log | Files | Refs

ref.hpp (2174B)


      1 #ifndef DOASKU_REF_HPP
      2 #define DOASKU_REF_HPP
      3 
      4 #include <cstdint>
      5 #include <utility>
      6 #include <vector>
      7 
      8 class Ref {
      9   public:
     10     using change_t = std::tuple<uint8_t, uint16_t>;
     11     using changes_t = std::vector<change_t>;
     12 
     13     uint16_t get(uint8_t field) const { return value[field]; }
     14     uint16_t get_ref(uint8_t value) const { return ref[value]; }
     15     uint16_t get_value(uint8_t field) const { return res[field]; }
     16 
     17     void clear(uint8_t field, uint8_t value);
     18     void set(uint8_t field, uint8_t value);
     19 
     20     changes_t get_hidden_singles() const;
     21     changes_t get_naked_singles() const;
     22 
     23     auto get_hidden_pairs() const { return get_hidden(2); }
     24     auto get_hidden_triplets() const { return get_hidden(3); }
     25     auto get_hidden_quads() const { return get_hidden(4); }
     26 
     27     auto get_naked_pairs() const { return get_naked(2); }
     28     auto get_naked_triplets() const { return get_naked(3); }
     29     auto get_naked_quads() const { return get_naked(4); }
     30 
     31     auto get_pointing_row() const { return get_pointing(0x7, 0); }
     32     auto get_pointing_col() const { return get_pointing(0x49, 1); }
     33 
     34   private:
     35     changes_t get_naked(int number) const;
     36     changes_t get_hidden(int number) const;
     37     changes_t get_pointing(uint16_t mask, bool seen) const;
     38 
     39     bool get_hidden(changes_t &res, uint8_t og, uint8_t number, uint8_t first,
     40                     uint16_t val, uint16_t mask) const;
     41 
     42     bool get_naked(changes_t &res, uint8_t og, uint8_t number, uint8_t first,
     43                    uint16_t val) const;
     44 
     45     static constexpr const std::int64_t mask_field = (1 << 9) - 1;
     46     static constexpr const std::int64_t mask_value = 0x201008040201;
     47 
     48     uint16_t value[9] = {mask_field, mask_field, mask_field,
     49                          mask_field, mask_field, mask_field,
     50                          mask_field, mask_field, mask_field};
     51 
     52     uint16_t ref[9] = {mask_field, mask_field, mask_field,
     53                        mask_field, mask_field, mask_field,
     54                        mask_field, mask_field, mask_field};
     55 
     56     uint16_t res[9] = {0};
     57 
     58     mutable uint16_t seen_hidden[4] = {0};
     59     mutable uint16_t seen_naked[4] = {0};
     60     mutable uint16_t seen_point[2] = {0};
     61 };
     62 
     63 #endif