stellar

Stellar - UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

repetition.hpp (972B)


      1 #ifndef STELLAR_REPETITION_H
      2 #define STELLAR_REPETITION_H
      3 
      4 #include <iostream>
      5 #include <vector>
      6 
      7 #include "utils.hpp"
      8 
      9 namespace repetition {
     10 
     11 class Table {
     12   public:
     13     Table() = default;
     14 
     15     [[nodiscard]] bool is_repetition(const U64 hash) const {
     16         for (int i = repetitions.size() - 1; i >= 0; i--) {
     17             if (repetitions[i] == hash) return true;
     18             if (repetitions[i] == hashNull) return false;
     19         }
     20         return false;
     21     }
     22 
     23     void pop() { repetitions.pop_back(); }
     24     void clear() { repetitions.clear(); }
     25     void push_null() { repetitions.push_back(hashNull); }
     26     void push_hash(U64 hash) { repetitions.push_back(hash); }
     27 
     28     friend std::ostream &operator<<(std::ostream &os, const Table &rtable) {
     29         for (const U64 hash : rtable.repetitions)
     30             os << hash << " ";
     31         return os;
     32     }
     33 
     34   private:
     35     std::vector<U64> repetitions;
     36 
     37     const static int hashNull = 0;
     38 };
     39 
     40 } // namespace repetition
     41 
     42 #endif