Last active
May 26, 2020 07:33
-
-
Save jirkapenzes/320a2f8cd3e671b344f3 to your computer and use it in GitHub Desktop.
Three Laws of Robotics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
Thanks, algorithm updated! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Second Law does not say that robot should listen ONLY to humans. SecondLawsException should be thrown when the action is result of an human order and it would violate the first law.