// global namespace
var Reversi = Reversi || {
EMPTY_TYPE: 'e',
BLACK_TYPE: 'b',
WHITE_TYPE: 'w',
BOARD_SIZE: 8
};
Reversi.Game = {
blackPlayer: "John",
whitePlayer: "James",
// new vars
winner: null,
amountBlack: 0,
amountWhite: 0,
amountEmpty: 0,
isMoveBlack: true,
start: function() {
// catch user moves
Reversi.Board.cbClick = this.moveCallback;
// draw board start position
Reversi.Board.init();
Reversi.Board.drawBoard();
Reversi.Board.drawAllDisks();
// using hometask functions first time for displaying start count
// may be not used, then amountBlack and amountWhite var should have value "2"
// for start of the game
this.countScoresForIndicator();
this.updateIndicators();
},
getIndexesColRow: function(index) {
return {
iCol: index % Reversi.BOARD_SIZE,
iRow: Math.floor(index / Reversi.BOARD_SIZE)
}
},
findDiskToFlip: function(moveIndex, type) {
var flipDisks = [];
var startPosition = this.getIndexesColRow(moveIndex);
// find to left, to right, to top, to bottom, to left-top, to right-top, to left-bottom and to right-bottom
for (var h=-1; h<=1; h++) {
for (var v=-1; v<=1; v++) {
if ( h == 0 && v == 0 ) {
continue;
}
var iCol = startPosition.iCol;
var iRow = startPosition.iRow;
//console.log(startPosition);
var tryNext = true;
var lineFlips = [];
while ( tryNext ) {
iCol += h;
iRow += v;
// check limits
if ( iCol < 0 || iCol > Reversi.BOARD_SIZE - 1
|| iRow < 0 || iRow > Reversi.BOARD_SIZE - 1 ) {
break;
}
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.