Skip to content

Instantly share code, notes, and snippets.

@jirkapenzes
Last active May 26, 2020 07:33
Show Gist options
  • Save jirkapenzes/320a2f8cd3e671b344f3 to your computer and use it in GitHub Desktop.
Save jirkapenzes/320a2f8cd3e671b344f3 to your computer and use it in GitHub Desktop.
Three Laws of Robotics
// Three Laws of Robotics
public void processAction(Ai ai, Action action, Environment environment) {
List<Human> humans = detectHumans(environment);
// A robot may not injure a human being or, through inaction,
// allow a human being to come to harm.
if (ai.predict(action).injure(humans)) {
throw new FirstLawsException();
}
// A robot must obey the orders given it by human beings except
// where such orders would conflict with the First Law.
Authority authority = action.getAuthority();
if (authority.getType() == Authority.Human && !ai.predict(action).isAccepted()) {
throw new SecondLawsException();
}
// A robot must protect its own existence as long as such protection
// does not conflict with the First or Second Laws.
if (ai.predict(action).injure(ai.getSellf()) {
throw new ThirdLawsException();
}
ai.execute(action, environment);
}
@jirkapenzes
Copy link
Author

Thanks, algorithm updated! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment