olistic / warriorjs

🏰 An exciting game of programming and Artificial Intelligence
https://warriorjs.com
MIT License
9.43k stars 490 forks source link

Enforce Player API #114

Closed olistic closed 6 years ago

olistic commented 6 years ago

With these changes, it's no longer possible to call methods on the spaces, units, or turn, that don't belong to the Player API.

Before this PR, a player could cheat by writing stuff like this:

class Player {
  playTurn(warrior) {
    if (warrior.feel().isUnit()) {
      const unit = warrior.feel().getUnit();
      unit.health = 1;
      warrior.attack(); // Instant kill!
    } else {
      warrior.walk();
    }
  }
}

Closes #71

codecov-io commented 6 years ago

Codecov Report

Merging #114 into master will increase coverage by 0.05%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #114      +/-   ##
==========================================
+ Coverage   90.76%   90.81%   +0.05%     
==========================================
  Files          80       79       -1     
  Lines        1007     1013       +6     
  Branches      156      157       +1     
==========================================
+ Hits          914      920       +6     
  Misses         77       77              
  Partials       16       16
Impacted Files Coverage Ξ”
packages/warriorjs-core/src/Warrior.js 100% <ΓΈ> (ΓΈ) :arrow_up:
packages/warriorjs-abilities/src/listen.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-units/src/Sludge.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-core/src/Unit.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-abilities/src/look.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-core/src/Position.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-core/src/Space.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-units/src/Archer.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-abilities/src/feel.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-core/src/Level.js 100% <100%> (ΓΈ) :arrow_up:
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data Powered by Codecov. Last update f8a0353...4ebe810. Read the comment docs.