This commit is contained in:
2022-12-23 23:57:29 +01:00
parent 87adca7e66
commit cb0fcc4702
14 changed files with 208 additions and 52 deletions

View File

@@ -3,10 +3,21 @@
#include <ostream>
#include <iostream>
Move::Move(const Square &from, const Square &to, const std::optional<PieceType> &promotion)
: mFrom(from), mTo(to), mPromotion(promotion) {
Move::Move(const Square &from, const Square &to) : mFrom(from), mTo(to) {
}
Move::Move(const Square &from, const Square &to, const std::optional<PieceType> &promotion, unsigned score)
: mFrom(from), mTo(to), mPromotion(promotion) {
mScore -= score;
}
Move::Move(const Square &from, const Square &to, unsigned int score) : mFrom(from), mTo(to) {
mScore -= score;
}
Move::Optional Move::fromUci(const std::string &uci) {
if (uci.length() < 4 || uci.length() > 5)
return std::nullopt;
@@ -48,17 +59,31 @@ std::ostream &operator<<(std::ostream &os, const Move &move) {
}
bool operator<(const Move &lhs, const Move &rhs) {
if (!(lhs.from() == rhs.from()))
return lhs.from() < rhs.from();
if (lhs.mScore != rhs.mScore) {
return lhs.mScore < rhs.mScore;
}
if (!(lhs.to() == rhs.to()))
return lhs.to() < rhs.to();
if (lhs.mFrom.index() != rhs.mFrom.index()) {
return lhs.mFrom.index() < rhs.mFrom.index();
}
if (lhs.mTo.index() != rhs.mTo.index()) {
return lhs.mTo.index() < rhs.mTo.index();
}
return lhs.promotion() < rhs.promotion();
}
bool operator==(const Move &lhs, const Move &rhs) {
return lhs.from() == rhs.from()
&& lhs.to() == rhs.to()
&& lhs.promotion() == rhs.promotion();
return lhs.score() == rhs.score()
&& lhs.from() == rhs.from()
&& lhs.to() == rhs.to()
&& lhs.promotion() == rhs.promotion();
}
unsigned int Move::score() const {
return mScore;
}
void Move::setScore(unsigned int score) {
mScore = score;
}