Permalink
Browse files

Initial upload

  • Loading branch information...
0 parents commit 2b3bfa5ed04207a3c9808984eae6c2fe49bdcc44 @Teifion committed Sep 4, 2013
@@ -0,0 +1,33 @@
+def includeme(config):
+ from .views import (
+ general,
+ game,
+ )
+
+ # General views
+ config.add_route('odummo.menu', '/menu')
+ config.add_route('odummo.stats', '/stats')
+ config.add_route('odummo.head_to_head_stats', '/head_to_head_stats')
+ config.add_route('odummo.preferences', '/preferences')
+
+ config.add_view(general.menu, route_name='odummo.menu', renderer='templates/general/menu.pt', permission='loggedin')
+ config.add_view(general.stats, route_name='odummo.stats', renderer='templates/general/stats.pt', permission='loggedin')
+ config.add_view(general.preferences, route_name='odummo.preferences', renderer='templates/general/preferences.pt', permission='loggedin')
+ config.add_view(general.head_to_head_stats, route_name='odummo.head_to_head_stats', renderer='templates/general/head_to_head_stats.pt', permission='loggedin')
+
+ # Game views
+ config.add_route('odummo.new_game', '/new_game')
+ config.add_route('odummo.rematch', '/rematch/{game_id}')
+
+ config.add_route('odummo.view_game', '/game/{game_id}')
+ config.add_route('odummo.make_move', '/make_move/{game_id}')
+ config.add_route('odummo.matchmake', '/matchmake')
+
+ config.add_view(game.new_game, route_name='odummo.new_game', renderer='templates/game/new_game.pt', permission='loggedin')
+ config.add_view(game.rematch, route_name='odummo.rematch', renderer='string', permission='loggedin')
+
+ config.add_view(game.view_game, route_name='odummo.view_game', renderer='templates/game/view_game.pt', permission='loggedin')
+ config.add_view(game.make_move, route_name='odummo.make_move', renderer='string', permission='loggedin')
+ config.add_view(general.matchmake, route_name='odummo.matchmake', renderer='templates/general/matchmake.pt', permission='loggedin')
+
+ return config
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,39 @@
+class AUser(object):
+ """A simple object to provide an interface into whatever your system User object is.
+ It allows us to use property names within the Odummo framework without having
+ to know what your User object uses."""
+
+ def __init__(self, request_object):
+ super(AUser, self).__init__()
+
+ if type(request_object) == dict:
+ return self.__from_dict(request_object)
+
+ user_object = config['get_user_func'](request_object)
+ self.id = getattr(user_object, config['user.id_property'])
+ self.name = getattr(user_object, config['user.name_property'])
+
+ def __from_dict(self, dict_oject):
+ self.id = dict_oject['id']
+ self.name = dict_oject['name']
+
+config = {
+ "layout": "../templates/default_layout.pt",
+ "DBSession": None,
+ "User": None,
+ "use_achievements": False,
+
+ "get_user_func": lambda r: KeyError("No function exists to get the user"),
+ "get_user": AUser,
+}
+
+# This is a copy of how I'm setting up my Odummo configuration
+# from .games import odummo
+# config.include(odummo, route_prefix="odummo")
+# odummo.config.config['layout'] = '../../../templates/layouts/viewer.pt'
+# odummo.config.config['DBSession'] = DBSession
+# odummo.config.config['User'] = models.User
+
+# odummo.config.config['get_user_func'] = lambda r: r.user
+# odummo.config.config['user.id_property'] = "id"
+# odummo.config.config['user.name_property'] = "name"
No changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
+"""
+This module contains all the functions that interact with the database.
+
+All should be considered impure.
+"""
@@ -0,0 +1,4 @@
+"""
+This module contains all functions relating to the rules of a game, but not
+nessesarily the running of a game itself.
+"""
@@ -0,0 +1,50 @@
+from sqlalchemy import (
+ Column,
+ Boolean,
+ Integer,
+ String,
+ ForeignKey,
+ DateTime,
+)
+
+# You will need to point this to wherever your declarative base is
+from ...models import Base
+
+class OdummoProfile(Base):
+ __tablename__ = 'odummo_profiles'
+ user = Column(Integer, ForeignKey("users.id"), nullable=False, index=True, primary_key=True)
+
+ preferred_colour = Column(Boolean, default=False)
+
+ matchmaking = Column(Boolean, nullable=False, default=False)
+ last_move = Column(DateTime, default=False)
+
+ wins = Column(Integer, default=0, nullable=False)
+ losses = Column(Integer, default=0, nullable=False)
+
+class OdummoGame(Base):
+ __tablename__ = 'odummo_games'
+ id = Column(Integer, primary_key=True)
+ turn = Column(Integer)
+
+ started = Column(DateTime, nullable=False)
+
+ player1 = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
+ player2 = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
+
+ winner = Column(Integer, ForeignKey("users.id"), nullable=True)
+
+ current_state = Column(String, nullable=False, default=' '*64)
+
+ rematch = Column(Integer, ForeignKey("odummo_games.id"))
+ source = Column(Integer, ForeignKey("odummo_games.id"))
+
+class OdummoMove(Base):
+ __tablename__ = 'odummo_moves'
+ id = Column(Integer, primary_key=True)
+
+ game = Column(Integer, ForeignKey("odummo_games.id"), nullable=False)
+ player = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
+
+ move = Column(Integer, nullable=False)
+ timestamp = Column(DateTime, nullable=False)
@@ -0,0 +1,3 @@
+Written for use in a system at work. It builds off the stats, matchmaking and general model of Wordy2 but is intended to add an AI opponent as an option.
+
+This software is released under a BSD license (do what you want with it but I'm not to blame for anything that happens as a result).
@@ -0,0 +1,50 @@
+BEGIN;
+
+CREATE TABLE odummo_profiles (
+ "user" INTEGER NOT NULL,
+ matchmaking BOOLEAN NOT NULL,
+ last_move TIMESTAMP WITHOUT TIME ZONE,
+
+ wins INTEGER NOT NULL,
+ losses INTEGER NOT NULL,
+
+ PRIMARY KEY ("user"),
+ FOREIGN KEY("user") REFERENCES users (id)
+);
+CREATE INDEX ix_odummo_profiles_user ON odummo_profiles ("user");
+
+CREATE TABLE odummo_games (
+ id SERIAL NOT NULL,
+ turn INTEGER,
+ started TIMESTAMP WITHOUT TIME ZONE NOT NULL,
+ player1 INTEGER NOT NULL,
+ player2 INTEGER NOT NULL,
+ winner INTEGER,
+ overall_state VARCHAR NOT NULL,
+ current_state VARCHAR NOT NULL,
+ active_board INTEGER NOT NULL,
+ rematch INTEGER,
+ source INTEGER,
+ PRIMARY KEY (id),
+ FOREIGN KEY(player1) REFERENCES users (id),
+ FOREIGN KEY(player2) REFERENCES users (id),
+ FOREIGN KEY(winner) REFERENCES users (id),
+ FOREIGN KEY(rematch) REFERENCES odummo_games (id),
+ FOREIGN KEY(source) REFERENCES odummo_games (id)
+);
+CREATE INDEX ix_odummo_games_player2 ON odummo_games (player2);
+CREATE INDEX ix_odummo_games_player1 ON odummo_games (player1);
+
+CREATE TABLE odummo_moves (
+ id SERIAL NOT NULL,
+ game INTEGER NOT NULL,
+ player INTEGER NOT NULL,
+ move INTEGER NOT NULL,
+ timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL,
+ PRIMARY KEY (id),
+ FOREIGN KEY(game) REFERENCES odummo_games (id),
+ FOREIGN KEY(player) REFERENCES users (id)
+);
+CREATE INDEX ix_odummo_moves_player ON odummo_moves (player);
+
+COMMIT;
No changes.
Binary file not shown.
No changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
+"""
+Views relating to games of Othello.
+"""
@@ -0,0 +1,3 @@
+"""
+Views related to the system that don't involve playing the game itself.
+"""

0 comments on commit 2b3bfa5

Please sign in to comment.