Skip to content

Conversation

@jacksonthall22
Copy link
Contributor

Adds file/rank TypeAliases, constants, and functions to be consistent with those for SQUARES, BB_SQUARES/_RANKS/_FILES, etc.

For example, we could do this already:

  >>> chess.SQUARE_NAMES[chess.E4]
Out[1]: 'e4'

but had to key into files/ranks manually:

>>> chess.FILE_NAMES[4]
Out[2]: 'e'
>>> chess.RANK_NAMES[3]
Out[3]: '4'

now it's a little easier!

>>> chess.FILE_NAMES[chess.FILE_E]
Out[2]: 'e'
>>> chess.RANK_NAMES[chess.RANK_4]
Out[3]: '4'

@Mintas
Copy link

Mintas commented Oct 11, 2025

Hi!
Nice feature, would like to have this one too!

What about making it a bit more concise?

File: TypeAlias = int
FILES = [FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H] = range(8)

and the same for RANKS ?

@niklasf
Copy link
Owner

niklasf commented Oct 11, 2025

Thanks!

Merging as is, because in some IDEs the tooltips are nicer when the constants are explicitly defined like this.

@niklasf niklasf merged commit 1ce4d3f into niklasf:master Oct 11, 2025
24 checks passed
@jacksonthall22
Copy link
Contributor Author

Sweet, thanks for merging @niklasf!

in some IDEs the tooltips are nicer when the constants are explicitly defined like this

Agreed - mostly did like this because SQUARES is now defined the same way (relevant commit, cc @Mintas)

@jacksonthall22 jacksonthall22 deleted the feat/rank-and-file-consts branch October 11, 2025 21:57
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.

3 participants