Skip to content

Commit

Permalink
Move onDrop handler to main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
byanofsky committed Jul 4, 2017
1 parent a52de6f commit c6a29d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<script src="./js/chess.min.js"></script>
<script src="./js/chessboard-0.3.0.min.js"></script>
<script src="./js/movecalc.js"></script>
<script src="./js/boardconfig.js"></script>
<script src="./js/main.js"></script>
<script src="./js/boardconfig.js"></script>
</html>
17 changes: 0 additions & 17 deletions public/js/boardconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ var onDragStart = function(source, piece, position, orientation) {
}
};

// Check that move is legal, then allow black to move
var onDrop = function(source, target) {
// see if the move is legal
var move = game.move({
from: source,
to: target,
promotion: 'q' // NOTE: always promote to a queen for example simplicity
});

// illegal move
if (move === null) return 'snapback';
console.log(move)

// make random legal move for black
window.setTimeout(makeMove, 250);
};

// Update the board position after the piece snap
// for castling, en passant, pawn promotion
var onSnapEnd = function() {
Expand Down
22 changes: 22 additions & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,25 @@ var playGame = function(algo=4, skillW=2, skillB=2) {
playGame(algo, skillW, skillB);
}, 250);
};

// Handles what to do after human makes move.
// Computer automatically makes next move
var onDrop = function(source, target) {
// see if the move is legal
var move = game.move({
from: source,
to: target,
promotion: 'q' // NOTE: always promote to a queen for example simplicity
});

// If illegal move, snapback
if (move === null) return 'snapback';

// Log the move
console.log(move)

// make move for black
window.setTimeout(function() {
makeMove(4, 3);
}, 250);
};

0 comments on commit c6a29d5

Please sign in to comment.