shangwyoung / Space_Station_Auction

WT 2016
2 stars 0 forks source link

Card Class #1

Closed shangwyoung closed 8 years ago

shangwyoung commented 8 years ago

Cards (the elements you’re bidding on) are described by a 6-element list: [<name>, <scienceValue>, <ecologyValue>, <cultureValue>, <commerceValue>, <industryValue>] e.g. ["Puppy Cloning Center", 2, 0, 3, 0, 0]

Sam Rossin has written the following class, which I think we can use as reference:

class Card:
    def __init__(self, name, science, ecology, culture, commerce, industry):
        self.list = [name, science, ecology, culture, commerce, industry]

    def getList(self):
        return self.list

    def getName(self):
        return self.list[0]

    def getScienceValue(self):
        return self.list[1]

    def getEcologyValue(self):
        return self.list[2]

    def getCultureValue(self):
        return self.list[3]

    def getCommerceValue(self):
        return self.list[4]

    def getIndustryValue(self):
        return self.list[5]

    def __repr__(self):
        return(self.list[0] + "\nScience Value: " + str(self.list[1]) +
               "\nEcology Value: " + str(self.list[2]) +
               "\nCulture Value: " + str(self.list[3]) +
               "\nCommerce Value: " + str(self.list[4]) +
               "\nIndustry Value: " + str(self.list[5]) + "\n")
nickmusic commented 8 years ago

I sent a FB message, but I realized the question might belong here. The class that I have written is very similar to Sam Rossin's but I chose to have the constructor take an array of ints for the stats instead of individual args. I believe it will be easier to generate random cards this way. Let me know if you have an issue with this.

The constructor looks like this. Pardon the lack of indentation.

class Card: def init(self, name, stats): self.card = [name, stats[0], stats[1], stats[2], stats[3], stats[4]]

tbwexler commented 8 years ago

Stylistically I'd suggest two fields for card: name and stats -- name won't be used much. I'd also add a getValue(self, index) function just to clean up the rest of the code.

nickmusic commented 8 years ago

That is exactly what I did actually. I will make sure my branch is available on the remote repository today. I do like the getValue() idea as opposed to having individual getters for everything.

On Thu, Jan 7, 2016 at 9:10 AM, tbwexler notifications@github.com wrote:

Stylistically I'd suggest two fields for card: name and stats -- name won't be used much. I'd also add a getValue(self, index) function just to clean up the rest of the code.

— Reply to this email directly or view it on GitHub https://github.com/aarony422/Space_Station_Auction/issues/1#issuecomment-169674692 .

nickmusic commented 8 years ago

Would it be easier for us to test if the string representation of the class was

Puppy Clone Factory Science: 0 Ecology: 2 Culture: 0 Commerce: 3 Industry: 0

or simply the array?

[Puppy Clone Factory, 0, 2, 0, 3, 0]

The second way might be easier if we are printing a lot of cards at once, but the first way is very readable. Thoughts?

On Thu, Jan 7, 2016 at 9:18 AM, Nicholas Music nmusic@oberlin.edu wrote:

That is exactly what I did actually. I will make sure my branch is available on the remote repository today. I do like the getValue() idea as opposed to having individual getters for everything.

On Thu, Jan 7, 2016 at 9:10 AM, tbwexler notifications@github.com wrote:

Stylistically I'd suggest two fields for card: name and stats -- name won't be used much. I'd also add a getValue(self, index) function just to clean up the rest of the code.

— Reply to this email directly or view it on GitHub https://github.com/aarony422/Space_Station_Auction/issues/1#issuecomment-169674692 .

tbwexler commented 8 years ago

I'd suggest the second approach, although you can always keep the prettier one around as a verbose version (if (verbose) ... else ... ).