How to find penultimate list item

BlitzMax Forums/BlitzMax Beginners Area/How to find penultimate list item

Grey Alien(Posted 2007) [#1]
Just thought some noobs might find this code useful. It finds the penultimate item in a list and typecasts it back the the correct type.

For example, if I had a TCard Type and I store them in an ordinary TList called CardList, and then I want to retrieve the penultimate (second from last) card, I can do it like this:

Local c:TCard = TCard(CardList.LastLink().PrevLink().Value())


Value() only returns an Object that is not of the correct type so that's why the whole statement has TCard() around it. The "typecasts" the object into a TCard so we can used it.

Hope you find it useful.


Gavin Beard(Posted 2007) [#2]
:-) thankin you mr alien sir, very helpful


FlameDuck(Posted 2007) [#3]
Dealing from the bottom of the deck again? Tsk, tsk, tsk...


Grey Alien(Posted 2007) [#4]
ahem yes well spotted, although my list is in reverse so that is the second from top card.


SpaceAce(Posted 2007) [#5]

ahem yes well spotted, although my list is in reverse so that is the second from top card.



That's called dealing seconds and is one of the things the mechanic's grip is great for.

SpaceAce


Grey Alien(Posted 2007) [#6]
"mechanic's grip"? Is this another form of cheating?


sswift(Posted 2007) [#7]
Speaking of cheating at cards...

I invented a magic trick involving cards once.


I allow a person to pick any card from a perfectly normal deck of cards. Could even be a new sealed deck.

Then I have them place the card down on top of the deck.

I then shuffle the deck, then allow them to shuffle it as well if they wish.

And finally, I go through the deck one card at a time until I get to their card and show it to them.


Figured out the trick yet?

Of course you haven't. :-)


The trick is that before I did the trick, I placed a small dab of vaseline on my thumb, and when I take the deck from the person with the card on top, I press my thumb down on it. The vaseline is effectively invisible, only a tiny amount, but it is enough for me to feel it when I go through the deck to find the card if I rub my fingers across the top.

(I may actually have done this trick with chapstick, I can't recall. Vaseline may be too sticky.)


Grey Alien(Posted 2007) [#8]
I had a similar one where after they pick the cardm they hand it too you and you push it back into the pack and make a tiny mark with you fingernail. Then they can shuffle it and later you can identify it by the fingernal mark. Your one is better though as you never touch the card before the pack is shuffled. Mine still worked pretty well though ;-)


SpaceAce(Posted 2007) [#9]
Yes, the mechanic's grip is a way of holding a deck of cards that gives better control over the deck, thus allowing base dealing, seconds dealing, peaking and other basic manipulations useful in magic and card cheating.

SpaceAce


Grey Alien(Posted 2007) [#10]
gasp! you cheater you ;-)


sswift(Posted 2007) [#11]
http://en.wikipedia.org/wiki/Mechanic's_grip


Grey Alien(Posted 2007) [#12]
Ah yes, look familiar.