LCOV - code coverage report
Current view: top level - src - movelist.h (source / functions) Hit Total Coverage
Test: test_coverage.info Lines: 12 16 75.0 %
Date: 2017-06-21 14:32:49 Functions: 0 0 -

          Line data    Source code
       1             : //////////////////////////////////////////////////////////////////////
       2             : //
       3             : //  FILE:       movelist.h
       4             : //              MoveList class
       5             : //
       6             : //  Part of:    Scid (Shane's Chess Information Database)
       7             : //  Version:    3.4
       8             : //
       9             : //  Notice:     Copyright (c) 1999-2002 Shane Hudson.  All rights reserved.
      10             : //              Copyright (c) 2016 Fulvio Benini.  All rights reserved.
      11             : //
      12             : //  Author:     Shane Hudson (sgh@users.sourceforge.net)
      13             : //
      14             : //////////////////////////////////////////////////////////////////////
      15             : 
      16             : 
      17             : #ifndef SCID_MOVELIST_H
      18             : #define SCID_MOVELIST_H
      19             : 
      20             : #include "common.h"
      21             : #include <iterator>
      22             : 
      23             : //////////////////////////////////////////////////////////////////////
      24             : //  MoveList:  Constants
      25             : 
      26             : const uint  MAX_LEGAL_MOVES = 256;  // max. length of the moves list
      27             : 
      28             : 
      29             : ///////////////////////////////////////////////////////////////////////////
      30             : //  MoveList:  Data Structures
      31             : 
      32             : // *** SimpleMove: less expensive to store than a full move as defined
      33             : //      in game.h, but still fully undoable.
      34             : //
      35             : struct simpleMoveT
      36             : {
      37             :     byte     pieceNum;
      38             :     pieceT   movingPiece;
      39             :     squareT  from;
      40             :     squareT  to;
      41             :     byte     capturedNum;
      42             :     pieceT   capturedPiece;
      43             :     pieceT   promote;
      44             :     squareT  capturedSquare; // ONLY different to "to" field if this capture
      45             :                             //    is an en passant capture.
      46             :     byte     castleFlags;    // pre-move information
      47             :     squareT  epSquare;       // pre-move information
      48             :     ushort   oldHalfMoveClock;
      49             :     int32_t  score;          // used for alpha/beta ordering.
      50             : 
      51             :         bool isNullMove() const {
      52    17865668 :                 return from == to && from != NULL_SQUARE &&
      53           0 :                        piece_Type(movingPiece) == KING;
      54             :         }
      55             : 
      56             :         bool operator<(const simpleMoveT& b) const {
      57             :                 // Highest score first
      58             :                 return score > b.score;
      59             :         }
      60             : };
      61             : 
      62             : struct cmpMove {
      63             :         const simpleMoveT& m;
      64           0 :         explicit cmpMove(const simpleMoveT& sm) : m(sm) {}
      65             : };
      66             : inline bool operator==(const simpleMoveT& a, const cmpMove& b) {
      67           0 :         return a.from == b.m.from && a.to == b.m.to && a.promote == b.m.promote;
      68             : }
      69             : 
      70             : // typedef std::vector<simpleMoveT> MoveList;
      71             : class MoveList {
      72             :         uint ListSize;
      73             :         simpleMoveT Moves[MAX_LEGAL_MOVES];
      74             : 
      75             : public:
      76     2008219 :         MoveList() : ListSize(0) {}
      77             : 
      78             :         typedef simpleMoveT* iterator;
      79             :         iterator begin() { return Moves; };
      80           0 :         iterator end() { return Moves + ListSize; }
      81             :         uint Size() { return ListSize; }
      82     2902941 :         void Clear() { ListSize = 0; }
      83             :         void emplace_back(squareT from, squareT to, pieceT promote,
      84             :                           pieceT movingPiece, pieceT capturedPiece) {
      85    20001799 :                 ASSERT(ListSize < MAX_LEGAL_MOVES);
      86    20001799 :                 simpleMoveT& sm = Moves[ListSize++];
      87    20001799 :                 sm.from = from;
      88    20001799 :                 sm.to = to;
      89    20001799 :                 sm.promote = promote;
      90    20001799 :                 sm.movingPiece = movingPiece;
      91    20001799 :                 sm.capturedPiece = capturedPiece;
      92             :         }
      93             :         void resize(size_t count) {
      94             :                 ASSERT(count <= MAX_LEGAL_MOVES);
      95             :                 ListSize = static_cast<uint>(count);
      96             :         }
      97             :         void push_back(const simpleMoveT& sm) {
      98             :                 ASSERT(ListSize < MAX_LEGAL_MOVES);
      99             :                 Moves[ListSize++] = sm;
     100             :         }
     101             :         simpleMoveT* Get(uint index) {
     102     1485667 :                 ASSERT(index < ListSize);
     103      779065 :                 return &(Moves[index]);
     104             :         }
     105             : };
     106             : 
     107             : #endif // SCID_MOVELIST_H

Generated by: LCOV version 1.12