thecharlieblake / Solvitaire

A solver for a range of perfect-information, single player solitaire card games
GNU General Public License v2.0
32 stars 11 forks source link

Move generation bug with foundations_init_type::ALL and foundations_base #111

Open thecharlieblake opened 5 years ago

thecharlieblake commented 5 years ago

In the lines of code below, in the case of ALL, the code foundations[(f_idx + rand_suit)] can go outside the range when rand_suit > 0.

switch (rules.foundations_init_cards) {
--
  | case sol_rules::foundations_init_type::NONE:
  | break;
  | case sol_rules::foundations_init_type::ONE:
  | founds_to_fill = 1; break;
  | case sol_rules::foundations_init_type::ALL:
  | founds_to_fill = static_cast<uint8_t>(4 * (rules.two_decks ? 2 : 1)); break;
  | }
  | for (uint8_t f_idx = 0; f_idx < founds_to_fill; f_idx++) {
  | card c = card((f_idx + rand_suit) % uint8_t(4), foundations_base);
  |  
  | deck.erase(find(begin(deck), end(deck), c));
  | place_card(foundations[(f_idx + rand_suit)], c);
  | }

(this is only going to affect something with ALL and foundations_base, and we don’t think we have any such games)