Sunday, 15 March 2015

java - Return Statements in a Finite State Machine -



java - Return Statements in a Finite State Machine -

could tell me purpose homecoming statement in finite state machine's state serves? illustration have code soccer player's state:

public class chaseball extends state<fieldplayer> { private static chaseball instance = new chaseball(); private chaseball() { } //this singleton public static chaseball instance() { homecoming instance; } @override public void enter(fieldplayer player) { player.steering().seekon(); } } @override public void execute(fieldplayer player) { //if ball within kicking range player changes state kickball. if (player.ballwithinkickingrange() && player.isreadyfornextkick()) { player.getfsm().changestate(kickball.instance()); return; } //if player closest player ball should maintain //chasing if (player.isclosestteammembertoball()) { player.steering().settarget(player.ball().pos()); return; } //if player not closest ball anymore, should homecoming //to home part , wait chance player.getfsm().changestate(returntohomeregion.instance()); } @override public void exit(fieldplayer player) { player.steering().seekoff(); } }

i wondering if explain purpose the homecoming keywords in first 2 if statements of execute() method serve? thanks

in case it's formatting alternative series of else if clauses. logically equivalent to

if (<condition>) { <code> } else if (<condition>) { <code> } else { <code> }

java return finite-state-machine

No comments:

Post a Comment