[Tutor] GoFish

Russell Bungay rab121@york.ac.uk
Sat, 11 May 2002 17:08:46 +0100


Hello Again,

As promised here are my comments on my code.  

General:

Validation - there is none, it is very easy to break the script by
entering false values in any number of places.
Features - lots of unimplemented features, some already have anchors in
code, I'll point them out.
Commenting - poor and lacking, no doc strings.

>#
>#gofish.py
>#

<snip>

class GoFish:

<snip __init__>
<snip new>

>    def create(self, options=None):
<snip>

>            else:
>                level = 'AI' + str(options[p][0])
>                self.fishers[p] = eval('players.' + level + '(options[p][1])')

This will let me slip in extra (planned) AI levels at a later date by
simply subclassing further in players.py.

Is there a nicer way than using eval?  I don't like it much, not sure
why, it just seems wrong.

<snip>

>        os.system('cls')

Needs rewriting for portability.
        
>    def createopt(self):
>
>        print 'opt'

When implemented, this will allow the starting of a game from options
gained from inquisiting.

>    def mainloop(self,start,human):
>
>        fish = start
>        num = len(self.fishers)
>
>        while len(self.fishers[human].hand) > 0:
>                
>                if fish not in self.out:
>                    fish = self.turn(fish,human)
>                elif len(self.out) == len(self.fishers) - 1:
>                    print 'cheese'
>                else:
>                    for f in self.fishers:
>                        if f not in self.out:
>                            fish = f
>                    fish = self.turn(fish,human)
>                
>                for p in self.fishers:
>                    if len(self.fishers[p].hand) == 0 and p not in self.out:
>                        print 'Well done ' + self.fishers[p].name + ' you finished in place number ' + str(len(self.out) + 1)
>                        self.out.append(p)
>                
>        raw_input()
>        self.quit()
 
The whole checking for game finishing seems a bit of a fudge to me, but
I just couldn't think of a more elagant way of coding it...

                       
>    def turn(self, fish, human):

<snip interface building>
<snip AI play>

>                    for player in self.fishers:
>                        if 'update' in dir(player):
>                            player.update()
This is for unimplemented higher AI levels which will track where cards
are.

<snip human play>            

>    def pref(self):
>
>        print 'pref'

Will allow easy access to preference in settings file.

>    def quit(self):
>
>        sys.exit()

Is this the best/cleanest way to quit a script?  I can find no other...

<snip settings file building>
<snip other modules>

Thankyou very much,

Russell
--
http://www.bigmaddrongo.com
President of York University Trampoline Club:
http://york.trampolining.net
Chair of The York Glee Singers:
http://www.gleesingers.co.uk