Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4110758
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:58:32+00:00 2026-05-20T21:58:32+00:00

I’m working on a small webapp in Rails that simulates a score card for

  • 0

I’m working on a small webapp in Rails that simulates a score card for the board game Agricola.

The question is: What/How is the best (read: proper) way to model the score card in Rails?

Currently, I have a ScoreCard model which columns are the ‘categories’ that counts toward the final score. It’s something like:

class ScoreCard < ActiveRecord::Base
  validates :field_tile,
            :pasture,
            :grain,
            :vegetable,
            :sheep,
            :wild_boar,
            :cattle,
            :unused_space,
            :fenced_stable,
            :clay_room,
            :stone_room,
            :family_member,
            :victory_point,
            :bonus_point,
            :numericality => true
end

The scoring mechanism is described in this game manual (see the ‘Scoring’ section on page 8). Here’s a snippet from the manual:

Fields: All field tiles that are on
the player’s farmyard are scored,
regardless of whether they are
currently fallow or are sown. A player
with 0 or 1 fields loses 1 point. Each
field after the first scores 1 point,
up to a maximum of 4 points for 5 or
more fields. Players score -1/1/2/3/4
points for 0-1/2/3/4/5+ fields.

Pastures: Points are awarded for
fenced areas (“Pastures”), not for the
number of farmyard spaces that are
fenced in (“Pasture spaces”). The size
of the individual pastures is
irrelevant. A player with no pastures
loses 1 point. Each pasture scores 1
point, up to a maximum of 4 points for
4 or more pastures. Players score
-1/1/2/3/4 points for 0/1/2/3/4+ pastures.

Since each ‘category’ (pasture, grain, etc) has different scoring mechanism, I defined some private methods that returns the final score of each ‘category’:

private
  def calculate_field_tiles_score
    case field_tile
      when 0..1 then -1
      when 2..4 then field_tile - 1
      else 4
    end 
  end

  def calculate_pasture_score
    # return proper score
  end

I also have a (public) calculate method in the model which calculates the final score:

def calculate
  calculate_field_tiles_score +
  calculate_pasture_score +
  # ... other scores
end

Is this a good approach? I’m not sure what the proper way of modelling it, but it doesn’t ‘feel right’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:58:33+00:00Added an answer on May 20, 2026 at 9:58 pm

    I’d go for something along the lines of:

    class Scorer
      def initialize(farmyard); @farmyard=farmyard; end
    end
    
    class FieldTilesScorer < Scorer
      def score
        case @farmyard.field_tile 
          #etc
        end
      end
    end
    
    class PasturesScorer < Scorer
       def score
         #return proper score
       end
    end
    

    and so on. Then when I want to score a farmyard, I’d do:

    [FieldTilesScorer, PastureScorer, ...].
      map{|s| s.new(@farmyard).score}.
      inject(0){|m,r| m+r}
    

    This way you’re modelling each category as its own class, and it’s easy to add rules which depend on any combination of state in the farmyard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.