Skip to content

SotC Character Generator, part 2

21 December 2008

So, I’ve gotten a little farther, adding a few of the sample aspects from the book.

Aspects:
  Cowardly
  Family Estate
  Meticulous
  Self-Destructive
  Veteran
Skills:
  ...

I thought it would be a slam dunk, but I learned something about LINQ and objects.

I defined a simple Aspect object:

   37 public class Aspect  
   38
 {

   39     public string Name { get; set; }

   40 }

And I expected the following to work:

   17             var availableAspects = aspectPool.Except(takenAspects);   18 

   19             if (!availableAspects.Any())

   20                 throw new ArgumentException(“No aspects remain in master aspect list”);

   21 

   22             return availableAspects.TakeRandom();

It quickly became apparent that the Except wasn’t filtering. I later came to understand it was because the default object’s Equals methods couldn’t distinguish between the different Aspects in the lists. When I overrode Equals and GetHashCode to defer to the Name string, problem solved!

Now, on to a little holiday shopping… 🙂

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: