Skip to content

Commit

Permalink
TTT Turns added
Browse files Browse the repository at this point in the history
  • Loading branch information
reututy committed Sep 3, 2017
1 parent a8520c4 commit 58c81af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.SingleResourceBProgram;
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.listeners.StreamLoggerListener;

/**
* For Gaming mode change isModelChecking to false.
* For Model Checking mode change isModelChecking to true.
* @author reututy
*/
class TicTacToeGameMain extends JFrame {

// GUI for interactively playing the game
Expand Down
105 changes: 29 additions & 76 deletions src/test/resources/BPJSTicTacToe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ importPackage(Packages.il.ac.bgu.cs.bp.bpjs.TicTacToe.events);

bp.log.info('Tic-Tac-Toe - Let the game begin!');

var countX = 0;
var countO = 0;
var SquareCount = 0;

// //GameRules
//GameRules
//
// /*
// * Block further marking of a square already
Expand All @@ -16,7 +15,6 @@ var countO = 0;
//

function addSquareBThreads(row, col) {


bp.registerBThread("ClickHandler(" + row + "," + col + ")", function() {
while (true) {
Expand All @@ -41,9 +39,30 @@ function addSquareBThreads(row, col) {
bsync({
block : [ X(row, col), O(row, col) ]
});
SquareCount++;
}
});

bp.registerBThread("EnforceTurns(" + row + "," + col + ")", function() {
while (true) {
var e = bsync({
waitFor : [ X(row, col), O(row, col) ]
});

var wt = (e.equals(X(row, col))) ? O(row, col) : X(row, col) ;

bp.log.info("It's "+ wt.name + "Turn");

bsync({
block : [ bp.Event(wt) ]
});

delete wt;
delete e;
}
});


}

for (var r = 0; r < 3; r++) {
Expand All @@ -52,76 +71,10 @@ for (var r = 0; r < 3; r++) {
}
}

//bp.registerBThread("DetectDraw(" + row + "," + col + ")", function() {
// while (true) {
// if(SquareCount == 9)
// bp.log.info("Game Over!");
//
// /*
// * Alternately block O moves while waiting
// * for X moves, and vice versa (we assume that X always plays first).
// */
// bp.registerBThread("EnforceTurns", function() {
// while (true) {
//
// }
// });
//
// /*
// * Wait for placement of three X marks
// * in a line and request XWin.
// * To-do: Priority-------------------------------------
// */
// bp.registerBThread("DetectXWin", function() {
// while (true) {
// bsync({
// waitFor : [ bp.Event("3XRow"),
// bp.Event("3XCol"),
// bp.Event("3XDia") ]
// }).name;
//
// bsync({
// request : bp.Event("XWin")
// });
// }
// });
//
// /*
// * Wait for placement of three O marks
// * in a line and request OWin.
// * To-do: Priority-------------------------------------
// */
// bp.registerBThread("DetectOWin", function() {
// while (true) {
// bsync({
// waitFor : [ bp.Event("3ORow"),
// bp.Event("3OCol"),
// bp.Event("3ODia") ]
// }).name;
//
// bsync({
// request : bp.Event("OWin")
// });
// }
// });
//
// /*
// * Wait for nine moves and request draw event.
// */
// bp.registerBThread("DetectDraw", function() {
// while (true) {
// if ( countX+countO === 9 ) {
// // TODO what?
// }
//
// }
// });
//
// //Tactics - DefaultOMoves
//
//
//
//
//
//
// //Environment
//
//
//
//
// }
//});

0 comments on commit 58c81af

Please sign in to comment.