Scid  4.6.5
movelist.h
Go to the documentation of this file.
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 //
36 {
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
49  int32_t score; // used for alpha/beta ordering.
50 
51  bool isNullMove() const {
52  return from == to && from != NULL_SQUARE &&
53  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  explicit cmpMove(const simpleMoveT& sm) : m(sm) {}
65 };
66 inline bool operator==(const simpleMoveT& a, const cmpMove& b) {
67  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;
74 
75 public:
76  MoveList() : ListSize(0) {}
77 
79  iterator begin() { return Moves; };
80  iterator end() { return Moves + ListSize; }
81  uint Size() { return ListSize; }
82  void Clear() { ListSize = 0; }
85  ASSERT(ListSize < MAX_LEGAL_MOVES);
86  simpleMoveT& sm = Moves[ListSize++];
87  sm.from = from;
88  sm.to = to;
89  sm.promote = promote;
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  ASSERT(index < ListSize);
103  return &(Moves[index]);
104  }
105 };
106 
107 #endif // SCID_MOVELIST_H
unsigned char byte
Definition: common.h:97
squareT capturedSquare
Definition: movelist.h:44
MoveList()
Definition: movelist.h:76
pieceT piece_Type(pieceT p)
Definition: common.h:287
iterator end()
Definition: movelist.h:80
cmpMove(const simpleMoveT &sm)
Definition: movelist.h:64
const squareT NULL_SQUARE
Definition: common.h:352
#define ASSERT(f)
Definition: common.h:67
const pieceT KING
Definition: common.h:221
byte capturedNum
Definition: movelist.h:41
byte castleFlags
Definition: movelist.h:46
uint Size()
Definition: movelist.h:81
const uint MAX_LEGAL_MOVES
Definition: movelist.h:26
void resize(size_t count)
Definition: movelist.h:93
simpleMoveT * iterator
Definition: movelist.h:78
iterator begin()
Definition: movelist.h:79
ushort oldHalfMoveClock
Definition: movelist.h:48
uint32_t uint
Definition: common.h:99
void Clear()
Definition: movelist.h:82
bool operator==(const simpleMoveT &a, const cmpMove &b)
Definition: movelist.h:66
squareT to
Definition: movelist.h:40
byte pieceNum
Definition: movelist.h:37
uint16_t ushort
Definition: common.h:98
squareT from
Definition: movelist.h:39
simpleMoveT * Get(uint index)
Definition: movelist.h:101
pieceT capturedPiece
Definition: movelist.h:42
int32_t score
Definition: movelist.h:49
squareT epSquare
Definition: movelist.h:47
pieceT movingPiece
Definition: movelist.h:38
void push_back(const simpleMoveT &sm)
Definition: movelist.h:97
const simpleMoveT & m
Definition: movelist.h:63
pieceT promote
Definition: movelist.h:43
byte squareT
Definition: common.h:113
void emplace_back(squareT from, squareT to, pieceT promote, pieceT movingPiece, pieceT capturedPiece)
Definition: movelist.h:83
byte pieceT
Definition: common.h:111
bool operator<(const simpleMoveT &b) const
Definition: movelist.h:56
bool isNullMove() const
Definition: movelist.h:51