From: Anthony Moralez Date: 2005-10-19T23:18:32+09:00 Subject: Re: [SOLUTION] Lost Cities (#51) Hi Daniel and James- On 10/18/05, Daniel Sheppard wrote: > Hmmm.... tried running your client through my tester, and it ends up > trying to draw cards from a pile that it can't, resulting in an infinite > loop of "There are no cards there" errors. This could be due to > line-wrapping in the email though - I already had to fix up this code: > > cards.last != @last_discard and cards.any? { |card| playable? > (card) } > > So that it was all on one line, otherwise it tries to call playable with > no args. > > (to make your player work with my tester, I also changed all references > of "@hand" to "@my_hand"). Thanks for those fixes. I found the other problem. Risk player keeps track of the discards and his last discard but never notices if he picks one up. Below are the fixes I used to get it to run. But I think I might have changed it's behavior. > > -----Original Message----- > > From: James Edward Gray II [mailto:james@grayproductions.net] > > Sent: Wednesday, 19 October 2005 8:18 AM > > To: ruby-talk ML > > Subject: Re: [SOLUTION] Lost Cities (#51) > > > > def discard_card( choices ) > > discard = choices.sort_by do |card| > > [ playable?(card) ? 1 : 0, playable?(card, :them) ? 1 : 0, > > card.value.is_a?(String) ? 0 : card.value ] > > end.first > > > > @last_discard = discard @piles[:discard][discard.land].delete discard > > "d#{discard.value}#{discard.land[0, 1]}".sub("nv", "") > > end > > > > def draw_card > > want = @piles[:discards].find do |land, cards| > > not @piles[:me][land].empty? and (not cards.find { |card| @my_hand.include? card } ) and > > cards.last != @last_discard and cards.any? { |card| playable? > > (card) } > > end > > if want > > want.first[0, 1] > > else > > "n" > > end > > end