Skip to content

drkameleon/fianchetto.art

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess-aware components / custom types,
and more...




What does this package do?

This package includes different useful types for chess programming & analysis: pieces, boards, moves, positions, games. It also comes with FEN & PGN parsing/output capabilities and can - potentially - serve as the foundation of other chess-related apps & packages.

How do I use it?

Simply import it and use any of the provided helper functions or types:

import .withHelpers "fianchetto"!

; Let's create a new chess game!
game: newGame ø!

; What about showing the FEN string?
print ["Initial FEN:" game\position]

; Make moves using coordinates
game\makeMove "e2e4"
game\makeMove "e7e5"
game\makeMove "g1f3"

; and... let's print board!
print "Final position:"
print game\position\board

Will produce:

Initial FEN: rnbkqbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBKQBNR w KQkq - 0 1 
Final position:
+---+---+---+---+---+---+---+---+
| r | n | b | q | k | b | n | r |
| p | p | p | p | - | p | p | p |
| - | - | - | - | - | - | - | - |
| - | - | - | - | p | - | - | - |
| - | - | - | - | P | - | - | - |
| - | - | - | - | - | N | - | - |
| P | P | P | P | - | P | P | P |
| R | N | B | Q | K | B | - | R |
+---+---+---+---+---+---+---+---+

Type reference

chessCoords

Mainly used to hold square coordinates, or a file-rank pair.

constructor
to :chessCoords [coords :string :block :integer]
fields
  • \file
  • \rank
methods
  • \index

chessPiece

The main chess piece representation

constructor
to :chessPiece [ch :char :literal :string]
fields
  • \color
  • \kind
methods
  • \white?
  • \getMovePattern [fromSq :chessCoords, toSq :chessCoords]

chessMove

A move type, encapsulating an origin and a target square.

constructor
to :chessMove [coordset :string :block]
fields
  • \fromSq
  • \toSq

chessBoard

The main chess board

constructor
to :chessBoard []
fields
  • \squares
methods
  • \getPiece [coords :chessCoords]
  • \setPiece [coords :chessCoords piece :null :chessPiece]

chessPosition

A given chess position

constructor
to :chessPosition [source :string :null]
fields
  • \board
  • \activeColor
  • \castling
  • \enPassant
  • \halfmove
  • \fullmove
methods
  • \validateMove [newMove :chessMove]
  • \applyMove [newMove :chessMove]

Tip

You can initialize a :chessPosition by directly using a FEN string; or exporting a given position back to FEN, using to :string. 😉

chessGame

The main chess game container

constructor
to :chessGame [source :string :null]
fields
  • \position
  • \moves
  • \result
  • \metadata
methods
  • \makeMove: [coords :chessMove :string]

Warning

Although the future goal of the :chessGame constructor is to fully support any type of PGN file input, right now support should be considered extremely limited!


License

MIT License

Copyright (c) 2024 Yanis Zafirópulos

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.