Skip to content

Commit

Permalink
Merge pull request #1 from AndreSteenveld/testclean
Browse files Browse the repository at this point in the history
Cleaning up Chessy so it can be used as a stand alone engine
  • Loading branch information
AndreSteenveld committed Jun 11, 2014
2 parents c9b2b84 + 1f81d87 commit ec6b330
Show file tree
Hide file tree
Showing 1,358 changed files with 2,549 additions and 136,536 deletions.
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,6 +1,7 @@

/node_modules
*.bak
/chess.NB125.ast.pui
/chess.prj
/chess.vfs
/script/dojo*
/script/dojo*
npm-debug.log
3 changes: 0 additions & 3 deletions .gitmodules
Expand Up @@ -8,6 +8,3 @@
path = script/dijit
url = C:/Users/Andre/work/externals/dijit

[submodule "script/util"]
path = script/util
url = C:/Users/Andre/work/externals/util
2 changes: 2 additions & 0 deletions chessy.js
@@ -0,0 +1,2 @@

module.exports = require( "./script/main.js" );
26 changes: 26 additions & 0 deletions package.json
@@ -0,0 +1,26 @@
{
"name": "Chessy",
"version": "0.0.0",
"description": "",
"main": "chessy.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/AndreSteenveld/Chessy.git"
},
"author": "Andre Steenveld",
"license": "MIT",
"bugs": {
"url": "https://github.com/AndreSteenveld/Chessy/issues"
},
"homepage": "https://github.com/AndreSteenveld/Chessy",
"devDependencies": {
"nodeunit": "^0.9.0"
},
"dependencies": {
"compose": "https://api.github.com/repos/andresteenveld/compose/tarball",
"rsvp": "^3.0.9"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
126 changes: 70 additions & 56 deletions script/chess/board/Board.js → script/board/Board.js
Expand Up @@ -3,16 +3,74 @@
* Licensed under the MIT public license for the full license see the LICENSE file
*
*/
define([
"..",
".",
"lib",
"./Field" /*jsl:import ./Field.js*/

], function( chess, board, lib, Field ){

board.Board = lib.declare( [ ], {
// All the fields we have on the board, the pieces and other properties we need to know about
var Compose = require( "compose" ),
Field = require( "./Field" );

module.exports = Compose(

function( ){
var board = this,
xNames = this.xNames = [ "a", "b", "c", "d", "e", "f", "g", "h" ],
yNames = this.yNames = [ "1", "2", "3", "4", "5", "6", "7", "8" ];

this.pieces = [ ];
this.piecesInPlay = [ ];
this.piecesOutOfPlay = [ ];
this.whitePiecesInPlay = [ ];
this.blackPiecesInPlay = [ ];

var fieldsByCoordinate = this.fieldsByCoordinate = xNames.map( function( x, xCoordinate ){
return yNames.map( function( y, yCoordinate ){
return new Field({
x: xCoordinate,
y: yCoordinate,

xName: x,
yName: y,

board: board
});
});
});

var fieldsByName = this.fieldsByName = Object.create( fieldsByCoordinate );

fieldsByCoordinate
.reduce( function( fields, row ){ return fields.concat( row ) }, [ ] )
.forEach( function( field ){

fieldsByName[ field.xName + field.yName ] = field;

});

this.fields = Object.create( fieldsByName );

this.white = Object.create( this.fields );
this.white.pieces = this.whitePiecesInPlay;

this.black = Object.create( fieldsByName );

fieldsByCoordinate
.reduce(
function( reversed, column ){
reversed.unshift( [ ].concat( column ).reverse( ) );
return reversed;
}
, [ ]
)
.forEach(
function( column, index ){
this.black[ index ] = column;
}
, this
);

this.black.pieces = this.blackPiecesInPlay;

},

{
// All the fields we have on the board, the pieces and other properties we need to know about
// the board.
fields: null,
fieldsByName: null,
Expand All @@ -32,49 +90,6 @@ define([
xNames: null,
yNames: null,

constructor: function( ){
var board = this,
xNames = this.xNames = [ "a", "b", "c", "d", "e", "f", "g", "h" ],
yNames = this.yNames = [ "1", "2", "3", "4", "5", "6", "7", "8" ],
fieldsByName = this.fieldsByName = { };

this.pieces = [ ];
this.piecesInPlay = [ ];
this.piecesOutOfPlay = [ ];
this.whitePiecesInPlay = [ ];
this.blackPiecesInPlay = [ ];

var fieldsByCoordinate = this.fieldsByCoordinate = xNames.map( function( x, xCoordinate ){
return yNames.map( function( y, yCoordinate ){
var field = new Field({
x: xCoordinate,
y: yCoordinate,

xName: x,
yName: y,

board: board
});

fieldsByName[ x + y ] = field;

return field;
});
});

this.fields = lib.delegate( fieldsByName, fieldsByCoordinate );

this.white = lib.delegate( this.fields, { pieces: this.whitePiecesInPlay });

// TODO: Rewrite this to a reduce that makes sense.
var blackBoard = lib.delegate( fieldsByName, fieldsByCoordinate
.map( function( column ){ return [ ].concat( column ).reverse( ); })
.reverse( )
);

this.black = lib.delegate( blackBoard, { pieces: this.blackPiecesInPlay });
},

clone: function( ){
var board = new chess.board.Board( );

Expand Down Expand Up @@ -217,7 +232,6 @@ define([
}
);
}
});
}

return board.Board;
});
);
67 changes: 36 additions & 31 deletions script/chess/board/Field.js → script/board/Field.js
Expand Up @@ -3,9 +3,24 @@
* Licensed under the MIT public license for the full license see the LICENSE file
*
*/
define([ ".", "lib" ], function( board, lib ){
var Compose = require( "compose" );

board.Field = lib.declare( [ ], {
module.exports = Compose(

function( _field_ ){
this.x = _field_.x;
this.y = _field_.y;

this.board = _field_.board;

this.xName = _field_.xName;
this.yName = _field_.yName;
this.name = this.xName + this.yName;

this.looking = [ ];
},

{
piece: null,
board: null,

Expand All @@ -18,19 +33,6 @@ define([ ".", "lib" ], function( board, lib ){

looking: null,

constructor: function( _field_ ){
this.x = _field_.x;
this.y = _field_.y;

this.board = _field_.board;

this.xName = _field_.xName;
this.yName = _field_.yName;
this.name = this.xName + this.yName;

this.looking = [ ];
},

leave: function( piece ){
// Firstly we are going to check if we really are who we say we are.
if( piece === this.piece ){
Expand Down Expand Up @@ -64,6 +66,21 @@ define([ ".", "lib" ], function( board, lib ){
},

occupy: function( piece, previousField ){

function unOccupy( piece, previousField, previousPiece ){

if( !!previousPiece ){

this.board.removeFromPlay( previousPiece, true );
previousPiece.place( this.board, this );

}

this.board.removeFromPlay( piece, true );
piece.place( this.board, previousField );

}

var previousPiece = this.piece;

this.piece && this.board.removeFromPlay( this.piece );
Expand All @@ -76,19 +93,8 @@ define([ ".", "lib" ], function( board, lib ){
});

if( previousField ){
return Function.bind( this, function unOccupy( ){

if( !!previousPiece ){

this.board.removeFromPlay( previousPiece, true );
previousPiece.place( this.board, this );

}

this.board.removeFromPlay( piece, true );
piece.place( this.board, previousField );

});

return unOccupy.bind( this, piece, previousField, previousPiece );
}
},

Expand All @@ -101,7 +107,6 @@ define([ ".", "lib" ], function( board, lib ){
toString: function( ){
return "[Field " + this.name + "]";
}
});
}

return board.Field;
});
);
43 changes: 0 additions & 43 deletions script/chess/main.js

This file was deleted.

22 changes: 0 additions & 22 deletions script/chess/pieces/Bishop.js

This file was deleted.

0 comments on commit ec6b330

Please sign in to comment.