Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: allow boards smaller than 8x8 #198

Open
ivan444 opened this issue Aug 30, 2020 · 12 comments · May be fixed by #199
Open

Feature request: allow boards smaller than 8x8 #198

ivan444 opened this issue Aug 30, 2020 · 12 comments · May be fixed by #199

Comments

@ivan444
Copy link

ivan444 commented Aug 30, 2020

Some games require boards which are smaller than 8x8. Add ability to create smaller boards. Controll it via config.

I'll send a PR.

This was referenced Aug 30, 2020
@slolo2000
Copy link

Hello,

Any chance to see this nice feature in a next release?

Thanks in advance and have a nice day.

@ivan444
Copy link
Author

ivan444 commented Jun 10, 2021 via email

@oakmac
Copy link
Owner

oakmac commented Jun 10, 2021

Any chance to see this nice feature in a next release?

I do not have any plans to add this to chessboard.js at this time (that does not mean "never", just "not right now").

@ivan444 solution looks like a good fix if you need this ASAP 👍 🤓

@slolo2000
Copy link

Maybe if the chess.js library implemented this feature then it would make more sense in chessboardjs.

Anyway, thanks a lot for your answer.

@slolo2000
Copy link

I have had look to the PR #199

var config = {position: fenString, numRows: 6, numColumns: 6};
board = Chessboard('myBoard', config);

It works well and it display a board with 6x6 like expected.
But if the fen string does not respect the real format (with 8 /) the board is not filled with chess pieces.

This issue is due to the validFen function which does not take care of board dimensions.
Also, objToFen and fenToObj functions need to be adapted to support fen string lower than 8 chunks.

@ivan444 Do you think you could add this to your PR #199 ?

Like that the ability to create smaller boards will be fully functional and will be add to chessboardjs, I hope.

@ivan444
Copy link
Author

ivan444 commented Jun 11, 2021

It works well and it display a board with 6x6 like expected.
But if the fen string does not respect the real format (with 8 /) the board is not filled with chess pieces.

@ivan444 Do you think you could add this to your PR #199 ?

That's intentional, as FEN string by definition is 8 characters long. Some assumptions break when using it for smaller boards.

My bad for not making it clear in the PR description

@slolo2000
Copy link

You are right for the FEN string definition.

But for example, this one is valid on a 6x6 board:

6/5p/2N1pk/6/6/K1R3 w - - 1 1

And it could be really useful to support small board for young players when they have to solve chess problems.

@slolo2000
Copy link

Maybe a first step to fully support smaller boards than 8x8

Based on your works @ivan444 I have completed validFen, fenToObj and objToFen functions in order to take in consideration config._boardDimension
It would be nice if you could complete you PR #199 in order to have a better support of small board.

chessboard-1.1.js.zip

@ivan444
Copy link
Author

ivan444 commented Jun 11, 2021

@oakmac what do you think about merging PR #199?

@slolo2000
Copy link

I don't know how to merge my code into your PR and I am not really sure about my code addition.
I have done so tests and it seems to work fine but if you could check what I have done before merging it would be nice.

@ivan444
Copy link
Author

ivan444 commented Jun 11, 2021

@slolo2000 I meant that @oakmac merge PR #199 to the main repo.

You can then add your change base in the main repo. Or you can fork my fork of the repo and create PR based on that (I recomment the former).

@slolo2000
Copy link

Always based on @ivan444 work, I have completed my previous work on "support for smaller boards"

I use it without problem and it seems to work quite nice.

chessboard-1.1.1.js.zip

You can even use this feature with chess.js using a piece of code like below in order to "normalize" your fen string.

// Used to normalize a fen string from smaller board to "normal" chess board
// dimBoardLength: the number of squares in a row/column
function normalizeFenString(fen, dimBoardLength) {
	var deltaFen = 8 - dimBoardLength;
	var position = fen;
	
	if (deltaFen > 0) {
		var fenBegin = fen.replace(/ .+$/, '');
		var fenEnd = fen.replace(fenBegin, '');
		var rows = fenBegin.split('/');

		position = "";
		for (var i = 0; i < deltaFen; i++) {
			if (position != "") {
				position += "/";
			}
			position += "8";
		}
		for (var i = 0; i < rows.length; i++) {
			var c = rows[i].slice(-1);
			if (c.search(/[1-8]/) !== -1) {
				position += "/" + rows[i].substring(0, rows[i].length - 1) + (parseInt(c, 10) + deltaFen).toString();
			} else {
				position += "/" + rows[i] + deltaFen.toString();
			}
		}
		
		position += fenEnd;
	}
	
	return position;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants