prantlf/mau-mau

View on GitHub
src/engine/players/SmartComputer.js

Summary

Maintainability
F
1 wk
Test Coverage

Function suggestCard has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

function suggestCard(availableCards, playableCards) {
  // Decomposition operation should not increase the statement count,
  // moving handling of sevens and aces to a separate method would
  // make the code less legible.
  /*eslint max-statements: [2, 20]*/
Severity: Minor
Found in src/engine/players/SmartComputer.js - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function suggestCard has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function suggestCard(availableCards, playableCards) {
  // Decomposition operation should not increase the statement count,
  // moving handling of sevens and aces to a separate method would
  // make the code less legible.
  /*eslint max-statements: [2, 20]*/
Severity: Minor
Found in src/engine/players/SmartComputer.js - About 1 hr to fix

    Function getAceCoverCount has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function getAceCoverCount(ace, availableCards) {
      var otherCards = availableCards.filter(function (card) {
            return card !== ace;
          }),
          // Check if the ace can be covered by a card, which lets
    Severity: Minor
    Found in src/engine/players/SmartComputer.js - About 1 hr to fix

      Function getSevenCoverCount has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getSevenCoverCount(seven, availableCards) {
        var otherCards = availableCards.filter(function (card) {
              return card !== seven;
            }),
            // Check if the seven can be covered by a card, which lets
      Severity: Minor
      Found in src/engine/players/SmartComputer.js - About 1 hr to fix

        Function suggestSuit has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function suggestSuit(chosenCard, availableCards) {
          // Cards remaining in hand after playing the queen
          var otherCards = availableCards.filter(function (card) {
                return card !== chosenCard.card;
              }),
        Severity: Minor
        Found in src/engine/players/SmartComputer.js - About 1 hr to fix

          Function getSevenCoverCount has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          function getSevenCoverCount(seven, availableCards) {
            var otherCards = availableCards.filter(function (card) {
                  return card !== seven;
                }),
                // Check if the seven can be covered by a card, which lets
          Severity: Minor
          Found in src/engine/players/SmartComputer.js - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function getAceCoverCount has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          function getAceCoverCount(ace, availableCards) {
            var otherCards = availableCards.filter(function (card) {
                  return card !== ace;
                }),
                // Check if the ace can be covered by a card, which lets
          Severity: Minor
          Found in src/engine/players/SmartComputer.js - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          function getAceCoverCount(ace, availableCards) {
            var otherCards = availableCards.filter(function (card) {
                  return card !== ace;
                }),
                // Check if the ace can be covered by a card, which lets
          Severity: Major
          Found in src/engine/players/SmartComputer.js and 1 other location - About 2 days to fix
          src/engine/players/SmartComputer.js on lines 186..227

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 369.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          function getSevenCoverCount(seven, availableCards) {
            var otherCards = availableCards.filter(function (card) {
                  return card !== seven;
                }),
                // Check if the seven can be covered by a card, which lets
          Severity: Major
          Found in src/engine/players/SmartComputer.js and 1 other location - About 2 days to fix
          src/engine/players/SmartComputer.js on lines 240..281

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 369.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          function divideCardRanks(playableCards) {
            var queens = [], sevens = [], aces = [],
                otherCards = playableCards.filter(function (card) {
                  switch (card.rank) {
                  case Ranks.queen:
          Severity: Major
          Found in src/engine/players/SmartComputer.js and 1 other location - About 5 hrs to fix
          src/engine/players/AverageComputer.js on lines 98..115

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 149.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

                nextChosenCard = nextChosenCards.find(function (card) {
                  return card.rank === Ranks.seven;
                }) || nextChosenCards.find(function (card) {
                  return card.rank === Ranks.ace;
                }) || nextChosenCards.find(function (card) {
          Severity: Major
          Found in src/engine/players/SmartComputer.js and 1 other location - About 3 hrs to fix
          src/engine/players/AverageComputer.js on lines 85..94

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 108.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            if (!chosenCard.card && aces.length) {
              chosenCard = getMaximumCoveredAce.call(this, aces, availableCards);
              // If there are just two players, avoid an immediate drawing a single
              // card to let the other player play; do not worry with more players
              if (!chosenCard.card && this.game.activePlayers.length > 2) {
          Severity: Major
          Found in src/engine/players/SmartComputer.js and 1 other location - About 2 hrs to fix
          src/engine/players/SmartComputer.js on lines 59..69

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 75.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            if (sevens.length) {
              chosenCard = getMaximumCoveredSeven.call(this, sevens, availableCards);
              // If there are just two players, avoid "being fed back" two cards
              // by another seven placed on ours; do not worry with more players
              if (!chosenCard.card && this.game.activePlayers.length > 2) {
          Severity: Major
          Found in src/engine/players/SmartComputer.js and 1 other location - About 2 hrs to fix
          src/engine/players/SmartComputer.js on lines 72..82

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 75.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          function getMaximumCoveredAce(aces, availableCards) {
            // Compute which ace can help us shed the maximum card count
            var covers = aces.map(ace => {
              return {
                card: ace,
          Severity: Major
          Found in src/engine/players/SmartComputer.js and 1 other location - About 1 hr to fix
          src/engine/players/SmartComputer.js on lines 175..184

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 64.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          function getMaximumCoveredSeven(sevens, availableCards) {
            // Compute which seven can help us shed the maximum card count
            var covers = sevens.map(seven => {
              return {
                card: seven,
          Severity: Major
          Found in src/engine/players/SmartComputer.js and 1 other location - About 1 hr to fix
          src/engine/players/SmartComputer.js on lines 229..238

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 64.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

                nextChosenCardsPerSuit = Object.keys(Suits)
                  .map(suit => {
                    var playableCards = this.game.rules.pickPlayableCardsForSuit(
                          otherCards, suit);
                    return suggestCard.call(this, otherCards, playableCards);
          Severity: Major
          Found in src/engine/players/SmartComputer.js and 1 other location - About 1 hr to fix
          src/engine/players/AverageComputer.js on lines 75..80

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 60.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status