GithubHelp home page GithubHelp logo

bowling-kata's Introduction

bowling-kata

保龄球游戏

创建一个程序,根据给定的击球情况,得出游戏的总分。 该程序不会执行以下操作:

  • 我们不会检查有效的击球数。
  • 我们不会检查击球的次数和回合是否正确。
  • 我们不会提供中间回合的分数。

根据应用程序的不同,这可能是定义完整故事的有效方法,也可能不是有效的方法,但是我们在这里这样做是为了保持轻量级的kata。 我想您会发现,如果确实需要上述改进,这些改进将很容易实现。 我们可以简要总结一下这种保龄球的计分规则:

  • 每场比赛包括十个回合,或10个“frames”对投球手来说。
  • 在每一回合中,投球手最多尝试两次击倒所有的球瓶。
  • 如果两次尝试都未能将其全部击倒,则该回合的得分就是两次尝试中击倒球瓶的总数。
  • 如果在两次尝试中全部击倒,则称为“spare”,得分为10加上下一掷(下一回合)击倒的球瓶数。
  • 如果在首次尝试中击倒所有球瓶,这称为“strike”。该回合结束,得分为10分,再加上接下来两次击倒的球瓶总数。
  • 如果最后(第十个)回合中得到spare或strike,则投球手可以获得掷一次(spare一次)或两次(strike两次)奖励球。 这些奖励击倒的球瓶数被视为同一回合的一部分。如果奖励次数中投掷击倒了所有的球瓶,则该过程不会重复:奖励投掷仅用于计算最后一回合的得分。
  • 游戏分数是所有回合分数的总和。

线索

使这场比赛有趣的原因是spare和strike得分的前瞻性。 在我们掷出spare或strike时,我们无法计算该回合的得分:我们必须等待一个或者两个回合才能计算出额外的奖励分。

推荐的测试用例

"X" 表示strike "/"表示spare "-"表示未击中
X X X X X X X X X X X X (12 rolls: 12 strikes) = 10 frames * 30 points = 300
9- 9- 9- 9- 9- 9- 9- 9- 9- 9- (20 rolls: 10 pairs of 9 and miss) = 10 frames * 9 points = 90
5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/5 (21 rolls: 10 pairs of 5 and spare, with a final 5) = 10 frames * 15 points = 150

bowling-kata's People

Contributors

ylliu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.