 |
BOOK: Beginning Visual C# 2010
 | This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 30th, 2010, 05:25 AM
|
|
Authorized User
|
|
Join Date: Dec 2008
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
CardLib logic, page 318, figure 11-7
What's the idea behind having The Ace of Diamonds greater than The Ten of Hearts and at the same time The Ten of Hearts is greater than The Ace of Diamonds? Since neither of the cards is a trump (clubs) and since Aces are high, shouldn't the latter comparison be false?
|
|

July 15th, 2010, 04:09 AM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Yes you right it should.
But I think they just didn't include the condition where both cards aren't trump cards (of Club Suit in this exercice), in the > operator overload function.
I was a bit confused too.
|
|

August 7th, 2010, 09:47 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 15
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
answer
Hey man.
According to what i understood, the suit values are to determine comparisons.
If both cards are not trump (Clubs), and they are different in their suit values, then the 1st card in the Deck wins the card below it automatically regardless to the Rank values and regardless to the isacehigh flag.
Well, if one of the cards is trump and the other is not trump, so it wins automatically.
If both cards have same suit value, then the Rank value should be the decider of the comparison, but now and only now the isacehigh flag should be checked, because as mentioned the suit values are the same for both.
Now, the Rank values will decide what will be the result of the comparison, where if isacehigh=flase, the Rnak values will just be compared to one another, and if isacehigh=true, cards with Rank of Ace will win automtically any card (unless ofcourse the 2nd card is also Ace-and then the result of the comparison will be no winner).
It is really bad explained in the book (the rules of the game), but I hope my explanation helps you and the next to come.
So I think there are no mistakes in their code in the book.
Best whishes! 
Last edited by stormage; August 8th, 2010 at 11:40 AM..
|
|

August 13th, 2010, 02:28 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
My Solution
I had the same issue with the CardLib logic and posted it as errata, but it has yet to show up.
I came up with my own solution, which could probably be written better, but it works.
I modified the overloads for > and >= to test for Aces High in either the first or second card position. If Trumps are set to true, they will still be higher than an ace in either position.
I added two private functions to perform the tests. Since they were done in several places, and the code was the same for the test each time, it made sense to simplify the logic by doing so.
Here are the code changes I made. If someone has an easier method of accomplishing this, please post it as well.
Code:
public static bool operator >(Card card1, Card card2)
{
if (card1.suit == card2.suit)
{
if (isAceHigh)
{
return TestAces(card1, card2);
}
else
{
return (card1.rank > card2.rank);
}
}
else
{
if (useTrumps)
{
if (card2.suit == Card.trump)
return false;
else
{
if (isAceHigh)
{
return TestAces(card1, card2);
}
else
{
return (card1.rank > card2.rank);
}
}
}
else
{
if (isAceHigh)
{
return TestAces(card1, card2);
}
else
{
return (card1.rank > card2.rank);
}
}
}
}
/// <summary>
/// The code demonstrated in the book did not account for Aces High very well.
/// I copied the test for aces high into here since I had to make changes to
/// the > operator and the to check if the suits were the same or different,
/// if a suit was set to trump, and a basic hand
/// </summary>
/// <param name="card1">Card object</param>
/// <param name="card2">Card object</param>
/// <returns>True/False</returns>
private static bool TestAces(Card card1, Card card2)
{
if (card1.rank == Rank.Ace)
{
if (card2.rank == Rank.Ace)
return false;
else
return true;
}
else
{
if (card2.rank == Rank.Ace)
return false;
else
return (card1.rank > card2.rank);
}
}
/// <summary>
/// The code demonstrated in the book did not account for Aces High very well.
/// I copied the test for aces high into here since I had to make changes to
/// the >= operator and the to check if the suits were the same or different,
/// if a suit was set to trump, and a basic hand
/// </summary>
/// <param name="card1">Card object</param>
/// <param name="card2">Card object</param>
/// <returns>True/False</returns>
private static bool TestAces2(Card card1, Card card2)
{
if (card1.rank == Rank.Ace)
{
return true;
}
else
{
if (card2.rank == Rank.Ace)
return false;
else
return (card1.rank >= card2.rank);
}
}
public static bool operator >=(Card card1, Card card2)
{
if (card1.suit == card2.suit)
{
if (isAceHigh)
{
return TestAces2(card1, card2);
}
else
{
return (card1.rank >= card2.rank);
}
}
else
{
if (useTrumps)
{
if (card2.suit == Card.trump)
return false;
else
{
if (isAceHigh)
{
return TestAces2(card1, card2);
}
else
{
return (card1.rank >= card2.rank);
}
}
}
else
{
if (isAceHigh)
{
return TestAces2(card1, card2);
}
else
{
return (card1.rank >= card2.rank);
}
}
}
}
Last edited by LloydAZ; August 13th, 2010 at 02:35 AM..
Reason: Typo
|
|

April 5th, 2011, 05:06 PM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
CardLib logic is OK - order matters
Quote:
Originally Posted by stormage
...
If both cards are not trump (Clubs), and they are different in their suit values, then the 1st card in the Deck wins
...
|
stormage is correct. The rules are explained at the bottom of page 308. The order matters. That is why A of D > 10 of H, and then 10 of H > A of D.
I am not a card player, so I missed that, too, on the first read.
Of course, the purpose of the book is to learn C# programming, not how to play card games. 
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Page 17 Figure 1-1 |
leskelly |
BOOK: Beginning JavaScript and CSS Development with jQuery |
4 |
March 18th, 2010 06:58 AM |
| Page 105, Figure 3-2 |
LongJohnSilver |
BOOK: Professional Visual Basic 2008 ISBN: 978-0-470-19136-1 |
0 |
March 3rd, 2009 11:20 AM |
| chapter 11 figure 11-7 relative positioning |
pelopito |
BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 |
2 |
November 29th, 2007 06:11 AM |
| Figure 6.5, Page 296 |
Nick Y |
BOOK: Ivor Horton's Beginning Visual C++ 2005 |
0 |
June 4th, 2006 02:32 AM |
|
 |
|