mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
refactor: new way to check if a move is from the bottom of the deck
This commit is contained in:
parent
3641fb8b0d
commit
acb11c881b
5 changed files with 21 additions and 13 deletions
|
|
@ -664,7 +664,6 @@ void PlayerActions::moveBottomCardsTo(const QString &targetZone, const QString &
|
|||
cmd.set_target_zone(targetZone.toStdString());
|
||||
cmd.set_x(0);
|
||||
cmd.set_y(0);
|
||||
cmd.set_is_from_bottom(true);
|
||||
|
||||
for (int i = maxCards - number; i < maxCards; ++i) {
|
||||
auto card = cmd.mutable_cards_to_move()->add_card();
|
||||
|
|
@ -786,7 +785,6 @@ void PlayerActions::actDrawBottomCards()
|
|||
cmd.set_target_zone(ZoneNames::HAND);
|
||||
cmd.set_x(0);
|
||||
cmd.set_y(0);
|
||||
cmd.set_is_from_bottom(true);
|
||||
|
||||
for (int i = maxCards - number; i < maxCards; ++i) {
|
||||
cmd.mutable_cards_to_move()->add_card()->set_card_id(i);
|
||||
|
|
|
|||
|
|
@ -237,8 +237,7 @@ Response::ResponseCode Server_AbstractPlayer::moveCard(GameEventStorage &ges,
|
|||
int yCoord,
|
||||
bool fixFreeSpaces,
|
||||
bool undoingDraw,
|
||||
bool isReversed,
|
||||
bool isFromBottom)
|
||||
bool isReversed)
|
||||
{
|
||||
// Disallow controller change to other zones than the table.
|
||||
if (((targetzone->getType() != ServerInfo_Zone::PublicZone) || !targetzone->hasCoords()) &&
|
||||
|
|
@ -290,7 +289,23 @@ Response::ResponseCode Server_AbstractPlayer::moveCard(GameEventStorage &ges,
|
|||
bool revealTopStart = false;
|
||||
bool revealTopTarget = false;
|
||||
|
||||
// If the cards are to be taken from the bottom of the deck, reverse the order in which they are taken.
|
||||
bool isFromBottom = false;
|
||||
if (startzone->getName() == ZoneNames::DECK) {
|
||||
int movedCount = static_cast<int>(cardsToMove.size());
|
||||
int tailStart = startzone->getCards().size() - movedCount;
|
||||
if (tailStart >= 0) {
|
||||
isFromBottom = true;
|
||||
int expectedPosition = tailStart;
|
||||
for (const auto &card : cardsToMove) {
|
||||
if (card.position != expectedPosition) {
|
||||
isFromBottom = false;
|
||||
break;
|
||||
}
|
||||
++expectedPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isFromBottom) {
|
||||
std::ranges::reverse_view reversedCardsToMove{cardsToMove};
|
||||
for (auto card : reversedCardsToMove) {
|
||||
|
|
@ -772,8 +787,7 @@ Server_AbstractPlayer::cmdMoveCard(const Command_MoveCard &cmd, ResponseContaine
|
|||
cardsToMove.append(&cmd.cards_to_move().card(i));
|
||||
}
|
||||
|
||||
return moveCard(ges, startZone, cardsToMove, targetZone, cmd.x(), cmd.y(), true, false, cmd.is_reversed(),
|
||||
cmd.is_from_bottom());
|
||||
return moveCard(ges, startZone, cardsToMove, targetZone, cmd.x(), cmd.y(), true, false, cmd.is_reversed());
|
||||
}
|
||||
|
||||
Response::ResponseCode
|
||||
|
|
|
|||
|
|
@ -92,8 +92,7 @@ public:
|
|||
int yCoord,
|
||||
bool fixFreeSpaces = true,
|
||||
bool undoingDraw = false,
|
||||
bool isReversed = false,
|
||||
bool isFromBottom = false);
|
||||
bool isReversed = false);
|
||||
|
||||
void processMoveCard(GameEventStorage &ges,
|
||||
Server_CardZone *startzone,
|
||||
|
|
|
|||
|
|
@ -52,7 +52,4 @@ message Command_MoveCard {
|
|||
|
||||
// Inverts the x coordinate to apply from the end of the target zone instead of the start
|
||||
optional bool is_reversed = 8 [default = false];
|
||||
|
||||
// Inverts the order in which cards are moved (if false, from top to bottom)
|
||||
optional bool is_from_bottom = 9 [default = false];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ TEST(ReverseCardMoveTest, MoveCardFromBottomTest)
|
|||
QList<const CardToMove *> cardsToMove = {&moveA, &moveB, &moveC, &moveD};
|
||||
GameEventStorage ges;
|
||||
|
||||
const auto response = player.moveCard(ges, &deckZone, cardsToMove, &exileZone, 0, 0, false, false, false, true);
|
||||
const auto response = player.moveCard(ges, &deckZone, cardsToMove, &exileZone, 0, 0, false, false, false);
|
||||
|
||||
EXPECT_EQ(response, Response::RespOk);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue