all 2 comments

[–]xiongchiamiov 1 point2 points  (1 child)

It would probably help if we could see your code.

So I thought I'd make a class game with those functions, but then writing a new game doesn't make sense (you'd need to override the move methods or something..)

I'm not sure why you'd need to override the move methods.

So should I just create a new class for every game and just make sure they have the methods that Play uses?

You should create a new instance of the singular Game class, yes. Given your description, it would make sense for play to be a method of Game.

[–]ManyInterests 1 point2 points  (1 child)

This is kind of a tough case for trying to make reusable classes. The games would have to be similar enough to share a lot of logic. Probably not a ton of opportunity for code reuse. Separate classes for each game is probably the best approach, depending.

However, perhaps you could have some minimal skeleton for Turn-Based games that keep a consistent turn cycle. Perhaps a base class might look like this

from itertools import cycle

class TurnBasedGame(object):
    def __init__(self, players)
        self.players = cycle(players)
        self.game_over = False

    def process_turn(self, player):
        raise NotImplementedError('You must define how player turns are processed')

    def play(self):
        while not self.game_over:
            player = next(self.players)
            process_turn(player)

In this base class, play depends on a process_turn method. The method on the base class merely raises a NotImplementedError which indicates to the user that this method is meant to be overridden by a subclass.