Page 1 of 1

Sorting stock with duplicate types

Posted: 06 November 2020, 07:38
by GoDodyGo
It seems stock function changeItemsWeight() can be used to sort by color (suit) or value. I have this working with a single deck of standard 52-cards. I can sort by value or I can sort by color. It works well.

However, can it be used when there are 2 or more decks of identical cards? I want to be able to pull out 1 of the duplicate cards and let the player move it elsewhere in their hand. For example the players hand is:

(h = hearts, c = clubs, d = diamonds)

5h, 6h, 6h, 7h, 8h, 6c, 6d

I want the player to be able to move 1 of the 6-of-hearts to sit with the other sixes. So, they want to see this:

5h, 6h, 7h, 8h, 6c, 6h, 6d

But I cannot see how to do it with changeItemsWeight(). It Ideas? Thanks!

Re: Sorting stock with duplicate types

Posted: 17 January 2021, 23:53
by DargorX
Did you find any solution?
I have the same problem :cry: :cry: :cry:

Re: Sorting stock with duplicate types

Posted: 18 January 2021, 01:27
by RavingWanderer
Having the same sort of problems as GoDodyGo with stock's sorting, I ended up overriding some of it methods, including sortItems, to gain more flexible behavior. The implementation provided is not well suited for rummy-style card games, where the player needs/wants to control the card order.

At a minimum, you can set stock.order_items = false, and then sort stock.items yourself. Just remember to call stock.updateDisplay() afterward.

Re: Sorting stock with duplicate types

Posted: 18 January 2021, 01:43
by RicardoRix
you must have a different stock 'type' per card, then adjust the weights.

So if you have 2 different decks, you'll either have to use the location_arg to remember which deck it's in, or add another field to the card table. And the 'type' will need to take into account which deck it is in, not just the value and suit.

Re: Sorting stock with duplicate types

Posted: 18 January 2021, 02:02
by GoDodyGo
Yes, I did find a solution. It's basically what RavingWanderer and RicardoRix said, sort of... My (ugly) source code is on github or you can join liverpoolrummy developer group. Search for 'boardLieIndex'.

Summary: I added add another field ('boardLieIndex') to each card which I want to sort. I didn't add it to the SQL, just on the JS side. Then I use JS to determine which order I want the cards to lie. Then I call stock.updateDisplay() afterwards (per RW).

It still doesn't work 100%. I have 1 last bug (yeah, right!) where [Ace, Joker, Three, Joker] incorrectly lies as [Ace, Three, Joker, Joker] but the underlying method of adding this extra field is the way to go IMHO.