It is currently 12 Nov 2025, 12:00
   
Text Size

Shandalar - Program Bugs

Library of Alexandria sees incorrect hand count (pending)

 

Last edited by Korath on 25 May 2015, 19:57, edited 1 time in total.

Comments

Posted by Korath » 22 May 2015, 12:42

This was a problem for a long time in Manalink. I was hoping that it was mainly because of cards added there, not because of problems with the original Microprose cards. (It doesn't appear to be either Crystal Ball's or Sylvan Library's fault, as reported.)

Cards in play, on the stack, and in hand are all kept in the same unsorted array, card_instances[][]. (Cards in libraries, graveyards, and exile are kept separate, and nothing is stored about them except for a four-byte id.) Since a fair number of cards care about how many a player has in hand, and iterating over the whole array to count how many instances are valid, not in play, and not on the stack is relatively slow, a separate count (hand_count[]) is maintained for each player.

The problem was that the functions to draw a card, to discard, and various actions that could add or remove a card to or from a player's hand (bounce_permanent(), kill_card(), put_into_play(), many others) didn't change hand_count[] themselves; it was the responsibility of the individual cards that used those functions. This path was fraught with peril and bugs, usually manifesting either with Library of Alexandria (as you observed) or a "discard your hand" effect demanding that you pick another card to discard when your hand was already empty - but it wasn't ever the fault of Library of Alexandria or Lion's Eye Diamond or Wit's End or whatever; it was some other, completely innocuous and non-obvious card that failed to adjust hand_count[] like it was supposed to.

(Annoyingly enough, the variable that displays in the title of the "Your Hand (6)" window, while it's always correct for the current game state and doesn't need to be manually maintained like hand_count[], isn't reliable during AI speculation and so can't be used.)

We eventually got rid of this error by making draw_a_card() and discard_card() and add_card_to_hand() and all the other functions of this sort maintain hand_count[] instead of making individual cards do it. I've done the same in expanding Shandalar. It's certainly possible that I overlooked a function needing a new version that maintains hand_count[], but I don't think so.

I'm really not looking forward to tracking these all down again. Hrm. Maybe I'll recalculate hand_count[] de novo during recalculate_all_cards_in_play(), which has to walk the card_instances[][] array anyway and gets run fairly frequently (almost exactly corresponding to whenever state-based actions are checked under modern rules).

Posted by Korath » 07 Jun 2015, 16:56

commit fc9bc5721d322be92de235f5179219e6fbf67925
Author: Korath <dgk@Dirge.none>
Date: Sun Jun 7 12:55:46 2015 -0400

[Shandalar] #529: recalc hand_count[] in count_colors_of_lands_in_play()

Posted by Korath » 07 Jun 2015, 17:00

Meanwhile, I'm going to play with Maro and his Kamigawa-block friends for a while before this gets merged into the dev branch, and see whether I can't stumble across what's actually breaking it.

If I don't find it, a config option to turn off recomputation might be in order, so other folks can help me look; I'd really rather fix the real problem than just hide its symptoms.

Ticket details

  • Ticket ID: 529
  • Project: Shandalar
  • Status: Pending
  • Component: Duel Engine
  • Project version: Ruined Tower 1
  • Priority: Normal
  • Severity: Normal
  • Assigned to: Korath
  • Reported by: Korath
  • Reporter's tickets: List all tickets
  • Reported on: 22 May 2015, 12:40
  • Last visited by drool66 » 02 Jan 2017, 22:15.
 

Main Menu

User Menu

Our Partners


Login Form