[Python Wpg] OO Python presentation proposal

syd at plug.ca syd at plug.ca
Mon May 1 17:17:50 EDT 2006


I have sketched out a rough outline of what I think might work for next
month's meeting. I welcome feedback on the design as well as on the
general approach to the topic.

I thought that since we had talked during the April meeting about
refactoring Starlanes-1.1 in a more object oriented way, that could form
the basis of the OO Python presentation. We'll take something we know
already (sort of) and  think about it in terms of objects.

I will need the help of others in validating my design and implementation,
so I'm going to sketch it here quickly and see what others think of the
general direction. As is usual during refactoring, I will try not to
introduce any new features -- only replicate perfectly behaviour of the
old version. The only exception to this is that I want to try to make the
game work as a server.

StarLane OO Design Overview
===========================

Class Universe represents the game board and initial values for various
game parameters. To demonstrate the object oriented principle of
inheritance, we will make Universe a subclass of (perhaps)
SimpleXMLRPCServer[1] for development into a networked, multi-player
environment. The Universe is composed of Cells.

Cells have 6 attributes:
- location (x, y)
- state (empty | start | new_base | established_company)
- up: returns the cell instance above, or None if there is no cell above
- down, left, right same as up except for direction

The Universe has the following attributes:

- A dictionary of cells keyed on a (x,y) tuple (as Jason suggested)
- max_x
- max_y
- max_turns
- max_stars
- size_x
- size_y
- current_player
- turn_counter
- create_stock: the amount of stock you get when you create a company
- dividend: percentage dividend at the beginning of every turn
- star_bonus: increase in value for proximity to star
- base_bonus: increase in value for each base
- base_cost: cost of adding a base
- displayStandings(): display the current standings of all players
- countPlayers(): returns the count of players
- nextTurn(): move the game one turn forward, change current player and
prompt for input
- cellsInState(state): how many cells on the board are in state state
- placeBase(location)
- placeCompany(location, company)


A Company has the following attributes:
- split_at: price at which the stock splits (class attribute only)
- name
- stock_value
- symbol
- active
- size
- stars: how many stars are near the company's base
- stockSplit(): perform a stock split if stock_value > split_at
- doMerger(): perform a merger with another company

A Player has the following methods and attributes:
- name
- cash
- stocks: a dictionary of the form: {stock_id: count}
- purchaseStock(company, amount): a player purchases stock from a company

[1] http://docs.python.org/lib/module-SimpleXMLRPCServer.html





More information about the Winnipeg mailing list