virtual MovementResult QueryMove(std::string & buffer);
virtual void Message(const char * message) {Program::SendMessage(message);}
+ virtual void Pause() {Program::Pause();} //Hack wrapper
+ virtual void Continue() {Program::Continue();} //Hack wrapper
virtual bool Valid() const {return Program::Running();}
virtual MovementResult QueryMove(std::string & buffer) = 0;
virtual bool Valid() const {return true;}
+
+ virtual void Pause() {} // Hack function (AI_Controller ONLY will overwrite with wrapper to Program::Pause)
+ virtual void Continue() {} // Hack function (AI_Controller '' '' wrapper to Program::Continue)
+
const Piece::Colour colour;
std::string name;
#endif //BUILD_GRAPHICS
turn = Piece::RED;
-
+ blue->Pause();
+ red->Continue();
if (!Board::HaltResult(result))
{
result = CheckVictoryAttrition();
turn = Piece::BLUE;
-
+ red->Pause();
+ blue->Continue();
if (!Board::HaltResult(result))
{
result = CheckVictoryAttrition();
* The child process closes unused sides of the pipe, and then calls exec to replace itself with the AI program
* The parent process closes unused sides of the pipe, and sets up member variables - associates streams with the pipe fd's for convenience.
*/
-Program::Program(const char * executablePath) : input(NULL), output(NULL), pid(0)
+Program::Program(const char * executablePath) : input(NULL), output(NULL), pid(0), paused(false)
{
//See if file exists and is executable...
if (access(executablePath, X_OK) != 0)
}
+/**
+ * Forces the program to pause by sending SIGSTOP
+ * Program can be resumed by calling Continue() (which sends SIGCONT)
+ * @returns true if the program could be paused, false if it couldn't (probably because it wasn't running)
+ */
+bool Program::Pause()
+{
+ if (pid > 0 && kill(pid,SIGSTOP) == 0)
+ {
+ paused = true;
+ return true;
+ }
+ return false;
+}
+/**
+ * Causes a paused program to continue
+ * @returns true if the program could be continued, false if it couldn't (probably because it wasn't running)
+ */
+bool Program::Continue()
+{
+ if (pid > 0 && kill(pid,SIGCONT) == 0)
+ {
+ paused = false;
+ return true;
+ }
+ return false;
+}
+/**
+ * @returns true iff the program is paused
+ */
+bool Program::Paused() const
+{
+ return paused;
+}
/**