Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce Player API #114

Merged
merged 4 commits into from
May 16, 2018
Merged

Enforce Player API #114

merged 4 commits into from
May 16, 2018

Conversation

olistic
Copy link
Owner

@olistic olistic commented May 16, 2018

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
Copy link

codecov-io commented May 16, 2018

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% <ø> (ø) ⬆️
packages/warriorjs-abilities/src/listen.js 100% <100%> (ø) ⬆️
packages/warriorjs-units/src/Sludge.js 100% <100%> (ø) ⬆️
packages/warriorjs-core/src/Unit.js 100% <100%> (ø) ⬆️
packages/warriorjs-abilities/src/look.js 100% <100%> (ø) ⬆️
packages/warriorjs-core/src/Position.js 100% <100%> (ø) ⬆️
packages/warriorjs-core/src/Space.js 100% <100%> (ø) ⬆️
packages/warriorjs-units/src/Archer.js 100% <100%> (ø) ⬆️
packages/warriorjs-abilities/src/feel.js 100% <100%> (ø) ⬆️
packages/warriorjs-core/src/Level.js 100% <100%> (ø) ⬆️
... 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.

The location of the space needs to be accessible (but not mutable) in
the Player API. The reason for this is because the player can pass the
space to other senses, that then use its location. This solution isn't
perfect, but it doesn't hurt. Should revisit if more things "need" to
be added to the Player API in the future.
A turn is now a regular JavaScript Object instead of an instance of a
class, and has only the methods that belong to the Player API.
@olistic olistic merged commit 4bbc1a7 into master May 16, 2018
@olistic olistic deleted the enforce-player-api branch May 16, 2018 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants