olistic / warriorjs

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

Restrict space and turn to Player API #106

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 nor on the turn (passed to the playTurn() function) 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().isEnemy()) {
      // Instant kill.
      const enemy = warrior.feel().getUnit();
      enemy.health = 1;
      warrior.attack();
    } else {
      warrior.walk();
    }
  }
}

Closes #71

WIP

codecov-io commented 6 years ago

Codecov Report

Merging #106 into master will increase coverage by 0.07%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #106      +/-   ##
=========================================
+ Coverage   90.83%   90.9%   +0.07%     
=========================================
  Files          80      79       -1     
  Lines        1015    1023       +8     
  Branches      159     160       +1     
=========================================
+ Hits          922     930       +8     
  Misses         77      77              
  Partials       16      16
Impacted Files Coverage Ξ”
packages/warriorjs-core/src/Warrior.js 100% <ΓΈ> (ΓΈ) :arrow_up:
packages/warriorjs-abilities/src/look.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-core/src/Unit.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-abilities/src/listen.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-core/src/Position.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-abilities/src/feel.js 100% <100%> (ΓΈ) :arrow_up:
packages/warriorjs-core/src/Space.js 100% <100%> (ΓΈ) :arrow_up:

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 fbc5c10...22254a1. Read the comment docs.

olistic commented 6 years ago

Closing in favor of #114.