browser-go-api/models/Game.py

65 lines
2.3 KiB
Python
Raw Normal View History

2019-10-04 22:00:47 +00:00
from app import db, ma
2019-10-10 21:57:29 +00:00
from marshmallow import fields
2019-10-02 03:09:46 +00:00
import enum
2019-10-10 21:57:29 +00:00
from models.User import user_schema
2019-10-02 03:09:46 +00:00
class Game(db.Model):
2019-10-02 20:55:09 +00:00
__tablename__ = "games"
__table_args__ = {'extend_existing': True}
2019-10-10 21:57:29 +00:00
class Players(enum.Enum):
BLACK = "The player taking black stones"
WHITE = "The player taking white stones"
VOID = "The game was a draw or voided"
class WinType(enum.Enum):
DRAW = "The game is a draw"
RESIGN = "The game ended in resignation"
SCORE = "The game ended by counting points"
TIME = "The game ended in loss by time out"
VOID = "The game was suspended"
2019-10-02 03:09:46 +00:00
2019-10-02 20:55:09 +00:00
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
2019-10-02 03:09:46 +00:00
date = db.Column(db.DateTime())
2019-10-02 20:55:09 +00:00
komi = db.Column(db.Numeric(2,1), nullable=False)
handicap = db.Column(db.Integer, nullable=False)
board_size = db.Column(db.Integer, nullable=False)
2019-10-02 03:09:46 +00:00
win_type = db.Column(db.Enum(WinType))
winner = db.Column(db.Enum(Players))
2019-10-02 20:55:09 +00:00
score = db.Column(db.Numeric(2,1))
2019-10-02 03:09:46 +00:00
white_captures = db.Column(db.Integer)
black_captures = db.Column(db.Integer)
application = db.Column(db.String(40))
application_version = db.Column(db.String(20))
event = db.Column(db.String(40))
name = db.Column(db.String(40))
description = db.Column(db.String(200))
2019-10-02 20:55:09 +00:00
round = db.Column(db.Integer)
2019-10-02 03:09:46 +00:00
# foreign keys
2019-10-02 20:55:09 +00:00
game_room = db.Column(db.Integer, db.ForeignKey("game_rooms.id"))
time_settings = db.Column(db.Integer, db.ForeignKey("time_settings.id"))
player_black = db.Column(db.Integer, db.ForeignKey("users.id"))
player_white = db.Column(db.Integer, db.ForeignKey("users.id"))
2019-10-02 03:09:46 +00:00
2019-10-10 21:57:29 +00:00
def __init__(self, name, description, board_size, game_room, player_white, komi=0.5, handicap=0, time_settings=1):
self.name = name
self.description = description
self.board_size = board_size
self.game_room = game_room
self.player_white = player_white
self.komi = komi
self.handicap = handicap
self.time_settings = time_settings
print('did it')
class GameSchema(ma.ModelSchema):
id = fields.Int()
name = fields.Str()
description = fields.Str()
boardSize = fields.Int()
player = fields.Nested(user_schema)
game_schema = GameSchema()
games_schema = GameSchema(many=True)