Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Napoleon - move.h

move.h

Caricato da: Crybot
Scarica il programma completo

  1. #ifndef MOVE_H
  2. #define MOVE_H
  3. #include "defines.h"
  4. #include "piece.h"
  5.  
  6. namespace Napoleon
  7. {
  8.     const MoveType KingCastle = 0x2, QueenCastle = 0x3, EnPassant = 0x5, QueenPromotion = 0xB,
  9.     RookPromotion = 0xA, BishopPromotion = 0x9, KnightPromotion = 0x8;
  10.  
  11.     class Move
  12.     {
  13.     public:
  14.         Move();
  15.         Move(Square, Square);
  16.         Move(Square, Square, Square);
  17.  
  18.         Square FromSquare() const;
  19.         Square ToSquare() const;
  20.         Square PiecePromoted() const;
  21.  
  22.         int ButterflyIndex() const;
  23.         bool IsNull() const;
  24.         bool IsCastle() const;
  25.         bool IsCastleOO() const;
  26.         bool IsCastleOOO() const;
  27.         bool IsPromotion() const;
  28.         bool IsEnPassant() const;
  29.         bool operator== (const Move&) const;
  30.         bool operator!= (const Move&) const;
  31.         std::string ToAlgebraic() const;
  32.  
  33.     private:
  34.         unsigned short move;
  35.  
  36.     };
  37.  
  38.     INLINE Move::Move() { }
  39.  
  40.     inline Move::Move(Square from, Square to)
  41.     {
  42.         move = (from & 0x3f) | ((to & 0x3f) << 6);
  43.     }
  44.  
  45.     inline Move::Move(Square from, Square to, Square flag)
  46.     {
  47.         move = (from & 0x3f) | ((to & 0x3f) << 6) | ((flag & 0xf) << 12);
  48.     }
  49.  
  50.     inline Square Move::FromSquare() const
  51.     {
  52.         return move & 0x3f;
  53.     }
  54.  
  55.     inline Square Move::ToSquare() const
  56.     {
  57.         return (move >> 6) & 0x3f;
  58.     }
  59.  
  60.     inline int Move::ButterflyIndex() const // used to index from-to based tables
  61.     {
  62.         return (move & 0xfff);
  63.     }
  64.  
  65.     inline Square Move::PiecePromoted() const
  66.     {
  67.         if (!IsPromotion())
  68.             return PieceType::None;
  69.  
  70.         return ((move >> 12) & 0x3) + 1;
  71.     }
  72.  
  73.     inline bool Move::IsEnPassant() const
  74.     {
  75.         return ((move >> 12) == EnPassant); // e.p. are encoded 0101
  76.     }
  77.  
  78.     inline bool Move::IsCastle() const
  79.     {
  80.         return (((move >> 12) == KingCastle) || ((move >> 12) == QueenCastle));
  81.     }
  82.  
  83.     inline bool Move::IsPromotion() const
  84.     {
  85.         return ((move >> 12) & 0x8);
  86.     }
  87.  
  88.     inline bool Move::operator ==(const Move& other) const
  89.     {
  90.         return (move == other.move);
  91.     }
  92.  
  93.     inline bool Move::operator !=(const Move& other) const
  94.     {
  95.         return (move != other.move);
  96.     }
  97. }
  98. #endif // MOVE_H