Show ComputerReferee.java syntax highlighted
package geronimo.hoshigo.model.external;
import geronimo.hoshigo.model.game.AbstractReferee;
import geronimo.hoshigo.model.game.Game;
import geronimo.hoshigo.model.game.Move;
import geronimo.hoshigo.model.game.Score;
import java.util.Set;
public class ComputerReferee extends AbstractReferee
{
// programme attaché au go ProgramPlayer
public final GoProgram program;
private String name;
/**
* Constructeur
* @param program programme de go attaché à l'arbitre
*/
public ComputerReferee(GoProgram program)
{
super();
this.program = program;
}
/* (non-Javadoc)
* @see geronimo.hoshigo.model.game.AbstractReferee#start()
*/
public synchronized void start()
{
super.start();
try
{
this.program.launchProgram();
this.name = this.getName();
}
catch (GoProgramException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected Score getScore()
{
try
{
return this.program.getScore();
}
catch (GoProgramException e)
{
// si la partie est en train de se destroy
// alors il est normal de recevoir cette exception
// donc pas de stack trace
if (this.program.programProcess == null)
{
return null;
}
else
{
e.printStackTrace();
return null;
}
}
}
/**
*
*/
protected Set<Move> getLegalMoves()
{
try
{
this.program.synchronizeWithGame(this.game);
return this.program.getLegalMovesFor(this.game.getCurrentPlayer()
.getColor());
}
catch (GoProgramException e)
{
// si la partie est en train de se destroy
// alors il est normal de recevoir cette exception
// donc pas de stack trace
if (this.program.programProcess == null)
{
return null;
}
else
{
e.printStackTrace();
return null;
}
}
}
public String getName()
{
if (this.name != null)
{
return this.name;
}
else
{
try
{
this.name = this.program.getProgramName();
return this.name;
}
catch (GoProgramException e)
{
e.printStackTrace();
}
return "unknown";
}
}
public boolean isHuman()
{
return false;
}
public void gameEnded(Game game, Score score)
{
}
public void destroy()
{
super.destroy();
this.program.killProgram();
}
}
See more files for this project here