// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
var documentObjectModel = null;
var socket = null;
var internetClient = null;
var application = null;
var messageBox = null;
var kayla = null;
// INCLUDE THE NECESSARY OBJECTS.
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Development) == "undefined") Development = new Object ();
Development . MessageBox = function ()
{
this . window = null;
this . initializedPredicate = 0;
this . initiate = function ()
{
this . initializedPredicate = 0;
this . recycleWindow ();
return;
};
this . initialize = function ()
{
var html;
this . finalize ();
this . initializedPredicate = 1;
this . recycleWindow ();
html = "";
html = html + "\n";
html = html + "\n";
html = html + "
\n";
html = html + "\n";
html = html + " \n";
html = html + "\n";
html = html + " MessageBox\n";
html = html + "\n";
html = html + " \n";
html = html + "\n";
html = html + " \n";
html = html + "\n";
html = html + " \n";
html = html + "\n";
html = html + " \n";
html = html + "\n";
html = html + " \n";
html = html + "\n";
html = html + " \n";
html = html + "\n";
html = html + " Message Box\n";
html = html + "\n";
html = html + "
\n";
html = html + "\n";
html = html + " \n";
html = html + "\n";
html = html + "
\n";
html = html + "\n";
html = html + " \n";
html = html + "\n";
html = html + " \n";
this . window = window . open ('', (new Date ()) . toString (), 'height = 300, menubar = 0, resizable = 1, scrollbars = 1, status = 0, toolbar = 0, width = 900');
this . window . document . writeln (html);
this . window . document . close ();
return;
};
this . finalize = function ()
{
this . initializedPredicate = 0;
this . recycleWindow ();
return;
}
this . recycleWindow = function ()
{
if (this . window != null)
this . window . close ();
this . window = null;
return;
};
this . getInitializedPredicate = function ()
{
if (this . initializedPredicate == 0 ) return (0);
if (this . window == null ) return (0);
if (typeof (this . window . existsPredicate) == "undefined" ) return (0);
return (1);
};
this . addType = function (type)
{
if (this . getInitializedPredicate () == 1)
if (typeof (this . window . addType) != "undefined")
this . window . addType (type);
return;
};
this . addMessage = function (type, text)
{
if (this . getInitializedPredicate () == 1)
if (typeof (this . window . addMessage) != "undefined")
this . window . addMessage (type, text);
return;
};
this . removeMessages = function ()
{
if (this . initializedPredicate == 1)
if (typeof (this . window . removeMessages) != "undefined")
this . window . removeMessages ();
return;
};
};
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Network) == "undefined") Network = new Object ();
Network . DocumentObjectModel = function ()
{
this . document = null;
this . getReleaseCode = function ()
{
return ("200608261504");
};
this . getSupportedPredicate = function ()
{
};
this . initialize = function ()
{
this . document = document;
};
this . appendNode = function (mainNode, appendageNode)
{
mainNode . appendChild (appendageNode);
};
this . clearNodes = function (node)
{
while (node . hasChildNodes ()) node . removeChild (node . firstChild);
};
this . createNode = function (tagName)
{
return (this . document . createElement (tagName));
};
this . createTextNode = function (text)
{
return (this . document . createTextNode (text));
};
this . getDocument = function ()
{
return (this . document);
};
this . getNode = function (nodeName)
{
return (this . document . getElementById (nodeName));
};
this . getValue = function (text)
{
return (parseInt (text));
};
this . getLayerX = function (cursorEvent)
{
if (typeof (cursorEvent) != "undefined")
if (typeof (cursorEvent . layerX) != "undefined")
return (cursorEvent . layerX);
if (typeof (event) != "undefined")
if (typeof (event . offsetX) != "undefined")
return (event . offsetX);
return (0);
};
this . getLayerY = function (cursorEvent)
{
if (typeof (cursorEvent) != "undefined")
if (typeof (cursorEvent . layerY) != "undefined")
return (cursorEvent . layerY);
if (typeof (event) != "undefined")
if (typeof (event . offsetY) != "undefined")
return (event . offsetY);
return (0);
};
this . getKeyCode = function (keyEvent)
{
var keyCode = 0;
if (navigator . userAgent . indexOf ("MSIE") == - 1)
keyCode = keyEvent . which;
else
keyCode = window . event . keyCode;
return (keyCode);
};
};
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Network) == "undefined") Network = new Object ();
Network . Socket = function ()
{
this . division = null;
this . script = null;
this . initialize = function ()
{
this . division = documentObjectModel . createNode ("div");
this . division . id = "NetworkSocket";
documentObjectModel . appendNode (documentObjectModel . getDocument () . body, this . division);
documentObjectModel . clearNodes (this . division);
this . script = null;
};
this . execute = function (command)
{
this . script = documentObjectModel . createNode ("script");
this . script . id = "NetworkSocket_Script";
this . script . type = "text/javascript";
this . script . src = command;
documentObjectModel . clearNodes (this . division);
documentObjectModel . appendNode (this . division, this . script);
};
};
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Network) == "undefined") Network = new Object ();
Network . InternetClient = function ()
{
this . initialize = function ()
{
};
this . getPageHeight = function ()
{
var height = 0;
if (typeof (window . innerHeight) == 'number')
height = window.innerHeight; // MOZILLA
else if (document . documentElement && document . documentElement . clientHeight)
height = document . documentElement . clientHeight; // INTERNET EXPLORER, "STANDARDS COMPLIANT MODE"
else if (document . body && document . body . clientHeight)
height = document . body . clientHeight; // INTERNET EXPLORER, "IE4 COMPATIBLE"
return (height);
};
this . getPageWidth = function ()
{
var width = 0;
if (typeof (window . innerWidth) == 'number')
width = window.innerWidth; // MOZILLA
else if (document . documentElement && document . documentElement . clientWidth)
width = document . documentElement . clientWidth; // INTERNET EXPLORER, "STANDARDS COMPLIANT MODE"
else if (document . body && document . body . clientWidth)
width = document . body . clientWidth; // INTERNET EXPLORER, "IE4 COMPATIBLE"
return (width);
};
};
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Reversi) == "undefined") Reversi = new Object ();
Reversi . Application = function ()
{
this . state = null;
this . panel = null;
this . board = null;
this . pieces = null;
this . offMarkerNode = null;
this . onMarkerNode = null;
this . piece = null;
this . cache = null;
this . gameCode = null;
this . ownPin = null;
this . opponentPin = null;
// TIME-RELATED ENTITIES
this . connectTimeDelay = 0;
this . connectTimeLimit = 0;
this . connectTimeCount = 0;
this . receiveTimeDelay = 0;
this . receiveTimeLimit = 0;
this . receiveTimeCount = 0;
this . cachePictures = function ()
{
this . cache = new Array ();
this . cache [0] = new Image (); this . cache [0] . src = "/games/reversi/Reversi/pictures/marker.off.jpg";
this . cache [1] = new Image (); this . cache [1] . src = "/games/reversi/Reversi/pictures/marker.on.jpg";
this . cache [2] = new Image (); this . cache [2] . src = "/games/reversi/Reversi/pictures/piece.primary.png";
this . cache [3] = new Image (); this . cache [3] . src = "/games/reversi/Reversi/pictures/piece.primary.gif";
this . cache [4] = new Image (); this . cache [4] . src = "/games/reversi/Reversi/pictures/piece.secondary.png";
this . cache [5] = new Image (); this . cache [5] . src = "/games/reversi/Reversi/pictures/piece.secondary.gif";
}
this . initialize = function ()
{
this . opponentPreviousMove = "";
this . ownMoves = new Array ();
this . opponentMoves = new Array ();
this . state = new Reversi . State ();
this . state . initialize ();
this . panel = new Reversi . Panel ();
this . panel . initialize ();
this . board = new Reversi . Board ();
this . board . initialize ();
this . connectTimeLimit = 180000;
this . connectTimeDelay = 4000;
this . connectTimeCount = 0;
this . receiveTimeLimit = 120000;
this . receiveTimeDelay = 500;
this . receiveTimeCount = 0;
this . pieces = new Array ();
// CREATE THE SECOND DIMENSION IN THE PIECES MATRIX.
for (var rowIndex = 0; rowIndex < 12; rowIndex = rowIndex + 1)
for (var columnIndex = 0; columnIndex < 12; columnIndex = columnIndex + 1)
if (this . pieces [rowIndex] == null)
this . pieces [rowIndex] = new Array ();
// POPULATE THE PIECES MATRIX WITH PIECES.
for (var rowIndex = 0; rowIndex < 12; rowIndex = rowIndex + 1)
for (var columnIndex = 0; columnIndex < 12; columnIndex = columnIndex + 1)
{
this . pieces [rowIndex] [columnIndex] = new Reversi . Piece ();
this . pieces [rowIndex] [columnIndex] . initialize ();
this . pieces [rowIndex] [columnIndex] . setCoordinates (rowIndex * (this . board . squareHeight + 1), columnIndex * (this . board . squareWidth + 1));
}
this . piece = new Reversi . Piece ();
this . piece . initialize ();
this . piece . setOwnPredicate (1);
this . piece . setCoordinates (0, 0);
this . piece . getNode () . style . display = "none";
this . piece . ready = 0;
this . state . reset ("default");
this . render ();
// ATTACH THE GRAPHICS NODES.
this . offMarkerNode = documentObjectModel . createNode ("div");
this . offMarkerNode . style . position = "absolute";
this . offMarkerNode . style . top = "0px";
this . offMarkerNode . style . left = "0px";
this . offMarkerNode . style . height = "50px";
this . offMarkerNode . style . width = "50px";
this . offMarkerNode . style . zIndex = "1";
this . offMarkerNode . style . backgroundImage = "url(/games/reversi/Reversi/pictures/marker.off.jpg)";
this . offMarkerNode . style . display = "none";
this . onMarkerNode = documentObjectModel . createNode ("div");
this . onMarkerNode . style . position = "absolute";
this . onMarkerNode . style . top = "0px";
this . onMarkerNode . style . left = "0px";
this . onMarkerNode . style . height = "50px";
this . onMarkerNode . style . width = "50px";
this . onMarkerNode . style . zIndex = "1";
this . onMarkerNode . style . backgroundImage = "url(/games/reversi/Reversi/pictures/marker.on.jpg)";
this . onMarkerNode . style . display = "none";
this . containerNode = documentObjectModel . createNode ("div");
this . containerNode . style . position = "relative";
this . containerNode . style . top = "0px";
this . containerNode . style . left = "0px";
this . containerNode . style . height = (408) + "px";
this . containerNode . style . left = "50%";
this . containerNode . style . zIndex = "0";
// if (navigator . userAgent . indexOf ("MSIE") != - 1)
//
// {
// this . containerNode . style . width = (this . panel . width + 25 + 1 + this . board . width + 4 + 4 + 4 + 2 + 2) + "px";
// this . containerNode . style . marginLeft = "-" + ((this . panel . width + 25 + 1 + this . board . width + 4 + 4 + 4 + 2 + 2) / 2) + "px";
// }
//
// else
//
// {
this . containerNode . style . width = (this . panel . width + 25 + 1 + this . board . width + 2) + "px";
this . containerNode . style . marginLeft = "-" + ((this . panel . width + 25 + 1 + this . board . width + 2) / 2) + "px";
// }
hideWaitMessage ();
documentObjectModel . getNode ("game") . style . textAlign = "left";
documentObjectModel . appendNode (documentObjectModel . getNode ("game"), this . containerNode);
documentObjectModel . appendNode (this . containerNode, this . panel . getNode ());
documentObjectModel . appendNode (this . containerNode, this . board . getNode ());
documentObjectModel . appendNode (this . board . getNode (), this . offMarkerNode);
documentObjectModel . appendNode (this . board . getNode (), this . onMarkerNode);
for (var rowIndex = 0; rowIndex < 12; rowIndex = rowIndex + 1)
for (var columnIndex = 0; columnIndex < 12; columnIndex = columnIndex + 1)
documentObjectModel . appendNode (this . board . getNode (), this . pieces [rowIndex] [columnIndex] . getNode ());
documentObjectModel . appendNode (this . board . getNode (), this . piece . getNode ());
this . ownPin = "7398";
this . panel . displayOpponentPlayerTypePrompt (this . setOpponentPlayerTypeDelegate);
this . cachePictures ();
};
this . finalize = function ()
{
this . state . finalize ();
this . panel . finalize ();
this . board . finalize ();
this . piece . finalize ();
this . state = null;
this . panel = null;
this . board = null;
this . pieces = null;
this . board . glassNode . onmousemove = null;
};
this . recordGame = function (winnerTitle)
{
var gameName;
var styleName;
var opponentType;
// Only the primary player is to record a game.
if (this . playerRank . toLowerCase () == "primary")
{
gameName = "Reversi";
if (this . boardSize . toLowerCase () == "default")
{
styleName = "default";
}
else if (this . boardSize . toLowerCase () == "standard")
{
styleName = "Standard";
}
else if (this . boardSize . toLowerCase () == "small")
{
styleName = "Small";
}
else if (this . boardSize . toLowerCase () == "medium")
{
styleName = "Medium";
}
else if (this . boardSize . toLowerCase () == "large")
{
styleName = "Large";
}
else
{
styleName = "";
}
if (this . opponentPlayerType == "virtual")
{
opponentType = "virtual";
}
else
{
opponentType = "actual";
}
if (winnerTitle . toLowerCase () == "tie")
{
winnerTitle = "tie";
}
else if (winnerTitle . toLowerCase () == "primary")
{
winnerTitle = "primary";
}
else if (winnerTitle . toLowerCase () == "secondary")
{
winnerTitle = "secondary";
}
else
{
winnerTitle = "";
}
socket . execute ("/games/reversi/Reversi/php" + "/" + "recordGame" + "." + "p" + "h" + "p?refreshCode=" + this . getRefreshCode () + "&gameName=" + gameName + "&styleName=" + styleName + "&opponentType=" + opponentType + "&winnerTitle=" + winnerTitle);
}
return;
};
this . setOpponentPlayerTypeDelegate = function (opponentPlayerType)
{
if (opponentPlayerType == "virtual")
{
application . opponentPlayerType = opponentPlayerType;
application . panel . hideOpponentPlayerTypePrompt ();
application . activateKayla ();
}
else
{
application . opponentPlayerType = opponentPlayerType;
application . panel . hideOpponentPlayerTypePrompt ();
application . panel . displayPinPrompt (application . ownPin, application . setOpponentPinDelegate);
application . panel . opponentPinArea . focus ();
}
};
this . activateKayla = function ()
{
kayla = new Reversi . Kayla ();
kayla . initialize ();
this . ownPin = "0000"; // fake pin -- allow the guest to move first
this . opponentPin = "0001"; // fake pin -- allow the guest to move first
this . playerRank = "primary"; // Forced.
this . panel . showPlayerMessage (this . playerRank);
this . panel . displaySizePrompt (this . setBoardSizeDelegate);
return;
};
this . setOpponentPinDelegate = function (pin)
{
application . setOpponentPin (pin);
return;
};
this . setOpponentPin = function (pin)
{
if (this . connectingPredicate == 1) return;
this . connectingPredicate = 1;
this . opponentPin = pin;
this . panel . showPins (this . ownPin, this . opponentPin);
messageBox . addMessage ("Events", "Connecting: " + this . opponentPin);
if (this . opponentPlayerType == "actual")
{
socket . execute ("/games/reversi/Reversi/php/connect.php?refreshcode=" + this . getRefreshCode () + "&ownPin=" + this . ownPin + "&opponentPin=" + this . opponentPin + "&winkPredicate=0\n");
}
this. connectTimeCount = 0;
this . connect ();
};
this . connect = function ()
{
this . panel . setMessage ("low", "connecting");
if (this . connectTimeCount > this . connectTimeLimit)
{
this . connectTimeCount = 0;
this . panel . setMessage ("high", "continue?");
this . panel . showOkayButton ("application . connect ()");
}
else if (this . gameCode == null) // IF NOT CONNECTED, THEN FIND OUT IF A CONNECTION HAS BEEN MADE.
{
messageBox . addMessage ("Events", "Attempting to connect.");
if (this . opponentPlayerType == "actual")
{
socket . execute ("/games/reversi/Reversi/php/getGameCode.php?refreshcode=" + this . getRefreshCode () + "&ownPin=" + this . ownPin + "&opponentPin=" + this . opponentPin);
}
setTimeout ("application . connect ()", this . connectTimeDelay);
this . connectTimeCount = this . connectTimeCount + this . connectTimeDelay;
}
else
{
if (typeof (this . winkPredicate) != "undefined")
messageBox . addMessage ("Notes", "[Wink] ~ Kayla");
this . panel . showPlayerMessage (this . playerRank);
messageBox . addMessage ("Events", "Connected. Player: " + this . playerRank);
if (this . playerRank == "primary")
{
this . panel . displaySizePrompt (this . setBoardSizeDelegate);
}
else
{
messageBox . addMessage ("Events", "Asking for the board size.");
this . piece . reverse ();
this . receiveTimeCount = 0;
this . getBoardSize ();
}
}
};
this . setBoardSizeDelegate = function (boardSize)
{
application . setBoardSize (boardSize);
application . startTurn ();
};
this . setBoardSize = function (boardSize)
{
this . gameExistsPredicate = 1;
// if (this . boardSize) if (this . boardSize != "default") return;
if (boardSize != "default")
{
if (this . playerRank == "primary")
messageBox . addMessage ("Events", "Sending the board size: " + boardSize);
else
messageBox . addMessage ("Events", "Received the board size: " + boardSize);
if (this . opponentPlayerType == "actual")
{
socket . execute ("/games/reversi/Reversi/php/setBoardSize.php?refreshcode=" + this . getRefreshCode () + "&gameCode=" + this . gameCode + "&ownPin=" + this . ownPin + "&opponentPin=" + this . opponentPin + "&boardSize=" + boardSize);
}
this . panel . showBoardSize (boardSize);
}
if (boardSize == "default" ) this . boardSize = "default";
if (boardSize == "Standard" ) this . boardSize = "Standard";
if (boardSize == "Small" ) this . boardSize = "Small";
if (boardSize == "Medium" ) this . boardSize = "Medium";
if (boardSize == "Large" ) this . boardSize = "Large";
this . board . setBoardSize (boardSize);
this . panel . setRowPixelCount (this . board . height);
documentObjectModel . getNode ("game") . style . height = (this . board . height) + "px";
// if (navigator . userAgent . indexOf ("MSIE") != - 1)
//
// {
// this . containerNode . style . width = (this . panel . width + 25 + 1 + this . board . width) + "px";
// this . containerNode . style . marginLeft = "-" + ((this . panel . width + 25 + 1 + this . board . width) / 2) + "px";
// }
//
// else
//
// {
this . containerNode . style . width = (this . panel . width + 25 + 1 + this . board . width + 2) + "px";
this . containerNode . style . marginLeft = "-" + ((this . panel . width + 25 + 1 + this . board . width + 2) / 2) + "px";
// }
this . state . reset (boardSize);
if (this . playerRank == "secondary")
{
this . state . reverse ();
for (var rowIndex = 0; rowIndex < 12; rowIndex = rowIndex + 1)
for (var columnIndex = 0; columnIndex < 12; columnIndex = columnIndex + 1)
{
this . pieces [rowIndex] [columnIndex] . reverse ();
}
}
this . render ();
};
this . getBoardSize = function ()
{
this . panel . setMessage ("low", "waiting for your friend to select the board size");
if (this . receiveTimeCount > this . receiveTimeLimit)
{
this . receiveTimeCount = 0;
this . panel . setMessage ("high", "continue?");
this . panel . showOkayButton ("application . getBoardSize ()");
}
else if (this . boardSize == null) // IF NOT CONNECTED, THEN FIND OUT IF A CONNECTION HAS BEEN MADE.
{
if (this . opponentPlayerType == "actual")
{
socket . execute ("/games/reversi/Reversi/php/getBoardSize.php?refreshcode=" + this . getRefreshCode () + "&gameCode=" + this . gameCode + "&ownPin=" + this . ownPin + "&opponentPin=" + this . opponentPin);
}
setTimeout ("application . getBoardSize ()", this . receiveTimeDelay);
this . receiveTimeCount = this . receiveTimeCount + this . receiveTimeDelay;
}
else
{
this . setBoardSize (this . boardSize);
this . endTurn ();
}
};
this . startTurn = function ()
{
this . panel . setMessage ("medium", "your turn");
this . disconnectEventCues ();
this . ownMove = null;
this . evaluate ();
this . tallyPieces ();
this . panel . showDifference (this . ownPieceCount - this . opponentPieceCount);
if (this . ownPieceCount == 0)
{
this . determineWinner ();
}
else if (this . opponentPieceCount == 0)
{
this . determineWinner ();
}
else if ((this . ownMoves . length == 0) && (this . opponentMoves . length == 0))
{
this . determineWinner ();
}
else if (this . ownMoves . length == 0)
{
this . forfeitMove ();
if (this . opponentMove != null)
{
var opponentMoveArray = this . opponentMove . split (",");
var rowIndex = parseInt (opponentMoveArray [0], 10);
var columnIndex = parseInt (opponentMoveArray [1], 10);
this . showMarker (rowIndex, columnIndex);
}
}
else
{
this . connectEventCues ();
}
};
this . endTurn = function (clearMarkerPredicate)
{
if (this . opponentPlayerType == "virtual")
{
this . panel . setMessage ("low", "machine's turn");
}
else
{
this . panel . setMessage ("low", "your friend's turn");
}
this . disconnectEventCues ();
this . opponentMove = null;
this . evaluate ();
if (clearMarkerPredicate)
this . hideMarker ();
this . tallyPieces ();
this . panel . showDifference (this . ownPieceCount - this . opponentPieceCount);
if (this . ownPieceCount == 0)
{
this . determineWinner ();
}
else if (this . opponentPieceCount == 0)
{
this . determineWinner ();
}
else if ((this . ownMoves . length == 0) && (this . opponentMoves . length == 0))
{
this . determineWinner ();
}
else
{
this . receiveTimeCount = this . receiveTimeDelay * 2;
setTimeout ("application . getMove ()", (this . opponentPlayerType == "virtual") ? "1000" : this . receiveTimeDelay * 2);
}
};
this . tallyPieces = function ()
{
this . ownPieceCount = 0;
this . opponentPieceCount = 0;
for (var rowIndex = 0; rowIndex < this . board . rowCount; rowIndex = rowIndex + 1)
for (var columnIndex = 0; columnIndex < this . board . columnCount; columnIndex = columnIndex + 1)
{
if (this . state . occupancy [rowIndex] [columnIndex] == 1)
if (this . state . possession [rowIndex] [columnIndex] == 1)
this . ownPieceCount = this . ownPieceCount + 1;
if (this . state . occupancy [rowIndex] [columnIndex] == 1)
if (this . state . possession [rowIndex] [columnIndex] == 0)
this . opponentPieceCount = this . opponentPieceCount + 1;
}
};
this . determineWinner = function ()
{
this . hideMarker ();
this . tallyPieces ();
if (this . ownPieceCount > this . opponentPieceCount)
{
this . recordGame ("primary");
this . panel . setMessage ("high", "congratulations!");
}
else if (this . opponentPieceCount > this . ownPieceCount)
{
this . recordGame ("secondary");
if (this . opponentPlayerType == "virtual")
{
this . panel . setMessage ("high", "The machine won. Thank you for playing.");
}
else
{
this . panel . setMessage ("high", "Your friend won. Thank you for playing.");
}
}
else
{
this . recordGame ("tie");
this . panel . setMessage ("high", "tie");
}
this . board . glassNode . onmousemove = null;
};
this . forfeitMove = function ()
{
messageBox . addMessage ("Events", "Forfeiting move.");
this . panel . showForfeitMessage ("own");
this . ownMove = "forfeit";
if (this . opponentPlayerType == "actual")
{
socket . execute ("/games/reversi/Reversi/php/setMove.php?refreshcode=" + this . getRefreshCode () + "&gameCode=" + this . gameCode + "&ownPin=" + this . ownPin + "&opponentPin=" + this . opponentPin + "&move=" + this . ownMove);
}
this . endTurn ();
};
this . setMove = function (rowIndex, columnIndex)
{
this . hideMarker ();
this . panel . hideForfeitMessage ();
this . ownMove = (rowIndex + "," + columnIndex);
messageBox . addMessage ("Events", "Sending move: " + this . ownMove);
if (this . opponentPlayerType == "actual")
{
socket . execute ("/games/reversi/Reversi/php/setMove.php?refreshcode=" + this . getRefreshCode () + "&gameCode=" + this . gameCode + "&ownPin=" + this . ownPin + "&opponentPin=" + this . opponentPin + "&move=" + this . ownMove);
}
this . endTurn ();
};
this . getMove = function ()
{
if (this . opponentPlayerType == "virtual")
{
this . panel . setMessage ("low", "machine's turn");
}
else
{
this . panel . setMessage ("low", "your friend's turn");
}
if (this . gameExistsPredicate == 0)
{
this . panel . setMessage ("high", "this game is no longer active");
return;
}
if (this . receiveTimeCount > this . receiveTimeLimit)
{
this . receiveTimeCount = 0;
this . panel . setMessage ("high", "continue?");
this . panel . showOkayButton ("application . getMove ()");
}
else if (this . opponentMove == this . opponentPreviousMove)
{
// SENDMOVE FAILED, SO RESEND IT.
messageBox . addMessage ("Events", "Resending move: " + this . ownMove);
messageBox . addMessage ("Warnings", "Network Error\nThe move had to be resent: " + this . ownMove);
this . opponentMove = null;
if (this . opponentPlayerType == "actual")
{
socket . execute ("/games/reversi/Reversi/php/setMove.php?refreshcode=" + this . getRefreshCode () + "&gameCode=" + this . gameCode + "&ownPin=" + this . ownPin + "&opponentPin=" + this . opponentPin + "&move=" + this . ownMove);
}
setTimeout ("application . getMove ()", this . receiveTimeDelay * 2);
this . receiveTimeCount = this . receiveTimeCount + this . receiveTimeDelay * 2;
}
else if ((this . opponentMove == null) || (this . opponentMove == this . ownMove))
{
if (this . opponentPlayerType == "actual")
{
socket . execute ("/games/reversi/Reversi/php/getMove.php?refreshcode=" + this . getRefreshCode () + "&gameCode=" + this . gameCode + "&ownPin=" + this . ownPin + "&opponentPin=" + this . opponentPin);
}
setTimeout ("application . getMove ()", this . receiveTimeDelay);
this . receiveTimeCount = this . receiveTimeCount + this . receiveTimeDelay;
}
else if (this . opponentMove == "forfeit")
{
this . hideMarker ();
this . panel . showForfeitMessage ((this . opponentPlayerType == "virtual") ? "virtual" : "actual");
this . startTurn ();
}
else
{
messageBox . addMessage ("Events", "Received move: " + this . opponentMove);
this . panel . hideForfeitMessage ();
this . opponentPreviousMove = this . opponentMove;
var opponentMoveArray = this . opponentMove . split (",");
var rowIndex = parseInt (opponentMoveArray [0], 10);
var columnIndex = parseInt (opponentMoveArray [1], 10);
this . showMarker (rowIndex, columnIndex);
// DUPLICATE THE OPPONENT'S MOVE ON THIS BOARD.
var rowMultipliers = new Array (-1, -1, -1, 0, 0, 1, 1, 1);
var columnMultipliers = new Array (-1, 0, 1, -1, 1, -1, 0, 1);
if (rowIndex >= 0)
if (rowIndex < this . board . rowCount)
if (columnIndex >= 0)
if (columnIndex < this . board . columnCount)
for (var distanceIndex = 2; distanceIndex < 12; distanceIndex = distanceIndex + 1)
for (var angleIndex = 0; angleIndex < 8; angleIndex = angleIndex + 1)
{
var anchorRowIndex = rowIndex + distanceIndex * rowMultipliers [angleIndex];
var anchorColumnIndex = columnIndex + distanceIndex * columnMultipliers [angleIndex];
if (this . state . occupancy [rowIndex] [columnIndex] == 0)
if (anchorRowIndex >= 0)
if (anchorRowIndex < this . board . rowCount)
if (anchorColumnIndex >= 0)
if (anchorColumnIndex < this . board . columnCount)
if (this . state . occupancy [anchorRowIndex] [anchorColumnIndex] == 1)
if (this . state . possession [anchorRowIndex] [anchorColumnIndex] == 0)
if (this . getFlankPredicate (anchorRowIndex, anchorColumnIndex, rowIndex, columnIndex) == 1)
this . capture (anchorRowIndex, anchorColumnIndex, rowIndex, columnIndex);
}
this . state . occupancy [rowIndex] [columnIndex] = 1;
this . state . possession [rowIndex] [columnIndex] = 0;
this . render ();
// START THE PLAYER'S NEXT TURN.
this . startTurn ();
}
};
this . getTranslatedMove = function (move)
{
var moveArray = move . split (",");
move = (this . board . rowCount - 1 - parseInt (moveArray [0], 10)) + "," + (this . board . columnCount - 1 - parseInt (moveArray [1], 10));
return (move);
};
this . evaluate = function ()
{
var rowMultipliers = new Array (-1, -1, -1, 0, 0, 1, 1, 1);
var columnMultipliers = new Array (-1, 0, 1, -1, 1, -1, 0, 1);
this . ownMoves = new Array ();
this . opponentMoves = new Array ();
for (var rowIndex = 0; rowIndex < this . board . rowCount; rowIndex = rowIndex + 1)
for (var columnIndex = 0; columnIndex < this . board . columnCount; columnIndex = columnIndex + 1)
for (var distanceIndex = 2; distanceIndex < 12; distanceIndex = distanceIndex + 1)
for (var angleIndex = 0; angleIndex < 8; angleIndex = angleIndex + 1)
{
var anchorRowIndex = rowIndex + distanceIndex * rowMultipliers [angleIndex];
var anchorColumnIndex = columnIndex + distanceIndex * columnMultipliers [angleIndex];
if (this . state . occupancy [rowIndex] [columnIndex] == 1)
if (anchorRowIndex >= 0)
if (anchorRowIndex < this . board . rowCount)
if (anchorColumnIndex >= 0)
if (anchorColumnIndex < this . board . columnCount)
if (this . state . occupancy [anchorRowIndex] [anchorColumnIndex] == 0)
if (this . getFlankPredicate (rowIndex, columnIndex, anchorRowIndex, anchorColumnIndex) == 1)
{
if (this . state . possession [rowIndex] [columnIndex] == 1)
this . ownMoves . push (anchorRowIndex + "," + anchorColumnIndex);
else
this . opponentMoves . push (anchorRowIndex + "," + anchorColumnIndex);
}
}
};
this . getFlankPredicate = function (fromRowIndex, fromColumnIndex, toRowIndex, toColumnIndex)
{
var matchCode = this . state . possession [fromRowIndex] [fromColumnIndex];
var rowStep = 0;
var columnStep = 0;
if (fromRowIndex < toRowIndex) rowStep = 1;
if (fromRowIndex > toRowIndex) rowStep = - 1;
if (fromColumnIndex < toColumnIndex) columnStep = 1;
if (fromColumnIndex > toColumnIndex) columnStep = - 1;
var rowIndex = fromRowIndex + rowStep;
var columnIndex = fromColumnIndex + columnStep;
var index = 0;
var initialValue = 0;
var rowLimit = fromRowIndex < toRowIndex ? toRowIndex - fromRowIndex - 1 : fromRowIndex - toRowIndex - 1;
var columnLimit = fromColumnIndex < toColumnIndex ? toColumnIndex - fromColumnIndex - 1 : fromColumnIndex - toColumnIndex - 1;
var limit = rowLimit > columnLimit ? rowLimit : columnLimit;
for (index = initialValue; index < limit; index = index + 1)
{
// RETURN FALSE IF THERE IS NO PIECE IN THE ANCHOR SQUARE.
if (this . state . occupancy [rowIndex] [columnIndex] == 0)
return (0);
// RETURN FALSE IF THERE IS THE PIECE IN THE SQUARE IS THE GUEST'S.
if (this . state . possession [rowIndex] [columnIndex] == matchCode)
return (0);
rowIndex = rowIndex + rowStep;
columnIndex = columnIndex + columnStep;
}
return (1);
};
this . capture = function (fromRowIndex, fromColumnIndex, toRowIndex, toColumnIndex)
{
matchCode = this . state . possession [fromRowIndex] [fromColumnIndex];
var rowStep = 0;
var columnStep = 0;
if (fromRowIndex < toRowIndex) rowStep = 1;
if (fromRowIndex > toRowIndex) rowStep = - 1;
if (fromColumnIndex < toColumnIndex) columnStep = 1;
if (fromColumnIndex > toColumnIndex) columnStep = - 1;
var rowIndex = fromRowIndex + rowStep;
var columnIndex = fromColumnIndex + columnStep;
var index = 0;
var initialValue = 0;
var rowLimit = fromRowIndex < toRowIndex ? toRowIndex - fromRowIndex - 1 : fromRowIndex - toRowIndex - 1;
var columnLimit = fromColumnIndex < toColumnIndex ? toColumnIndex - fromColumnIndex - 1 : fromColumnIndex - toColumnIndex - 1;
var limit = rowLimit > columnLimit ? rowLimit : columnLimit;
for (index = initialValue; index < limit; index = index + 1)
{
this . state . possession [rowIndex] [columnIndex] = matchCode;
rowIndex = rowIndex + rowStep;
columnIndex = columnIndex + columnStep;
}
};
this . render = function ()
{
for (var rowIndex = 0; rowIndex < this . board . rowCount; rowIndex = rowIndex + 1)
for (var columnIndex = 0; columnIndex < this . board . columnCount; columnIndex = columnIndex + 1)
{
// IF THE STATE INDICATES A PIECE IN A SQUARE, THEN SHOW THE PIECE.
// OTHERWISE, HIDE THE PIECE.
if (this . state . occupancy [rowIndex] [columnIndex] == 1)
this . pieces [rowIndex] [columnIndex] . getNode () . style . display = "block";
else
this . pieces [rowIndex] [columnIndex] . getNode () . style . display = "none";
// IF THE STATE INDICATES THAT THE PIECE IN THE SQUARE IS THE GUEST'S, THEN SHOW THE 'OWN' PIECE.
// OTHERWISE, SHOW THE 'OPPONENT' PIECE.
if (this . state . possession [rowIndex] [columnIndex] == 1)
this . pieces [rowIndex] [columnIndex] . setOwnPredicate (1);
else
this . pieces [rowIndex] [columnIndex] . setOwnPredicate (0);
}
};
this . connectEventCues = function ()
{
if (this . piece . ready == 1)
this . piece . getNode () . style . display = "block";
this . board . glassNode . that = this;
this . board . glassNode . onmouseup = this . cursorUpDelegate;
this . board . glassNode . onmousemove = this . cursorMoveDelegate;
};
this . disconnectEventCues = function ()
{
this . piece . getNode () . style . display = "none";
this . board . glassNode . onmouseup = null;
};
this . cursorMoveDelegate = function (cursorEvent)
{
application . cursorMove (cursorEvent);
}
this . cursorMove = function (cursorEvent)
{
if (this . piece . ready == 0)
{
this . piece . ready = 1;
this . piece . getNode () . style . display = "block";
}
this . piece . setCoordinates (documentObjectModel . getLayerY (cursorEvent) - this . piece . height / 2, documentObjectModel . getLayerX (cursorEvent) - this . piece . width / 2);
cursorEvent . stopPropagation ();
cursorEvent . preventDefault ();
return;
};
this . cursorUpDelegate = function (cursorEvent)
{
application . cursorUp (cursorEvent);
}
this . cursorUp = function (cursorEvent)
{
this . board . glassNode . onmouseup = null;
var rowIndex = Math . floor (documentObjectModel . getLayerY (cursorEvent) / 51);
var columnIndex = Math . floor (documentObjectModel . getLayerX (cursorEvent) / 51);
var rowMultipliers = new Array (-1, -1, -1, 0, 0, 1, 1, 1);
var columnMultipliers = new Array (-1, 0, 1, -1, 1, -1, 0, 1);
if (this . getValidMovePredicate (rowIndex, columnIndex) == 1)
if (rowIndex >= 0)
if (rowIndex < this . board . rowCount)
if (columnIndex >= 0)
if (columnIndex < this . board . columnCount)
for (var distanceIndex = 2; distanceIndex < 12; distanceIndex = distanceIndex + 1)
for (var angleIndex = 0; angleIndex < 8; angleIndex = angleIndex + 1)
{
var anchorRowIndex = rowIndex + distanceIndex * rowMultipliers [angleIndex];
var anchorColumnIndex = columnIndex + distanceIndex * columnMultipliers [angleIndex];
if (this . state . occupancy [rowIndex] [columnIndex] == 0)
if (anchorRowIndex >= 0)
if (anchorRowIndex < this . board . rowCount)
if (anchorColumnIndex >= 0)
if (anchorColumnIndex < this . board . columnCount)
if (this . state . occupancy [anchorRowIndex] [anchorColumnIndex] == 1)
if (this . state . possession [anchorRowIndex] [anchorColumnIndex] == 1)
if (this . getFlankPredicate (anchorRowIndex, anchorColumnIndex, rowIndex, columnIndex) == 1)
this . capture (anchorRowIndex, anchorColumnIndex, rowIndex, columnIndex);
}
if (this . getValidMovePredicate (rowIndex, columnIndex) == 0)
{
this . panel . setMessage ("high", "that move is not allowed");
this . board . glassNode . onmouseup = this . cursorUpDelegate;
}
if (this . getValidMovePredicate (rowIndex, columnIndex) == 1)
{
this . state . occupancy [rowIndex] [columnIndex] = 1;
this . state . possession [rowIndex] [columnIndex] = 1;
this . render ();
this . setMove (rowIndex, columnIndex);
}
cursorEvent . stopPropagation ();
cursorEvent . preventDefault ();
return;
};
this . getValidMovePredicate = function (rowIndex, columnIndex)
{
for (var index = 0; index < this . ownMoves . length; index = index + 1)
if (this . ownMoves [index] == (rowIndex + "," + columnIndex))
return (1);
return (0);
};
this . showMarker = function (rowIndex, columnIndex)
{
if ((rowIndex % 2) == (columnIndex % 2))
{
this . offMarkerNode . style . top = (rowIndex * 51) + "px";
this . offMarkerNode . style . left = (columnIndex * 51) + "px";
this . offMarkerNode . style . display = "block";
}
else
{
this . onMarkerNode . style . top = (rowIndex * 51) + "px";
this . onMarkerNode . style . left = (columnIndex * 51) + "px";
this . onMarkerNode . style . display = "block";
}
};
this . hideMarker = function ()
{
this . offMarkerNode . style . display = "none";
this . onMarkerNode . style . display = "none";
};
this . getRefreshCode = function ()
{
var date = new Date ();
var refreshCode = "";
refreshCode = refreshCode + this . getPaddedText (date . getUTCFullYear () , "0", 4);
refreshCode = refreshCode + this . getPaddedText (date . getUTCMonth () , "0", 2);
refreshCode = refreshCode + this . getPaddedText (date . getUTCDay () , "0", 2);
refreshCode = refreshCode + this . getPaddedText (date . getUTCHours () , "0", 2);
refreshCode = refreshCode + this . getPaddedText (date . getUTCMinutes () , "0", 2);
refreshCode = refreshCode + this . getPaddedText (date . getUTCSeconds () , "0", 2);
refreshCode = refreshCode + this . getPaddedText (date . getUTCMilliseconds () , "0", 3);
return (refreshCode);
};
this . getPaddedText = function (text, padCharacter, characterCount)
{
text = text . toString ();
while (text . length < characterCount)
text = padCharacter + "" + text;
return (text);
};
};
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Reversi) == "undefined") Reversi = new Object ();
Reversi . State = function ()
{
this . occupancy = null;
this . possession = null;
this . ownPin = null;
this . opponentPin = null;
this . initialize = function ()
{
this . occupancy = new Array (new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array ());
this . possession = new Array (new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array ());
this . ownPin = null;
this . opponentPin = null;
};
this . finalize = function ()
{
this . occupancy = null;
this . possession = null;
this . ownPin = null;
this . opponentPin = null;
};
this . reset = function (boardSize)
{
if (boardSize == "default" ) {this . rowCount = 8; this . columnCount = 8;}
if (boardSize == "Standard" ) {this . rowCount = 8; this . columnCount = 8;}
if (boardSize == "Small" ) {this . rowCount = 8; this . columnCount = 8;}
if (boardSize == "Medium" ) {this . rowCount = 10; this . columnCount = 10;}
if (boardSize == "Large" ) {this . rowCount = 12; this . columnCount = 12;}
var rowIndex;
var columnIndex;
for (rowIndex = 0; rowIndex < 12; rowIndex = rowIndex + 1)
for (columnIndex = 0; columnIndex < 12; columnIndex = columnIndex + 1)
{
this . occupancy [rowIndex] [columnIndex] = 0;
this . possession [rowIndex] [columnIndex] = 0;
}
if (boardSize == "default" ) {rowIndex = 3; columnIndex = 3;}
if (boardSize == "Standard" ) {rowIndex = 3; columnIndex = 3;}
if (boardSize == "Small" ) {rowIndex = 3; columnIndex = 3;}
if (boardSize == "Medium" ) {rowIndex = 4; columnIndex = 4;}
if (boardSize == "Large" ) {rowIndex = 5; columnIndex = 5;}
this . occupancy [rowIndex + 0] [columnIndex + 0] = 1;
this . occupancy [rowIndex + 0] [columnIndex + 1] = 1;
this . occupancy [rowIndex + 1] [columnIndex + 0] = 1;
this . occupancy [rowIndex + 1] [columnIndex + 1] = 1;
this . possession [rowIndex + 0] [columnIndex + 0] = 0;
this . possession [rowIndex + 0] [columnIndex + 1] = 1;
this . possession [rowIndex + 1] [columnIndex + 0] = 1;
this . possession [rowIndex + 1] [columnIndex + 1] = 0;
};
this . reverse = function ()
{
for (rowIndex = 0; rowIndex < 12; rowIndex = rowIndex + 1)
for (columnIndex = 0; columnIndex < 12; columnIndex = columnIndex + 1)
this . possession [rowIndex] [columnIndex] = 1 - this . possession [rowIndex] [columnIndex];
for (rowIndex = 0; rowIndex < (this . rowCount / 2); rowIndex = rowIndex + 1)
for (columnIndex = 0; columnIndex < this . columnCount; columnIndex = columnIndex + 1)
{
var occupancyValue = this . occupancy [rowIndex] [columnIndex];
var possessionValue = this . possession [rowIndex] [columnIndex];
this . occupancy [rowIndex] [columnIndex] = this . occupancy [this . rowCount - 1 - rowIndex] [this . columnCount - 1 - columnIndex];
this . possession [rowIndex] [columnIndex] = this . possession [this . rowCount - 1 - rowIndex] [this . columnCount - 1 - columnIndex];
this . occupancy [this . rowCount - 1 - rowIndex] [this . columnCount - 1 - columnIndex] = occupancyValue;
this . possession [this . rowCount - 1 - rowIndex] [this . columnCount - 1 - columnIndex] = possessionValue;
}
};
};
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Reversi) == "undefined") Reversi = new Object ();
Reversi . Panel = function ()
{
this . height = 409;
this . width = 175;
// STATE
this . boardState = null; // AN ARRAY OF CODES THAT DESCRIBES WHAT OCCUPIES EACH SQUARE ON THE BOARD.
this . ownPin = null; // A MULTI-DIGIT PIN THAT IS USED TO IDENTIFY {THIS PLAYER, THIS BOARD INSTANCE}.
this . opponentPin = null; // A MULTI-DIGIT PIN THAT IS USED TO IDENTIFY {THAT PLAYER, THIS BOARD INSTANCE}.
this . currentPlayerPin = null; // A COPY OF THE PIN THAT IS OWNED BY THE PLAYER WHO'S TURN IT IS.
this . setOpponentPinDelegate = null;
this . setSizeDelegate = null;
this . okayButtonInstructions = null;
// INTERFACE
this . title = null;
this . node = null;
this . titleDivision = null;
this . forfeitDivision = null;
this . messageDivision = null;
this . opponentPlayerTypeFormDivision = null;
this . okayButtonDivision = null;
this . pinFormDivision = null;
this . pinDivision = null;
this . differenceDivision = null;
this . ownPinArea = null;
this . opponentPinArea = null;
this . playerDivision = null;
this . playerImage = null;
this . sizeFormDivision = null;
this . sizeDivision = null;
this . lowMessageColor = null;
this . mediumMessageColor = null;
this . highMessageColor = null;
this . initialize = function ()
{
this . node = documentObjectModel . createNode ("div");
this . titleDivision = documentObjectModel . createNode ("div");
this . forfeitDivision = documentObjectModel . createNode ("div");
this . messageDivision = documentObjectModel . createNode ("div");
this . opponentPlayerTypeFormDivision = documentObjectModel . createNode ("div");
this . okayButtonDivision = documentObjectModel . createNode ("div");
this . pinFormDivision = documentObjectModel . createNode ("div");
this . pinDivision = documentObjectModel . createNode ("div");
this . differenceDivision = documentObjectModel . createNode ("div");
this . ownPinArea = documentObjectModel . createNode ("input");
this . opponentPinArea = documentObjectModel . createNode ("input");
this . playerDivision = documentObjectModel . createNode ("div");
this . playerImage = documentObjectModel . createNode ("img");
this . sizeFormDivision = documentObjectModel . createNode ("div");
this . sizeDivision = documentObjectModel . createNode ("div");
this . lowMessageColor = "#7c7b51";
this . mediumMessageColor = "#495537";
this . highMessageColor = "#553737";
this . title = "Reversi";
this . node . id = "ReversiPanel";
this . node . style . position = "absolute";
this . node . style . top = "0px";
this . node . style . left = "0px";
this . node . style . height = (51 * 8 - 1) + "px";
this . node . style . width = "175px";
this . node . style . backgroundColor = "#444444";
this . node . style . border = "#000000 2px solid";
this . node . style . overflow = "hidden";
this . titleDivision . id = "ReversiPanel_TitleDivision";
this . titleDivision . style . position = "relative";
this . titleDivision . style . color = "#ffffff";
this . titleDivision . style . backgroundColor = "#222222";
this . titleDivision . style . borderBottom = "#333333 0px solid";
this . titleDivision . style . padding = "8px";
this . titleDivision . style . textAlign = "center";
this . forfeitDivision . id = "ReversiPanel_ForfeitDivision";
this . forfeitDivision . style . position = "relative";
this . forfeitDivision . style . color = "#ffffff";
this . forfeitDivision . style . backgroundColor = this . lowMessageColor;
this . forfeitDivision . style . borderBottom = "#333333 1px solid";
this . forfeitDivision . style . padding = "8px";
this . forfeitDivision . style . textAlign = "center";
this . forfeitDivision . style . display = "none";
this . messageDivision . id = "ReversiPanel_MessageDivision";
this . messageDivision . style . position = "relative";
this . messageDivision . style . color = "#ffffff";
this . messageDivision . style . backgroundColor = this . lowMessageColor;
this . messageDivision . style . borderBottom = "#333333 1px solid";
this . messageDivision . style . padding = "8px";
this . messageDivision . style . textAlign = "center";
this . opponentPlayerTypeFormDivision . id = "ReversiPanel_OpponentPlayerTypeFormDivision";
this . opponentPlayerTypeFormDivision . style . position = "relative";
this . opponentPlayerTypeFormDivision . style . color = "#ffffff";
this . opponentPlayerTypeFormDivision . style . backgroundColor = "#555555";
this . opponentPlayerTypeFormDivision . style . borderBottom = "#333333 1px solid";
this . opponentPlayerTypeFormDivision . style . padding = "8px";
this . opponentPlayerTypeFormDivision . style . textAlign = "center";
this . opponentPlayerTypeFormDivision . style . display = "none";
this . okayButtonDivision . id = "ReversiPanel_OkayButtonDivision";
this . okayButtonDivision . that = this;
this . okayButtonDivision . style . position = "relative";
this . okayButtonDivision . style . cursor = "pointer";
this . okayButtonDivision . style . color = "#ffffff";
this . okayButtonDivision . style . backgroundColor = "#555555";
this . okayButtonDivision . style . borderBottom = "#333333 1px solid";
this . okayButtonDivision . style . padding = "8px";
this . okayButtonDivision . style . textAlign = "center";
this . okayButtonDivision . style . display = "none";
var makaylaOption = documentObjectModel . createNode ("img");
var friendOption = documentObjectModel . createNode ("img");
makaylaOption . that = this;
makaylaOption . style . cursor = "pointer";
makaylaOption . opponentPlayerType = "virtual";
makaylaOption . src = "/games/reversi/Reversi/pictures/button.makayla.jpg";
makaylaOption . onclick = function () {this . that . setOpponentPlayerTypeDelegate (this . opponentPlayerType);}
friendOption . that = this;
friendOption . style . cursor = "pointer";
friendOption . opponentPlayerType = "actual";
friendOption . src = "/games/reversi/Reversi/pictures/button.friend.jpg";
friendOption . onclick = function () {this . that . setOpponentPlayerTypeDelegate (this . opponentPlayerType);}
documentObjectModel . appendNode (this . opponentPlayerTypeFormDivision, makaylaOption);
documentObjectModel . appendNode (this . opponentPlayerTypeFormDivision, documentObjectModel . createNode ("br"));
documentObjectModel . appendNode (this . opponentPlayerTypeFormDivision, friendOption);
this . pinFormDivision . id = "ReversiPanel_pinFormDivision";
this . pinFormDivision . style . position = "relative";
this . pinFormDivision . style . color = "#ffffff";
this . pinFormDivision . style . backgroundColor = "#555555";
this . pinFormDivision . style . borderBottom = "#333333 1px solid";
this . pinFormDivision . style . padding = "8px";
this . pinFormDivision . style . textAlign = "center";
this . pinFormDivision . style . display = "none";
this . ownPinArea . id = "ReversiPanel_ownPinArea";
this . ownPinArea . style . position = "relative";
this . ownPinArea . style . width = "50px";
this . ownPinArea . style . color = "#ffffff";
this . ownPinArea . style . backgroundColor = "#555555";
this . ownPinArea . style . border = "#000000 1px solid";
this . ownPinArea . style . padding = "2px";
this . ownPinArea . style . textAlign = "center";
this . ownPinArea . value = this . ownPin;
this . opponentPinArea . id = "ReversiPanel_opponentPinArea";
this . opponentPinArea . that = this;
this . opponentPinArea . style . position = "relative";
this . opponentPinArea . style . width = "50px";
this . opponentPinArea . style . color = "#000000";
this . opponentPinArea . style . backgroundColor = "#ffffff";
this . opponentPinArea . style . border = "#000000 1px solid";
this . opponentPinArea . style . padding = "2px";
this . opponentPinArea . style . textAlign = "center";
this . opponentPinArea . value = "";
this . ownPinArea . onkeypress = function (keyEvent)
{
var keyCode = context . getKeyCode (keyEvent);
return (false);
};
this . opponentPinArea . onkeypress = function (keyEvent)
{
var keyCode = documentObjectModel . getKeyCode (keyEvent);
// APPROVE CERTAIN CHARACTERS FIRST, REJECT OTHER CHARACTERS LATER.
if (keyCode == 8) return (true); // BACKSPACE
if (keyCode == 48) return (true); // 0
if (keyCode == 49) return (true); // 1
if (keyCode == 50) return (true); // 2
if (keyCode == 51) return (true); // 3
if (keyCode == 52) return (true); // 4
if (keyCode == 53) return (true); // 5
if (keyCode == 54) return (true); // 6
if (keyCode == 55) return (true); // 7
if (keyCode == 56) return (true); // 8
if (keyCode == 57) return (true); // 9
// AT THIS POINT, WE KNOW THE CHARACTER IS NOT ALLOWED, SO DISCARD IT.
return (false);
};
this . opponentPinArea . onkeyup = function ()
{
if (this . value == this . that . ownPinArea . value) this . value = "";
if (this . value . length > 4) this . value = this . value . substring (0, 4);
if (this . value . length == 4)
{
this . that . setOpponentPinDelegate (this . value);
}
};
this . okayButtonDivision . onclick = function ()
{
this . that . hideOkayButton ();
};
this . pinDivision . id = "ReversiPanel_PinDivision";
this . pinDivision . style . position = "relative";
this . pinDivision . style . color = "#ffffff";
this . pinDivision . style . backgroundColor = "#555555";
this . pinDivision . style . borderBottom = "#333333 1px solid";
this . pinDivision . style . padding = "8px";
this . pinDivision . style . textAlign = "center";
this . pinDivision . style . display = "none";
this . differenceDivision . id = "ReversiPanel_DifferenceDivision";
this . differenceDivision . style . position = "relative";
this . differenceDivision . style . color = "#aaaaaa";
this . differenceDivision . style . backgroundColor = "#444444";
this . differenceDivision . style . borderBottom = "#444444 1px solid";
this . differenceDivision . style . padding = "8px";
this . differenceDivision . style . textAlign = "center";
this . differenceDivision . style . display = "none";
this . playerDivision . id = "ReversiPanel_PlayerDivision";
this . playerDivision . style . position = "relative";
this . playerDivision . style . color = "#ffffff";
this . playerDivision . style . backgroundColor = "#444444";
this . playerDivision . style . borderBottom = "#444444 1px solid";
this . playerDivision . style . padding = "8px";
this . playerDivision . style . textAlign = "center";
this . playerDivision . style . display = "block";
var javascriptText;
javascriptText = "";
javascriptText = javascriptText + "javascript: ";
javascriptText = javascriptText + "messageBox . initialize (); ";
javascriptText = javascriptText + "messageBox . addType (\"Events\"); ";
javascriptText = javascriptText + "messageBox . addType (\"Notes\"); ";
javascriptText = javascriptText + "messageBox . addType (\"Warnings\"); ";
javascriptText = javascriptText + "messageBox . addType (\"Errors\"); ";
this . playerImage . that = this;
this . playerImage . src = "/games/reversi/Reversi/pictures/piece.primary." + (navigator . userAgent . indexOf ("Firefox") != - 1 ? "png" : "gif");
this . playerImage . style . display = "block";
this . playerImage . style . marginLeft = "auto";
this . playerImage . style . marginRight = "auto";
this . playerImage . style . height = "50px";
this . playerImage . style . width = "50px";
this . playerImage . setAttribute ("onclick", javascriptText);
this . sizeFormDivision . id = "ReversiPanel_SizeFormDivision";
this . sizeFormDivision . style . position = "relative";
this . sizeFormDivision . style . color = "#ffffff";
this . sizeFormDivision . style . backgroundColor = "#555555";
this . sizeFormDivision . style . borderBottom = "#333333 1px solid";
this . sizeFormDivision . style . padding = "8px";
this . sizeFormDivision . style . textAlign = "center";
this . sizeFormDivision . style . display = "none";
this . sizeDivision . id = "ReversiPanel_SizeDivision";
this . sizeDivision . style . position = "relative";
this . sizeDivision . style . color = "#ffffff";
this . sizeDivision . style . backgroundColor = "#555555";
this . sizeDivision . style . borderBottom = "#333333 1px solid";
this . sizeDivision . style . padding = "8px";
this . sizeDivision . style . textAlign = "center";
this . sizeDivision . style . display = "none";
// APPEND THE MAJOR COMPONENTS TO THE PANEL.
documentObjectModel . appendNode (this . getNode (), this . titleDivision);
documentObjectModel . appendNode (this . getNode (), this . forfeitDivision);
documentObjectModel . appendNode (this . getNode (), this . messageDivision);
documentObjectModel . appendNode (this . getNode (), this . okayButtonDivision);
documentObjectModel . appendNode (this . getNode (), this . opponentPlayerTypeFormDivision);
documentObjectModel . appendNode (this . getNode (), this . sizeFormDivision);
documentObjectModel . appendNode (this . getNode (), this . sizeDivision);
documentObjectModel . appendNode (this . getNode (), this . pinFormDivision);
documentObjectModel . appendNode (this . getNode (), this . pinDivision);
documentObjectModel . appendNode (this . getNode (), this . playerDivision);
documentObjectModel . appendNode (this . getNode (), this . differenceDivision);
documentObjectModel . appendNode (this . playerDivision, this . playerImage);
// APPEND THE MINOR COMPONENTS TO THE MAJOR COMPONENTS.
var standardOption = documentObjectModel . createNode ("img");
var smallOption = documentObjectModel . createNode ("img");
var mediumOption = documentObjectModel . createNode ("img");
var largeOption = documentObjectModel . createNode ("img");
documentObjectModel . appendNode (this . sizeFormDivision, standardOption);
documentObjectModel . appendNode (this . sizeFormDivision, documentObjectModel . createNode ("br"));
documentObjectModel . appendNode (this . sizeFormDivision, smallOption);
documentObjectModel . appendNode (this . sizeFormDivision, documentObjectModel . createNode ("br"));
documentObjectModel . appendNode (this . sizeFormDivision, mediumOption);
documentObjectModel . appendNode (this . sizeFormDivision, documentObjectModel . createNode ("br"));
documentObjectModel . appendNode (this . sizeFormDivision, largeOption);
standardOption . that = this;
standardOption . style . cursor = "pointer";
standardOption . sizeName = "Standard";
standardOption . src = "/games/reversi/Reversi/pictures/button.standard.jpg";
standardOption . onclick = function () {this . that . setSizeDelegate (this . sizeName);}
smallOption . that = this;
smallOption . style . cursor = "pointer";
smallOption . sizeName = "Small";
smallOption . src = "/games/reversi/Reversi/pictures/button.small.jpg";
smallOption . onclick = function () {this . that . setSizeDelegate (this . sizeName);}
mediumOption . that = this;
mediumOption . style . cursor = "pointer";
mediumOption . sizeName = "Medium";
mediumOption . src = "/games/reversi/Reversi/pictures/button.medium.jpg";
mediumOption . onclick = function () {this . that . setSizeDelegate (this . sizeName);}
largeOption . that = this;
largeOption . style . cursor = "pointer";
largeOption . sizeName = "Large";
largeOption . src = "/games/reversi/Reversi/pictures/button.large.jpg";
largeOption . onclick = function () {this . that . setSizeDelegate (this . sizeName);}
documentObjectModel . appendNode (this . titleDivision, documentObjectModel . createTextNode (this . title));
var okayOption;
okayOption = documentObjectModel . createNode ("img");
okayOption . that = this;
okayOption . style . cursor = "pointer";
okayOption . typeText = "okay";
okayOption . src = "/games/reversi/Reversi/pictures/button.okay.jpg";
documentObjectModel . appendNode (this . okayButtonDivision, okayOption);
documentObjectModel . appendNode (this . pinFormDivision, this . ownPinArea);
documentObjectModel . appendNode (this . pinFormDivision, documentObjectModel . createTextNode (" "));
documentObjectModel . appendNode (this . pinFormDivision, this . opponentPinArea);
this . setMessage ("low", "Initializing");
};
this . showForfeitMessage = function (player)
{
var message;
if (player == "own")
message = "You had to forfeit your turn.";
else if (player == "virtual")
message = "The machine had to forfeit its turn.";
else
message = "Your friend had to forfeit their turn.";
if (player == "own")
this . forfeitDivision . style . backgroundColor = this . highMessageColor;
else
this . forfeitDivision . style . backgroundColor = this . mediumMessageColor;
documentObjectModel . clearNodes (this . forfeitDivision);
documentObjectModel . appendNode (this . forfeitDivision, documentObjectModel . createTextNode (message));
this . forfeitDivision . style . display = "block";
};
this . showPlayerMessage = function (player)
{
var message;
var extension;
if (navigator . userAgent . indexOf ("Firefox") != - 1)
extension = "png";
else
extension = "gif";
if (player == "primary")
this . playerImage . src = "/games/reversi/Reversi/pictures/piece.primary." + extension;
else
this . playerImage . src = "/games/reversi/Reversi/pictures/piece.secondary." + extension;
this . playerDivision . style . display = "block";
return;
};
this . hideForfeitMessage = function ()
{
this . forfeitDivision . style . display = "none";
return;
};
this . setMessage = function (level, message)
{
if (level == "low") this . messageDivision . style . backgroundColor = this . lowMessageColor;
if (level == "medium") this . messageDivision . style . backgroundColor = this . mediumMessageColor;
if (level == "high") this . messageDivision . style . backgroundColor = this . highMessageColor;
documentObjectModel . clearNodes (this . messageDivision);
documentObjectModel . appendNode (this . messageDivision, documentObjectModel . createTextNode (message));
return;
};
this . displayOpponentPlayerTypePrompt = function (delegate)
{
this . setOpponentPlayerTypeDelegate = delegate;
this . setMessage ("medium", "Who would you like to challenge?");
this . opponentPlayerTypeFormDivision . style . display = "block";
this . setOpponentPlayerTypeDelegate ("actual");
return;
};
this . hideOpponentPlayerTypePrompt = function ()
{
this . opponentPlayerTypeFormDivision . style . display = "none";
return;
};
this . displayPinPrompt = function (ownPin, delegate)
{
this . ownPin = ownPin;
this . ownPinArea . value = ownPin;
this . setOpponentPinDelegate = delegate;
this . setMessage ("medium", "please exchange codes with your friend");
this . pinFormDivision . style . display = "block";
return;
};
this . showPins = function (ownPin, opponentPin)
{
this . pinFormDivision . style . display = "none";
this . pinDivision . style . display = "block";
documentObjectModel . appendNode (this . pinDivision, documentObjectModel . createTextNode (ownPin + " : " + opponentPin));
return;
};
this . showDifference = function (difference)
{
var sign = "";
var reversedSign = "";
var span = documentObjectModel . createNode ("span");
span . style . color = "#444444";
if (difference < 0) sign = "- ";
if (difference > 0) sign = "+ ";
if (difference < 0) difference = difference * -1;
if (difference < 0) reversedSign = " -";
if (difference > 0) reversedSign = " +";
this . differenceDivision . style . display = "block";
documentObjectModel . appendNode (span, documentObjectModel . createTextNode (reversedSign));
documentObjectModel . clearNodes (this . differenceDivision);
documentObjectModel . appendNode (this . differenceDivision, documentObjectModel . createTextNode (sign + difference));
documentObjectModel . appendNode (this . differenceDivision, span);
return;
};
this . displaySizePrompt = function (delegate)
{
this . setSizeDelegate = delegate;
this . setMessage ("medium", "please select the board size");
this . sizeFormDivision . style . display = "block";
return;
};
this . showBoardSize = function (boardSize)
{
this . sizeFormDivision . style . display = "none";
this . sizeDivision . style . display = "block";
documentObjectModel . appendNode (this . sizeDivision, documentObjectModel . createTextNode (boardSize + " Board"));
return;
};
this . showOkayButton = function (okayButtonInstructions)
{
this . okayButtonInstructions = okayButtonInstructions;
this . okayButtonDivision . style . display = "block";
return;
};
this . hideOkayButton = function ()
{
this . okayButtonDivision . style . display = "none";
setTimeout (this . okayButtonInstructions, 10);
return;
};
this . getNode = function ()
{
return (this . node);
};
this . render = function (renderNode)
{
documentObjectModel . appendNode (renderNode, this . getNode ());
return;
};
this . setRowPixelCount = function (rowPixelCount)
{
this . node . style . height = (rowPixelCount) + "px";
return;
};
this . setBoardSize = function (heightSquareCount, widthSquareCount)
{
for (var rowIndex = 0; rowIndex < heightSquareCount; rowIndex = rowIndex + 1)
{
this . boardState [rowIndex] = new Array ();
}
for (var rowIndex = 0; rowIndex < heightSquareCount; rowIndex = rowIndex + 1)
for (var columnIndex = 0; columnIndex < widthSquareCount; columnIndex = columnIndex + 1)
{
this . boardState [rowIndex] [columnIndex] = new Array ();
}
return;
};
}
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Reversi) == "undefined") Reversi = new Object ();
Reversi . Board = function ()
{
this . node = null;
this . glassNode = null;
this . rowCount = null;
this . columnCount = null;
this . squareHeight = null;
this . squareWidth = null;
this . height = null;
this . width = null;
this . squareNodes = null;
this . squareColor0 = null;
this . squareColor1 = null;
this . initialize = function ()
{
this . node = documentObjectModel . createNode ("div");
this . glassNode = documentObjectModel . createNode ("div");
this . squareNodes = new Array (new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array (), new Array ());
this . rowCount = 8;
this . columnCount = 8;
this . squareHeight = 50;
this . squareWidth = 50;
this . height = (this . squareHeight + 1) * this . rowCount - 1;
this . width = (this . squareWidth + 1) * this . columnCount - 1;
this . squareColor0 = "#434343";
this . squareColor1 = "#3f3f3f";
this . render ();
};
this . finalize = function ()
{
this . node = null;
this . height = null;
this . width = null;
this . rowCount = null;
this . columnCount = null;
};
this . getNode = function ()
{
return (this . node);
};
this . render = function ()
{
this . node . style . position = "absolute";
this . node . style . top = "0px";
this . node . style . left = "200px";
this . node . style . height = (this . height) + "px";
this . node . style . width = (this . width) + "px";
this . node . style . backgroundColor = "#353535";
this . node . style . border = "#000000 2px solid";
this . node . style . overflow = "hidden";
this . node . style . zIndex = "0";
this . glassNode . style . position = "absolute";
this . glassNode . style . top = "-4px";
this . glassNode . style . left = "-4px";
this . glassNode . style . height = (this . height) + "px";
this . glassNode . style . width = (this . width) + "px";
this . glassNode . style . zIndex = "3";
// if (navigator . userAgent . indexOf ("MSIE") != - 1)
//
// {
// this . height = (this . squareHeight + 1) * this . rowCount - 1 + 4;
// this . width = (this . squareWidth + 1) * this . columnCount - 1 + 4;
// this . node . style . height = (this . height) + "px";
// this . node . style . width = (this . width) + "px";
// this . glassNode . style . height = (this . height) + "px";
// this . glassNode . style . width = (this . width) + "px";
// }
for (var rowIndex = 0; rowIndex < 12; rowIndex = rowIndex + 1)
for (var columnIndex = 0; columnIndex < 12; columnIndex = columnIndex + 1)
{
var node;
node = documentObjectModel . createNode ("div");
node . style . position = "absolute";
node . style . top = (rowIndex * (this . squareHeight + 1)) + "px";
node . style . left = (columnIndex * (this . squareWidth + 1)) + "px";
node . style . height = "50px";
node . style . width = "50px";
node . style . backgroundColor = ((rowIndex % 2) == (columnIndex % 2)) ? this . squareColor0 : this . squareColor1;
this . squareNodes [rowIndex] [columnIndex] = node;
documentObjectModel . appendNode (this . node, node);
}
documentObjectModel . appendNode (this . node, this . glassNode);
};
this . setBoardSize = function (boardSize)
{
if (boardSize == "default" ) this . rowCount = 8;
if (boardSize == "Standard" ) this . rowCount = 8;
if (boardSize == "Small" ) this . rowCount = 8;
if (boardSize == "Medium" ) this . rowCount = 10;
if (boardSize == "Large" ) this . rowCount = 12;
if (boardSize == "default" ) this . columnCount = 8;
if (boardSize == "Standard" ) this . columnCount = 8;
if (boardSize == "Small" ) this . columnCount = 8;
if (boardSize == "Medium" ) this . columnCount = 10;
if (boardSize == "Large" ) this . columnCount = 12;
// if (navigator . userAgent . indexOf ("MSIE") != - 1)
//
// {
// this . height = (this . squareHeight + 1) * this . rowCount - 1 + 4;
// this . width = (this . squareWidth + 1) * this . columnCount - 1 + 4;
// }
//
// else
//
// {
this . height = (this . squareHeight + 1) * this . rowCount - 1;
this . width = (this . squareWidth + 1) * this . columnCount - 1;
// }
this . node . style . height = (this . height) + "px";
this . node . style . width = (this . width) + "px";
this . glassNode . style . height = (this . height) + "px";
this . glassNode . style . width = (this . width) + "px";
};
};
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Reversi) == "undefined") Reversi = new Object ();
Reversi . Piece = function ()
{
this . node = null;
this . ownPredicate = null;
this . reversedPredicate = null;
this . height = null;
this . width = null;
this . initialize = function ()
{
this . node = documentObjectModel . createNode ("div");
this . ownPredicate = 0;
this . reversedPredicate = 0;
this . height = 50;
this . width = 50;
this . node . style . position = "absolute";
this . node . style . top = "0px";
this . node . style . left = "0px";
this . node . style . height = (this . height) + "px";
this . node . style . width = (this . width) + "px";
this . node . style . display = "none";
this . node . style . zIndex = "2";
this . render ();
};
this . finalize = function ()
{
this . node = null;
this . ownPredicate = null;
this . reversedPredicate = null;
this . height = null;
this . width = null;
};
this . getNode = function ()
{
return (this . node);
};
this . setCoordinates = function (rowCoordinate, columnCoordinate)
{
this . node . style . top = (rowCoordinate) + "px";
this . node . style . left = (columnCoordinate) + "px";
};
this . setOwnPredicate = function (predicate)
{
this . ownPredicate = predicate;
this . render ();
};
this . reverse = function ()
{
this . reversedPredicate = 1;
this . render ();
};
this . render = function ()
{
var extension;
if (navigator . userAgent . indexOf ("Firefox") != - 1)
extension = "png";
else
extension = "gif";
if (! this . reversedPredicate)
{
if (this . ownPredicate)
this . node . style . backgroundImage = "url(/games/reversi/Reversi/pictures/piece.primary." + extension + ")";
else
this . node . style . backgroundImage = "url(/games/reversi/Reversi/pictures/piece.secondary." + extension + ")";
}
else
{
if (this . ownPredicate)
this . node . style . backgroundImage = "url(/games/reversi/Reversi/pictures/piece.secondary." + extension + ")";
else
this . node . style . backgroundImage = "url(/games/reversi/Reversi/pictures/piece.primary." + extension + ")";
}
};
};
// MICHAEL MCELROY, MICHAELMCELROY.NET
// COPYRIGHT, 2006, ALL RIGHTS RESERVED
if (typeof (Reversi) == "undefined") Reversi = new Object ();
Reversi . Kayla = function ()
{
this . initialize = function ()
{
application . getMove_Override = application . getMove;
application . getMove = this . play;
return;
};
this . play = function (event)
{
application . opponentMove = kayla . getPreferredMove (); // Remember: Kayla is the opponent.
application . getMove_Override ();
return (false);
};
this . getPreferredMove = function ()
{
var preferredMove = null;
var preferredMoveRank = null;
preferredMove = null;
preferredMoveRank = 0;
if (application . opponentMoves . length == 0)
{
preferredMove = "forfeit";
}
else
{
for (var index = 0; index < application . opponentMoves . length; index = index + 1)
{
var move;
var rank;
move = new Array (application . opponentMoves [index] . split (",") [0] * 1, application . opponentMoves [index] . split (",") [1] * 1);
rank = 0;
rank = rank + this . getScoreDifference (move [0], move [1]);
rank = rank * this . getScoreMultiplier (move [0], move [1]);
if (rank > preferredMoveRank)
{
preferredMove = move;
preferredMoveRank = rank;
}
}
}
messageBox . addMessage ("Notes", "Putting a piece at {" + (preferredMove [0]) + ", " + (preferredMove [1]) + "} for " + (this . getScoreDifference (preferredMove [0], preferredMove [1])) + " " + (((this . getScoreDifference (preferredMove [0], preferredMove [1])) == 1) ? "point" : "points") +". ~ Kayla");
return ((preferredMove == "forfeit") ? preferredMove : (preferredMove [0] + "," + preferredMove [1]));
};
this . getScoreDifference = function (rowIndex, columnIndex)
{
var scoreDifference;
var minimumRowIndex;
var minimumColumnIndex;
var maximumRowIndex;
var maximumColumnIndex;
var rowMultipliers;
var columnMultipliers;
scoreDifference = 0;
minimumRowIndex = 0;
minimumColumnIndex = 0;
maximumRowIndex = application . board . rowCount - 1;
maximumColumnIndex = application . board . columnCount - 1;
rowMultipliers = new Array (-1, -1, -1, 0, 0, 1, 1, 1);
columnMultipliers = new Array (-1, 0, 1, -1, 1, -1, 0, 1);
for (var angleIndex = 0; angleIndex < 8; angleIndex = angleIndex + 1)
{
var potentialDifference;
potentialDifference = 0;
for (var distanceIndex = 1; distanceIndex < 12; distanceIndex = distanceIndex + 1)
{
var targetRowIndex;
var targetColumnIndex;
targetRowIndex = rowIndex + distanceIndex * rowMultipliers [angleIndex];
targetColumnIndex = columnIndex + distanceIndex * columnMultipliers [angleIndex];
if (targetRowIndex >= minimumRowIndex)
if (targetRowIndex <= maximumRowIndex)
if (targetColumnIndex >= minimumColumnIndex)
if (targetColumnIndex <= maximumColumnIndex)
if (application . state . occupancy [targetRowIndex] [targetColumnIndex] == 1)
if (application . state . possession [targetRowIndex] [targetColumnIndex] == 0)
{
potentialDifference = potentialDifference + 1;
}
if (targetRowIndex >= minimumRowIndex)
if (targetRowIndex <= maximumRowIndex)
if (targetColumnIndex >= minimumColumnIndex)
if (targetColumnIndex <= maximumColumnIndex)
if (application . state . occupancy [targetRowIndex] [targetColumnIndex] == 1)
if (application . state . possession [targetRowIndex] [targetColumnIndex] == 1)
{
distanceIndex = 12;
}
if (targetRowIndex >= minimumRowIndex)
if (targetRowIndex <= maximumRowIndex)
if (targetColumnIndex >= minimumColumnIndex)
if (targetColumnIndex <= maximumColumnIndex)
if (application . state . occupancy [targetRowIndex] [targetColumnIndex] == 0)
{
potentialDifference = 0;
distanceIndex = 12;
}
if ((targetRowIndex < minimumRowIndex) || (targetRowIndex > maximumRowIndex) || (targetColumnIndex < minimumColumnIndex) || (targetColumnIndex > maximumColumnIndex))
{
potentialDifference = 0;
distanceIndex = 12;
}
}
scoreDifference = scoreDifference + potentialDifference;
}
scoreDifference = scoreDifference * 2 + 1;
return (scoreDifference);
};
this . getScoreMultiplier = function (rowIndex, columnIndex)
{
var scoreMultiplier;
var minimumRowIndex;
var minimumColumnIndex;
var maximumRowIndex;
var maximumColumnIndex;
scoreMultiplier = 0;
minimumRowIndex = 0;
minimumColumnIndex = 0;
maximumRowIndex = application . board . rowCount - 1;
maximumColumnIndex = application . board . columnCount - 1;
// RANK THE SQUARES BY RINGS (IF THE SQUARE IS IN THE OUTER THREE RINGS).
if ((scoreMultiplier == 0) && (rowIndex == (minimumRowIndex + 0)) && (columnIndex >= (minimumColumnIndex + 0)) && (columnIndex <= (maximumColumnIndex - 0))) scoreMultiplier = 15;
if ((scoreMultiplier == 0) && (rowIndex == (minimumRowIndex + 1)) && (columnIndex >= (minimumColumnIndex + 1)) && (columnIndex <= (maximumColumnIndex - 1))) scoreMultiplier = 7;
if ((scoreMultiplier == 0) && (rowIndex == (minimumRowIndex + 2)) && (columnIndex >= (minimumColumnIndex + 2)) && (columnIndex <= (maximumColumnIndex - 2))) scoreMultiplier = 10;
if ((scoreMultiplier == 0) && (rowIndex == (maximumRowIndex - 2)) && (columnIndex >= (minimumColumnIndex + 2)) && (columnIndex <= (maximumColumnIndex - 2))) scoreMultiplier = 10;
if ((scoreMultiplier == 0) && (rowIndex == (maximumRowIndex - 1)) && (columnIndex >= (minimumColumnIndex + 1)) && (columnIndex <= (maximumColumnIndex - 1))) scoreMultiplier = 7;
if ((scoreMultiplier == 0) && (rowIndex == (maximumRowIndex - 0)) && (columnIndex >= (minimumColumnIndex + 0)) && (columnIndex <= (maximumColumnIndex - 0))) scoreMultiplier = 15;
if ((scoreMultiplier == 0) && (columnIndex == (minimumColumnIndex + 0)) && (rowIndex >= (minimumRowIndex + 0)) && (rowIndex <= (maximumRowIndex - 0))) scoreMultiplier = 15;
if ((scoreMultiplier == 0) && (columnIndex == (minimumColumnIndex + 1)) && (rowIndex >= (minimumRowIndex + 1)) && (rowIndex <= (maximumRowIndex - 1))) scoreMultiplier = 7;
if ((scoreMultiplier == 0) && (columnIndex == (minimumColumnIndex + 2)) && (rowIndex >= (minimumRowIndex + 2)) && (rowIndex <= (maximumRowIndex - 2))) scoreMultiplier = 10;
if ((scoreMultiplier == 0) && (columnIndex == (maximumColumnIndex - 2)) && (rowIndex >= (minimumRowIndex + 2)) && (rowIndex <= (maximumRowIndex - 2))) scoreMultiplier = 10;
if ((scoreMultiplier == 0) && (columnIndex == (maximumColumnIndex - 1)) && (rowIndex >= (minimumRowIndex + 1)) && (rowIndex <= (maximumRowIndex - 1))) scoreMultiplier = 7;
if ((scoreMultiplier == 0) && (columnIndex == (maximumColumnIndex - 0)) && (rowIndex >= (minimumRowIndex + 0)) && (rowIndex <= (maximumRowIndex - 0))) scoreMultiplier = 15;
// DOWNGRADE THE RANK OF SQUARES ON THE OUTER-MOST RING IF THEY ARE NEXT TO AN OPPONENT'S PIECE.
if ((rowIndex == minimumRowIndex) && (columnIndex > minimumColumnIndex) && (columnIndex < maximumColumnIndex) && (((application . state . occupancy [rowIndex + 0] [columnIndex - 1] == 1) && (application . state . possession [rowIndex + 0] [columnIndex - 1] == 0)) || ((application . state . occupancy [rowIndex + 0] [columnIndex + 1] == 1) && (application . state . possession [rowIndex + 0] [columnIndex + 1] == 0)))) scoreMultiplier = 5;
if ((rowIndex == maximumRowIndex) && (columnIndex > minimumColumnIndex) && (columnIndex < maximumColumnIndex) && (((application . state . occupancy [rowIndex - 0] [columnIndex - 1] == 1) && (application . state . possession [rowIndex - 0] [columnIndex - 1] == 0)) || ((application . state . occupancy [rowIndex - 0] [columnIndex + 1] == 1) && (application . state . possession [rowIndex - 0] [columnIndex + 1] == 0)))) scoreMultiplier = 5;
if ((columnIndex == minimumColumnIndex) && (rowIndex > minimumRowIndex) && (rowIndex < maximumRowIndex) && (((application . state . occupancy [rowIndex + 1] [columnIndex + 0] == 1) && (application . state . possession [rowIndex + 1] [columnIndex + 0] == 0)) || ((application . state . occupancy [rowIndex - 1] [columnIndex + 0] == 1) && (application . state . possession [rowIndex - 1] [columnIndex + 0] == 0)))) scoreMultiplier = 5;
if ((columnIndex == maximumColumnIndex) && (rowIndex > minimumRowIndex) && (rowIndex < maximumRowIndex) && (((application . state . occupancy [rowIndex + 1] [columnIndex - 0] == 1) && (application . state . possession [rowIndex + 1] [columnIndex - 0] == 0)) || ((application . state . occupancy [rowIndex - 1] [columnIndex - 0] == 1) && (application . state . possession [rowIndex - 1] [columnIndex - 0] == 0)))) scoreMultiplier = 5;
// UPGRADE THE RANK OF SQUARES ON THE OUTER-MOST RING IF THE MOVE CAN CAPTURE A PIECE NEXT TO IT.
if ((rowIndex == minimumRowIndex) && (columnIndex > minimumColumnIndex) && (columnIndex < maximumColumnIndex))
{
var canCapturePredicate;
canCapturePredicate = 0;
// LEFT OF THE COLUMN INDEX.
for (var index = minimumColumnIndex + 1; index < columnIndex; index = index + 1)
if (application . getFlankPredicate (rowIndex, columnIndex, rowIndex, index) == 1)
canCapturePredicate = 1;
// RIGHT OF THE COLUMN INDEX.
for (var index = columnIndex; index < (maximumColumnIndex - 1); index = index + 1)
if (application . getFlankPredicate (rowIndex, columnIndex, rowIndex, index) == 1)
canCapturePredicate = 1;
if (canCapturePredicate == 1)
scoreMultiplier = 17;
}
if ((rowIndex == maximumRowIndex) && (columnIndex > minimumColumnIndex) && (columnIndex < maximumColumnIndex))
{
var canCapturePredicate;
canCapturePredicate = 0;
// LEFT OF THE COLUMN INDEX.
for (var index = minimumColumnIndex + 1; index < columnIndex; index = index + 1)
if (application . getFlankPredicate (rowIndex, columnIndex, rowIndex, index) == 1)
canCapturePredicate = 1;
// RIGHT OF THE COLUMN INDEX.
for (var index = columnIndex; index < (maximumColumnIndex - 1); index = index + 1)
if (application . getFlankPredicate (rowIndex, columnIndex, rowIndex, index) == 1)
canCapturePredicate = 1;
if (canCapturePredicate == 1)
scoreMultiplier = 17;
}
if ((columnIndex == minimumColumnIndex) && (rowIndex > minimumRowIndex) && (rowIndex < maximumRowIndex))
{
var canCapturePredicate;
canCapturePredicate = 0;
// LEFT OF THE COLUMN INDEX.
for (var index = minimumRowIndex + 1; index < rowIndex; index = index + 1)
if (application . getFlankPredicate (rowIndex, columnIndex, index, columnIndex) == 1)
canCapturePredicate = 1;
// RIGHT OF THE COLUMN INDEX.
for (var index = rowIndex; index < (maximumRowIndex - 1); index = index + 1)
if (application . getFlankPredicate (rowIndex, columnIndex, index, columnIndex) == 1)
canCapturePredicate = 1;
if (canCapturePredicate == 1)
scoreMultiplier = 17;
}
if ((columnIndex == maximumColumnIndex) && (rowIndex > minimumRowIndex) && (rowIndex < maximumRowIndex))
{
var canCapturePredicate;
canCapturePredicate = 0;
// LEFT OF THE COLUMN INDEX.
for (var index = minimumRowIndex + 1; index < rowIndex; index = index + 1)
if (application . getFlankPredicate (rowIndex, columnIndex, index, columnIndex) == 1)
canCapturePredicate = 1;
// RIGHT OF THE COLUMN INDEX.
for (var index = rowIndex; index < (maximumRowIndex - 1); index = index + 1)
if (application . getFlankPredicate (rowIndex, columnIndex, index, columnIndex) == 1)
canCapturePredicate = 1;
if (canCapturePredicate == 1)
scoreMultiplier = 17;
}
// SQUARES NEXT TO THE CORNER SQUARES ARE ALL BUT BANNED.
if ((rowIndex == (minimumRowIndex + 0)) && (columnIndex == (minimumColumnIndex + 0))) scoreMultiplier = 1;
if ((rowIndex == (minimumRowIndex + 1)) && (columnIndex == (minimumColumnIndex + 0))) scoreMultiplier = 1;
if ((rowIndex == (minimumRowIndex + 0)) && (columnIndex == (minimumColumnIndex + 1))) scoreMultiplier = 1;
if ((rowIndex == (minimumRowIndex + 0)) && (columnIndex == (maximumColumnIndex - 0))) scoreMultiplier = 1;
if ((rowIndex == (minimumRowIndex + 1)) && (columnIndex == (maximumColumnIndex - 0))) scoreMultiplier = 1;
if ((rowIndex == (minimumRowIndex + 0)) && (columnIndex == (maximumColumnIndex - 1))) scoreMultiplier = 1;
if ((rowIndex == (maximumRowIndex - 0)) && (columnIndex == (minimumColumnIndex + 0))) scoreMultiplier = 1;
if ((rowIndex == (maximumRowIndex - 1)) && (columnIndex == (minimumColumnIndex + 0))) scoreMultiplier = 1;
if ((rowIndex == (maximumRowIndex - 0)) && (columnIndex == (minimumColumnIndex + 1))) scoreMultiplier = 1;
if ((rowIndex == (maximumRowIndex - 0)) && (columnIndex == (maximumColumnIndex - 0))) scoreMultiplier = 1;
if ((rowIndex == (maximumRowIndex - 1)) && (columnIndex == (maximumColumnIndex - 0))) scoreMultiplier = 1;
if ((rowIndex == (maximumRowIndex - 0)) && (columnIndex == (maximumColumnIndex - 1))) scoreMultiplier = 1;
// CORNER SQUARES ARE VERY DESIRABLE.
if ((rowIndex == minimumRowIndex) && (columnIndex == minimumColumnIndex)) scoreMultiplier = 100;
if ((rowIndex == minimumRowIndex) && (columnIndex == maximumColumnIndex)) scoreMultiplier = 100;
if ((rowIndex == maximumRowIndex) && (columnIndex == minimumColumnIndex)) scoreMultiplier = 100;
if ((rowIndex == maximumRowIndex) && (columnIndex == maximumColumnIndex)) scoreMultiplier = 100;
// THE DEFAULT VALUE.
if ((scoreMultiplier == 0)) scoreMultiplier = 10;
return (scoreMultiplier);
};
};
// ARRANGE TO HAVE THE APPLICATION INITIATED AS SOON AS THE DOCUMENT LOADS.
var setupReversi = function ()
{
showWaitMessage ();
setTimeout ("initializeReversi ();", 500);
};
var initializeReversi = function ()
{
messageBox = new Development . MessageBox ();
messageBox . initiate ();
documentObjectModel = new Network . DocumentObjectModel ();
documentObjectModel . initialize ();
socket = new Network . Socket ();
socket . initialize ();
internetClient = new Network . InternetClient ();
internetClient . initialize ();
application = new Reversi . Application ();
application . initialize ();
};
var showWaitMessage = function ()
{
var documentObjectModel;
documentObjectModel = new Network . DocumentObjectModel ();
documentObjectModel . initialize ();
var division = documentObjectModel . createNode ("div");
var span = documentObjectModel . createNode ("span");
var link = documentObjectModel . createNode ("a");
division . style . color = "#545f36";
division . style . textAlign = "center";
span . style . fontSize = "18px";
span . style . display = "block";
span . style . width = "100%";
span . style . color = "#3e4625";
link . style . color = "#545f36";
link . target = "_blank";
link . href = "http://www.mozilla.com/firefox";
documentObjectModel . appendNode (documentObjectModel . getNode ("game"), division);
documentObjectModel . appendNode (division, span);
documentObjectModel . appendNode (division, documentObjectModel . createNode ("br"));
if (navigator . userAgent . indexOf ("MSIE") != - 1)
{
documentObjectModel . appendNode (division, documentObjectModel . createTextNode ("Internet Explorer requires additional time to initialize the game."));
// documentObjectModel . appendNode (division, documentObjectModel . createTextNode ("Internet Explorer requires extra time to initialize the game."));
// documentObjectModel . appendNode (division, documentObjectModel . createNode ("br"));
// documentObjectModel . appendNode (division, documentObjectModel . createTextNode ("Internet Explorer also requires extra time to start the game, so please be patient."));
// documentObjectModel . appendNode (division, documentObjectModel . createNode ("br"));
// documentObjectModel . appendNode (division, documentObjectModel . createTextNode ("Please consider using "));
// documentObjectModel . appendNode (division, link);
// documentObjectModel . appendNode (division, documentObjectModel . createTextNode ("."));
// documentObjectModel . appendNode (division, documentObjectModel . createNode ("br"));
}
documentObjectModel . appendNode (span, documentObjectModel . createTextNode ("loading ..."));
// documentObjectModel . appendNode (link, documentObjectModel . createTextNode ("Firefox"));
};
var hideWaitMessage = function ()
{
var documentObjectModel;
documentObjectModel = new Network . DocumentObjectModel ();
documentObjectModel . initialize ();
documentObjectModel . clearNodes (documentObjectModel . getNode ("game"));
};