->Terry<- wrote:

> To anyone willing to take the time to have a
> look at the code and offer any advice or
> suggestions, I would be much appreciative.
> I'm looking for code suggestions rather than
> game-play suggestions, although I'm open to
> any help.

A couple of notes after a quick look:

- As you note, def check_valid_jump(sel1, sel2) is really ugly. When I have 
code like this I look for a way to drive it from a table instead of a bunch of 
if/elif statements full of magic numbers. In this case it looks like you have 
one condition for each state. The conditions and results could be put in a list 
whose index is the state and whose values are the test values for sel1 and 
sel2. You would have a table that looks like this:
jump_table = [
  (1, 1, 4, 2),    # (state # sel1 and sel2 values to check for state, return 
value)
  (2, 1, 6, 3),
  # etc for all the tests
]

Then check_valid_jump() becomes
def check_valid_jump(sel1, sel2):
  for st, sel1value, sel2value, result in jump_table:
    if sel1 == sel1value and sel2 == sel2value:
      if state[st] == 1:
        return result
    break
  return 0

- get_button() could be similarly simplified, only you don't even need a table, 
you are just returning the number of the peg_coords that was clicked. This 
should work:

def get_button(click):
  for i, peg in peg_coords:
    if click in peg:
      return i+1
  return 0

> 
> I haven't got my head really wrapped around the
> OO stuff, so I'm thinking rewriting it using
> classes would make a good project to learn
> with. Is this the sort of thing that one would
> use classes for? Or is is better left as
> simple as possible?

I'm a believer in "as simple as possible". One of the strengths of Python is 
that you don't *have* to use classes if they are not called for. Maybe there is 
some benefit in using classes in your program, for example a peg class might 
simplify it, I'm not sure. This essay talks about some of the reasons you might 
want to introduce classes into a program:
http://personalpages.tds.net/~kent37/blog/stories/15.html
 
Kent

-- 
http://www.kentsjohnson.com

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

Reply via email to