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/grid labels #1057

Closed
wants to merge 6 commits into from
Closed

Feature/grid labels #1057

wants to merge 6 commits into from

Conversation

R3dan
Copy link

@R3dan R3dan commented Dec 31, 2023

Grid Labels

Explanation:

This push request adds labels to the __str__ method of chess.Board as mentioned in #971. You can set the label when calling __init__() of chess.Board or __call__() of chess.BaseBoard. By default, labels are displayed on the bottom and left. You can display them with either a list, dictionary or bool:

  • list: enter the first letter of the side (l, b, r, u) of the sides you want to display on
  • dictionary: for every side (as key) enter a bool: True = display and False = don't display
  • bool: True: Display on default sides (bottom and left), False : Don't display any

Examples

Currently:

r n b q k b n r
p p p p p p p p
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
P P P P P P P P
R N B Q K B N R

Default:

1|r n b q k b n r
2|p p p p p p p p
3|. . . . . . . .
4|. . . . . . . .
5|. . . . . . . .
6|. . . . . . . .
7|P P P P P P P P
8|R N B Q K B N R
-+---------------
 |a b c d e f g h

All sides:

 |a b c d e f g h|
-+---------------+-
1|r n b q k b n r|1
2|p p p p p p p p|2
3|. . . . . . . .|3
4|. . . . . . . .|4
5|. . . . . . . .|5
6|. . . . . . . .|6
7|P P P P P P P P|7
8|R N B Q K B N R|8
-+---------------+-
 |a b c d e f g h|

@R3dan
Copy link
Author

R3dan commented Dec 31, 2023

Also if anyone knows what's generating these errors (in my code) I will happily fix, but 5 of these are http requests not found. And the others are "errors" in the code but I don't know where and have tried and tested it.

The numbers had been 8-1 now 1-8. (first digit is bottom row)
@R3dan
Copy link
Author

R3dan commented Dec 31, 2023

Fixed the orders of the numbers

See commit

## Add __str__ options
This allows the program (running the game) to look at the game without the grids. You have to call `__str__` and disable them:
```
board = chess.Board
#no grid labels
print(board.__str__(False)
#with grid labels set earlier
print(board)
```

I also added `__getitem__` to `LegalMoveGenerator` which turns a list of legal moves (similar to `__repr__`)
@R3dan
Copy link
Author

R3dan commented Jan 1, 2024

Add str options

This allows the program (running the game) to look at the game without the grids. You have to call __str__ and disable them:

board = chess.Board
#no grid labels
print(board.__str__(False)
#with grid labels set earlier
print(board)

Legal move list

I also added __getitem__ to LegalMoveGenerator which turns a list of legal moves (similar to __repr__)

See commit

@niklasf
Copy link
Owner

niklasf commented Apr 18, 2024

Sorry to reject this. In the current design, chess.Board instances should carry no more information than is required to describe the position and its history (in particular no orientation and formatting information, so that __eq__ makes sense).

Even as a normal methods, ASCII/Unicode formatting tends to approach a massively configurable mess, because there a so many possible ways to do it, some of which existed in the history of this library. By now I think it's probably best to provide something very simple, and leave customization as an exercise to the reader.

@niklasf niklasf closed this Apr 18, 2024
This pull request was closed.
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 this pull request may close these issues.

2 participants