ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - fulldecent/FDChessboardView: An iOS / Mac view controller for chess boards
An iOS / Mac view controller for chess boards. Contribute to fulldecent/FDChessboardView development by creating an account on GitHub.
Visit Site

GitHub - fulldecent/FDChessboardView: An iOS / Mac view controller for chess boards

GitHub - fulldecent/FDChessboardView: An iOS / Mac view controller for chess boards

FDChessboardView

CI Status Version License Platform Carthage compatible

Features

  • High resolution graphics
  • Customizable themes and game graphics
  • Supports all single board chess variants: suicide, losers, atomic, etc.
  • Supports games with odd piece arrangement and non-standard castling (Fisher 960)
  • Very clean API, this is just a view
  • Supports a minimum deployment target of iOS 8 or OS X Mavericks (10.9)

Installation

Add FDChessboardView to your project using Swift Package Manager. In Xcode that is simply: File > Swift Packages > Add Package Dependency... and you're done. Alternative installations options are shown below for legacy projects.

CocoaPods

If you are already using CocoaPods, just add 'FDChessboardView' to your Podfile then run pod install.

Carthage

If you are already using Carthage, just add to your Cartfile:

github "fulldecent/FDChessboardView" ~> 0.1

Then run carthage update to build the framework and drag the built FDChessboardView.framework into your Xcode project.

Usage

Import the project and implement a data source:

import FDChessboardView

public protocol FDChessboardViewDataSource: class {
    /// What piece is on the square?
    func chessboardView(_ board: FDChessboardView, pieceForSquare square: FDChessboardSquare) -> FDChessboardPiece?

    /// The last move
    func chessboardViewLastMove(_ board: FDChessboardView) -> (from:FDChessboardSquare, to:FDChessboardSquare)?

    /// The premove
    func chessboardViewPremove(_ board: FDChessboardView) -> (from:FDChessboardSquare, to:FDChessboardSquare)?
}

If your application will allow the pieces to be moved, implement a delegate:

public protocol FDChessboardViewDelegate: class {
    /// Where can this piece move to?
    func chessboardView(_ board: FDChessboardView, legalDestinationsForPieceAtSquare from: FDChessboardSquare) -> [FDChessboardSquare]

    /// Before a move happenes
    func chessboardView(_ board: FDChessboardView, canMoveFrom from: FDChessboardSquare, to: FDChessboardSquare, withPromotion promotion: FDChessboardPiece?) -> Bool

    /// After a move happened
    func chessboardView(_ board: FDChessboardView, didMoveFrom from: FDChessboardSquare, to: FDChessboardSquare, withPromotion promotion: FDChessboardPiece?)
}

Then you can customize the view or call certain actions:

/// The location of a square on a chess board
public struct FDChessboardSquare: Hashable {
    /// From 0...7 (a...h)
    public let file: Int
    
    /// From 0...7 (white king starting position to black king starting position)
    public let rank: Int
}

/// The pieces on a chess board
public enum FDChessboardPiece: String {
    case WhitePawn
    case BlackPawn
    case WhiteKnight
    case BlackKnight
    case WhiteBishop
    case BlackBishop
    case WhiteRook
    case BlackRook
    case WhiteQueen
    case BlackQueen
    case WhiteKing
    case BlackKing
}

/// Display for a chess board
@IBDesignable open class FDChessboardView: UIView {
    @IBInspectable open var lightBackgroundColor: UIColor
    @IBInspectable open var darkBackgroundColor: UIColor
    open var targetBackgroundColor: UIColor
    open var legalBackgroundColor: UIColor
    open var lastMoveColor: UIColor
    open var premoveColor: UIColor
    open weak var dataSource: FDChessboardViewDataSource?
    open weak var delegate: FDChessboardViewDelegate?
    open var doesAnimate: Bool
    open var doesShowLegalSquares: Bool
    open var doesShowLastMove: Bool
    open var doesShowPremove: Bool

    /// Add a piece onto the board
    open func setPiece(_ piece: FDChessboardPiece?, forSquare square: FDChessboardSquare)

    /// Repull all board information from data source
    open func reloadData()

    /// Move a piece on the board, clears any prior premove
    open func move(_ piece: FDChessboardPiece, from: FDChessboardSquare, to: FDChessboardSquare, promotedTo promoted: FDChessboardPiece?)
    
    /// Premove a piece on the board, clears any prior premove
    open func premove(_ piece: FDChessboardPiece, from: FDChessboardSquare, to: FDChessboardSquare, promotedTo promoted: FDChessboardPiece?)
    
    /// Removes any premove on the board
    open func clearPremove()
    
    /// Move a piece on the board, clears any prior premove
    open func unmove(_ piece: FDChessboardPiece, from: FDChessboardSquare, to: FDChessboardSquare, promotedTo promoted: FDChessboardPiece?, capturing: FDChessboardPiece)
}

Upcoming features

These following items are in the API for discussion and awaiting implementation:

  • Display for last move
  • Mutable game state (i.e. can move the pieces)
  • Animation for piece moves
  • Highlighting of legal squares for a piece after begin dragging
  • Premove

See also

See also Kibitz for Mac which is making a comeback https://github.com/fulldecent/kibitz

License

FDChessboardView is available under the MIT license. See the LICENSE file for more information.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory