ruby on rails - Organising data for a football (soccer) management simulation -
i'm trying create online football (soccer) management game ruby on rails, , it's quite ambitious me i'm finding parts challenging. i've coded basic match engine, when comes tactics, lineups, formations, etc. i'm finding more difficult organise various data , create relations in activerecord. same applies league , cup systems.
i'll try provide brief overview here:
- a nation/club has first team , youth/u21 team
- a nation/club/team has players
- a nation/club/team has matches against others in league , cup systems
- a league system has 3 leagues in each division (pyramid system: 1 promoted, 3 relegated)
- a cup system has knockout matches (and mini-league group stages) including time , penalty shootouts
- a league/cup has rounds/match days each season
- a round/match day has matches
- a match has details e.g. scores/ratings
- a match has actions e.g. goal/assist
- a match has tactics/lineups each team e.g. formation/players
any ideas how best organise in models?
edit: i'm having trouble linking players matches (via lineups?). both teams need 11 of players selected play: 1 in goal , remaining 10 outfield players spread across defence/midfield/attack outfield positions, e.g. 4-4-2, etc. player 11 chosen play in midfield, player 9 in attack, player 1 in goal, etc. possible formations include 3-5-2, 3-4-3, 4-4-2, 4-5-1, 4-3-3, etc.
here's sample of schema i'm attempting use:
create_table "teams", force: :cascade |t| t.integer "nation_id" ... end create_table "players", force: :cascade |t| t.integer "nation_id" t.integer "team_id" ... end create_table "matches", force: :cascade |t| t.integer "home_team_id" t.integer "away_team_id" ... end create_table "lineups", force: :cascade |t| t.integer "match_id" t.integer "team_id" ... end create_table "formations", force: :cascade |t| t.string "name" ... end create_table "positions", force: :cascade |t| t.integer "formation_id" t.string "name" ... end
would work? i'm not sure if formations or positions tables neccessary, or if work.
this not rails question per se - general modelling question. there should large number of books, articles , tutorials on objectoriented modelling out there.
without going detail here:
- basically, did of work writing out list.
- every word substantive in description leads (candidate a) model. i.e.: nation, club, team, player, match, league-system, cup, league, division, match-day etc.
- draw in boxes (google "uml class diagram" if want fancy). boxes correspond files
app/models/*.rb
. - draw line between each of boxes have kind of relationship (a.k.a., association) between them.
- mark out how many of each can related (i.e., "each player can have 0 or 1 team", "each team can have many players" etc.). gives
has_many
,has_one
,belongs_to
associations.
at end, models trivial have actual rails class. example, "day" might or might not class-worthy (i.e., date attribute matches; if want associate more information day per se, or if want plan matches occur on same day without having actual date yet during planning phase, go ahead). of matter of style, opinion , experience, there no hard , fast rules here.
check out classical work "design patterns" the introduction modelling.
Comments
Post a Comment