Ad
  • Default User Avatar

    yes, but what is the issue here ? you modify tracker yourself, so you mutate the state of your Hand object. then at the next call with the same object, of course the mutations will persist. take a look at how the random tests work, all of the hands are built beforehand and are played against each other at random, it is very likely that one hand get used multiple times, hence why the changes persist

  • Default User Avatar

    it seems to be your own code that modifies the tracker field though, I slightly modified your test in compare():

    Result compare(Hand *pl, Hand *op) {
      int checksum = (pl->tracker == 0) + (op->tracker == 0);
      pl->type = buildTracker(pl, pl->cards);
      op->type = buildTracker(op, op->cards);
      Result retval = _compare(pl, op);
      int new_checksum = (pl->tracker == 0) + (op->tracker == 0);
      assert(checksum == new_checksum);
      return retval;
    }
    

    the assertion fails.

  • Custom User Avatar

    This code does not really confirm anything because we do not know how your real code, the one which breaks things, looks like.

  • Default User Avatar

    Are you sure? b7 to a8 return 4.
    If begin OR end position is a corner point (A1,A8,H1,H8) AND BOTH row and col are 1 step, we've a minimum of 4 moves.
    This covers the moves A1-->B2; B2-->A1; H1-->G2; G2-->H1; A8-->B7; B7-->A8; H8-->G7; G7-->H8
    For all other 1-1 moves, you will not fall in the second IF case and it returns 2 moves.

    I play with the ASCII value: 'a' = 65, 'b' = 66... 'h' = 72; '1' = 49, '2' = 50,... '9' = 57
    It doesn't matter if we move from a to b or b to a as ABS(66-65) == ABS(65-66) == 1; same for the digits.