Skip to content

Commit

Permalink
Got Tantalus working with just the king off the board
Browse files Browse the repository at this point in the history
? Quite pleased with this even if it turned out to be VERY easy in the end. Just required understanding what was crashing chess.js and fixing it obviously. The problem was when it attempted to castle or at least generate a castling move and then found out there was no king, generating impossible squares. By adding a check that makes sure there's actually a  king present it worked totally fine.

? Tantalus looks so much better with just the king gone. The joke is much stronger, and there's something terrible and funny about playing chess in this context, knowing  you cannot possibly win and can at best end up capturing every black piece, only to have the king perpetually out of reach.
  • Loading branch information
pippinbarr committed Apr 5, 2019
1 parent 4452f40 commit 8168f81
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
51 changes: 26 additions & 25 deletions js/Tantalus.js
Expand Up @@ -4,34 +4,35 @@ class Tantalus extends BaseChess {

constructor () {
super(3);
this.game.load('8/8/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
// this.game.load('8/8/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
this.game.load('rnbq1bnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
this.board.position(this.game.fen(),false);
$('#board').prepend('<div id="black-pieces"></div>');
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bR.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bN.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bB.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bQ.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bK.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bB.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bN.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bR.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bR.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bN.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bB.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bQ.png" style="width: 49px; height: 49px;">`);
$('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bK.png" style="margin-left: 200px; width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bB.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bN.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bR.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
// $('#black-pieces').append(`<img src="img/chesspieces/wikipedia/bP.png" style="width: 49px; height: 49px;">`);
}

moveBlack() {
let fen = this.game.fen();
let fenArray = fen.split(' ');
fenArray[1] = 'w';
fenArray[3] = '-'; // Really don't get how this goes wonky and needs this 'fix'
fen = fenArray.join(' ');
this.game.load(fen);
}
// moveBlack() {
// let fen = this.game.fen();
// let fenArray = fen.split(' ');
// fenArray[1] = 'w';
// fenArray[3] = '-'; // Really don't get how this goes wonky and needs this 'fix'
// fen = fenArray.join(' ');
// this.game.load(fen);
// }

}
18 changes: 15 additions & 3 deletions js/chess.js
Expand Up @@ -504,9 +504,10 @@ var Chess = function(fen) {
function generate_moves(options) {
function add_move(board, moves, from, to, flags) {
if (board[from] === null || board[from] === undefined) {
console.log(board,moves,from,to,flags);
// console.log(board,moves,from,to,flags);
}
/* if pawn promotion */

if (
board[from].type === PAWN &&
(rank(to) === RANK_8 || rank(to) === RANK_1)
Expand Down Expand Up @@ -608,8 +609,9 @@ var Chess = function(fen) {
/* check for castling if: a) we're generating all moves, or b) we're doing
* single square move generation on the king's square
*/
if (!single_square || last_sq === kings[us]) {
if ((!single_square || last_sq === kings[us]) && kings[us] !== -1) {
/* king-side castling */

if (castling[us] & BITS.KSIDE_CASTLE) {
var castling_from = kings[us];
var castling_to = castling_from + 2;
Expand All @@ -626,7 +628,9 @@ var Chess = function(fen) {
}

/* queen-side castling */
if (castling[us] & BITS.QSIDE_CASTLE) {
if (castling[us] & BITS.QSIDE_CASTLE && kings[us] !== -1) {


var castling_from = kings[us];
var castling_to = castling_from - 2;

Expand All @@ -638,6 +642,7 @@ var Chess = function(fen) {
!attacked(them, castling_from - 1) &&
!attacked(them, castling_to)
) {
// console.log(kings[us]);
add_move(board, moves, kings[us], castling_to, BITS.QSIDE_CASTLE);
}
}
Expand All @@ -647,6 +652,7 @@ var Chess = function(fen) {
* to be captured)
*/
if (!legal) {
// console.log("generate_moves returning !legal moves...")
return moves;
}

Expand All @@ -660,6 +666,9 @@ var Chess = function(fen) {
undo_move();
}

// console.log("generate_moves() returning legal_moves...");
// console.log(legal_moves.length);

return legal_moves;
}

Expand Down Expand Up @@ -1287,7 +1296,10 @@ var Chess = function(fen) {
* unnecessary move keys resulting from a verbose call.
*/

// console.log("generating ugly_moves with generate_moves()...")
var ugly_moves = generate_moves(options);
// console.log("generate_moves() returned these ugly_moves...")
// console.log(ugly_moves);
var moves = [];

for (var i = 0, len = ugly_moves.length; i < len; i++) {
Expand Down
8 changes: 6 additions & 2 deletions process/to-do.md
Expand Up @@ -28,9 +28,13 @@

- ~~__LET'S TAKE THE EASY ROUTE FOR NOW__ Fix the fact that chess.js seems to break when you play with no kings (perhaps it's to do with attempting to castle? Or otherwise move something involving the king's square? How to fix this? One option is to move ALL pieces off the board and not have any... the other is to actively change chess.js for this project. Yiiikes.)~~
- ~~Show the black pieces off the top of the board~~
- ~~__LESS OF A PROBLEM NOW? Styling of black pieces isn't great__~~
- ~~__I VASTLY PREFER JUST THE KING__ How do I feel about this "all the pieces" versus "just the king" approach??? (Maybe we could go with no piece but just the king visible off the board as the "apple"?)~~
- ~~__THIS IS CUTE BUT SOUNDS REALLY COMPLEX AND IS SUCH A DELAYED GAG I'm GOING TO GUESS NOBODY WOULD SEE IT__ King steps off the board when in check? (And back on when he wouldn't be in check?)~~
- ~~__FUNNY, BUT A BIT UNWEILDY?__ Two separate chessboards one with black one with white? (Bit weird because it's implying black has the same problem - but maybe if it's just the king...)~~
- ~~__I AM A PROGRAMMING GOD__ Fix chess.js to deal with the situation where black has no king~~

- Styling of black pieces isn't great
- How do I feel about this "all the pieces" versus "just the king" approach???
- Improve styling of the king off the board (proper alignment etc.)

## Danaids

Expand Down

0 comments on commit 8168f81

Please sign in to comment.