Hi Kent,

First off, thank you so much for the suggestions! They have helped clarify some of the concepts I've been struggling with lately ( mostly object - related ones ). I have been teaching myself Python in my spare time for the last few months, and have no previous programming experience, so any feedback I get really helps me improve as a programmer.

I have implemented some of the changes you talked about, and posted an updated version of my program here:

http://rafb.net/paste/results/SicsjJ23.html

I hope this new version is a bit better, and that my answers to your questions help you understand what I'm doing.

do you mean, 'each player is teammates with each other player exactly once', or, 'each player is teammates with each other player at most once'? Is there a certain number of rounds that must be played?

Each player is teammates with each other player exactly once.

- Why do you have the initialization code in a comment? Wouldn't it be helpful to put that in a function or maybe Tournament.__init__()?

The initialization code is commented because I don't run it every time the script runs ( it takes awhile to run ). I usually load the list from a file, this is reflected in my updated code.


- I have a hard time figuring out how this is supposed to work. Maybe some comments about the algorithm you are using would help? I have no idea what self.key is doing.

My algorithm works something like this:

Fact: roundlist partitions into 11 slices of length 113400, and self.key keeps track of which round in each of those slices I am currently using.

Starting with the first tournament ( Tournament(0) ), I do the following:
1. Construct the tournament.
2. Test to see if two players are on the same team twice ( checkTeammates )
3. Test to see if two players match up against each other too often (checkOpponents )
4a. If everything is ok, I'll append another round from the next slice.
4b. If not, I'll try the next round in the most recent slice. If none of the rounds in the slice work, I'll move back and try the next round in the previous slice, etc.
5. Whenever I manage to build an 11 round tournament, I'm done.


It's an attempt at a recursive algorithm, and I'm not sure how well it is implemented.

- What is the argument to Tournament.__init__() for?

The argument lets you specify a starting tournament, to avoid having to start the search from the beginning, you can instead pick up from some point where you last left off.


Example: Tournament(0,113460) gives a two round tournament using elements 0, 113460 from roundlist.

- The above code depends on roundlist which is not even defined anywhere in the module (just shown in the comment). This suggests again that the init code from the comment should be part of Tournament, and roundlist should be an attribute of Tournament. For a class to depend on some external variable is bad design and will break if the client code is in a different module from the class code (roundlist will be in a different namespace than Tournament).

I have always been uneasy about this, but I wanted to be able to define multiple tournament objects off of the same roundlist, to avoid generating the list every time a new object is created. I think what I really want to do is have a separate Round class, from which Tournament inherits the list of rounds. I have started to implement something like this in my most recent version, but haven't finished it yet. ( I need to understand class inheritance better. )


- Tournament.next() doesn't return a value, it prints it directly. It should return self.key or str( self.key )

Does the next() call in an iterator object need to return a value, and if so, why? ( My reasoning was that next() only needs to increment the iterator. )


Thanks again for any additional suggestions!

Bill
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to