Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
feat: generate opponent moves by using .moves({ opponent: true })
Browse files Browse the repository at this point in the history
  • Loading branch information
lengyanyu258 committed Apr 25, 2019
1 parent a7da849 commit c8548ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xiangqi.js",
"version": "0.1.4",
"version": "0.2.0",
"description": "A Javascript Chinese chess/cchess/Xiangqi library for xiangqi move generation/validation, piece placement/movement, and check/checkmate/draw detection",
"author": "lengyanyu258 <[email protected]> (https://github.com/lengyanyu258)",
"license": "BSD-2-Clause",
Expand Down
16 changes: 13 additions & 3 deletions xiangqi.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ var Xiangqi = function(fen) {
}
}

// do we need opponent moves?
if (typeof options !== 'undefined' && 'opponent' in options && options.opponent) {
turn = swap_color(turn);
us = turn;
them = swap_color(us);
}

var i, j, len;
for (i = first_sq; i <= last_sq; ++i) {
var piece = board[i];
Expand Down Expand Up @@ -561,6 +568,11 @@ var Xiangqi = function(fen) {
undo_move();
}

// do we needed opponent moves?
if (typeof options !== 'undefined' && 'opponent' in options && options.opponent) {
turn = swap_color(turn);
}

return legal_moves;
}

Expand Down Expand Up @@ -1082,9 +1094,7 @@ var Xiangqi = function(fen) {
var moves = [];

for (var i = 0, len = ugly_moves.length; i < len; i++) {
/* does the user want a full move object (most likely not), or just
* SAN
*/
// does the user want a full move object (most likely not), or just ICCS
if (
typeof options !== 'undefined' &&
'verbose' in options &&
Expand Down
Loading

0 comments on commit c8548ad

Please sign in to comment.