browser-go-api/models/Move.py

44 lines
1.4 KiB
Python
Raw Permalink Normal View History

2019-10-04 22:00:47 +00:00
from app import db, ma
2019-10-02 03:24:15 +00:00
import enum
2019-10-02 20:55:09 +00:00
class Move(db.Model):
__tablename__ = "moves"
__table_args__ = {'extend_existing': True}
2019-10-02 03:24:15 +00:00
2019-10-10 21:57:29 +00:00
class Players(enum.Enum):
BLACK = "The player taking black stones"
WHITE = "The player taking white stones"
2019-10-02 20:55:09 +00:00
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
2019-10-02 03:24:15 +00:00
player = db.Column(db.Enum(Players))
x_point = db.Column(db.Integer)
y_point = db.Column(db.Integer)
move_number = db.Column(db.Integer)
2019-10-02 23:48:10 +00:00
is_pass = db.Column(db.Boolean, nullable=False, default=False)
is_main = db.Column(db.Boolean, nullable=False, default=True)
2019-10-02 03:24:15 +00:00
# foreign keys
2019-10-13 17:15:03 +00:00
game = db.Column(db.ForeignKey("games.id"), nullable=False)
2019-10-11 00:52:43 +00:00
preceding_move = db.Column(db.Integer, db.ForeignKey("moves.id"))
2019-10-11 00:41:49 +00:00
2019-10-13 23:08:05 +00:00
def __init__(self, game_id, player, x_point, y_point, move_number, is_pass=True, is_main=True, preceding_move=None):
self.game = game_id
if player == 'black':
self.player = 'BLACK'
else:
self.player = 'WHITE'
self.x_point = x_point
self.y_point = y_point
self.move_number = move_number
self.is_pass = is_pass
self.is_main = is_main
self.preceding_move = preceding_move
Move.succeeding_moves = db.relationship(
'Move',
lazy='subquery',
backref=db.backref('moves', lazy=True),
remote_side=Move.id
)