An iOS / Mac view controller for chess boards

Overview

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:

0.1 ">
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.

You might also like...
🐦 Flappy Bird reincarnation [Swift 5.3, GameplayKit, SpriteKit, iOS 12].
🐦 Flappy Bird reincarnation [Swift 5.3, GameplayKit, SpriteKit, iOS 12].

🐦 Flappy Bird reincarnation [Swift 5.3, GameplayKit, SpriteKit, iOS 12].

Lambton College, 2nd Semester Final IOS Project (Star Wars) game
Lambton College, 2nd Semester Final IOS Project (Star Wars) game

The game we developed for our project of the course advanced iOS application is based on a functioning of a real time shooting game, in which initiall

PlayCover is a project that allows you to sideload iOS apps on macOS( currently arm, Intel support will be tested.

PlayCover Run iOS apps & games on M1 Mac with mouse, keyboard and controller support. Intel macs support will be implemented later. Installation Just

iOS drop-in library presenting a 2048-style game
iOS drop-in library presenting a 2048-style game

iOS-2048 iOS drop-in library presenting a clean-room Objective-C/Cocoa implementation of the game 2048. Screenshot Instructions The included sample ap

The iOS version of 2048, made using SpriteKit

2048 This is a derivative and the iOS version of the game 2048. In the very unlikely case that you don't know what it is, you can check it out here. M

iOS association game chatbot. AI based on neural word embedding language model. Image recognition with convolutional neural net.
iOS association game chatbot. AI based on neural word embedding language model. Image recognition with convolutional neural net.

AssociationBot ##iOS association game chatbot. UI based on JSQMessagesDemo. Association database created with the help of Word2Vec neural word embeddi

Open source release of Canabalt for iOS

Open source release of Canabalt for iOS

An iOS game for horrible people

CardsAgainst App An iOS game for horrible people A peer-to-peer Cards Against Humanity game for iOS, written with Multipeer Connectivity in Swift 4. L

A physics-based cocos2d iOS game

CastleHassle License Copyright (c) 2010-2014 Castle Hassle Permission is hereby granted, free of charge, to any person obtaining a copy of this softwa

Comments
  • Chess pieces don't show up

    Chess pieces don't show up

    Hi everyone! I've imported FDChessboardView via CocoaPods (from git master) and copied datasource from Example But no chess pieces have shown up, only board. I tried to debug and it looks like that chess pieces are being created, but not being drawn. What am I doing wrong?

    One thing that I have noticed is that master branch has SVG images, but in XCode I see PNG images… Maybe that's the case…

    opened by velikanov 3
  • Adopt layout from https://github.com/fulldecent/swift5-module-template

    Adopt layout from https://github.com/fulldecent/swift5-module-template

    A modern project layout for Swift modules is defined at https://github.com/fulldecent/swift5-module-template

    Work plan

    • [ ] Study best practices at link above
    • [ ] Apply the "Recipe" from the Swift 5 Module Template to this project
    • [ ] Ensure that PR does not change the current development team
    • [ ] Convert PNGs to Swift (because Swift Package Manager does not support resources yet), see example in the Recipe
    • [ ] Add support for CocoaPods

    Follow-on work

    • [ ] Make a minor version feature release with this updated project
    opened by fulldecent 1
  • Color SVG

    Color SVG

    We need color SVG for pieces, that means we need a different SVG library:

    Please help be decide between https://github.com/SVGKit/SVGKit https://bitbucket.org/sodastsai/svgimage

    Ideally we want good support for iOS and Mac

    opened by fulldecent 1
  • Document release process

    Document release process

    Including

    • version bump
    • changelog // See format at https://github.com/CocoaPods/CocoaPods
    • tagging
    • CocoaPods push
    • carthage build

    Or maybe just make better commit like this https://github.com/CocoaPods/CocoaPods/commit/3832b47295ec889bd068d6224593b2776b125161

    https://github.com/Alamofire/Alamofire/blob/master/CHANGELOG.md

    opened by fulldecent 0
Releases(3.0.0)
Owner
William Entriken
EN/中文 [email protected]
William Entriken
A simple Chess game for iOS, written in Swift

Swift Chess This is a simple chess game for iPhone and iPad, designed for novice players. It features a very simple AI that plays much like a beginner

Nick Lockwood 135 Jan 6, 2023
Sage is a cross-platform chess library for Swift.

Sage is not a chess engine; it's a move generator. Hexe, on the other hand, is able to both generate moves and evaluate them.

Nikolai Vazquez 368 Dec 29, 2022
ShogibanKit is a framework (not yet) for implementing complex Japanese Chess (Shogii) in Swift. No UI, nor AI.

ShogibanKit Framework Shogi, or Japanese Chess, is based on very complex rules, and it is hard to implement all basic rules. This ShogibanKit aims to

Kaz Yoshikawa 62 Jul 16, 2022
Use iOS devices as game controller for PC via usb-lighting cable.

Xpad v1.0 Use iOS devices as game controller for PC via usb-lighting cable. How to use Prequirments Download all files of this project. [iOS] Open /Xp

Jinglong Zhu 2 Apr 23, 2022
Use iOS devices as game controller for PC via usb-lighting cable.

Xpad v1.0 Use iOS devices as game controller for PC via usb-lighting cable. How to use Prequirments Download all files of this project. [iOS] Open /Xp

Jinglong Zhu 2 Apr 23, 2022
Minesweeper for Mac.

Minesweeper Minesweeper for Mac. System Requirements: ≥ macOS Sierra 10.12 The app icon is not designed for macOS Big Sur or above, but this app is bu

null 84 Aug 4, 2022
蜘蛛纸牌 for mac

蜘蛛纸牌 for Mac 仿 Windows 经典单机游戏 蜘蛛纸牌 已完成 基本游戏功能 难易度设置 分数、步数显示 部分提示音效果 提示音设置 撤销功能 已知问题 拖动牌时鼠标释放位置必须是一列排区域内 无法修改窗口大小 未完成 发牌等动画效果 耗时统计、最好成绩记录 胜利后烟花效果 提示功能

Bug开发者 29 Oct 30, 2022
蜘蛛纸牌 for mac

蜘蛛纸牌 for Mac 仿 Windows 经典单机游戏 蜘蛛纸牌 已完成 基本游戏功能 难易度设置 分数、步数显示 部分提示音效果 提示音设置 撤销功能 胜利后烟花效果 已知问题 拖动牌时鼠标释放位置必须是一列排区域内 无法修改窗口大小 未完成 发牌等动画效果 耗时统计、最好成绩记录 提示功能

Kelvin 29 Oct 30, 2022
The ultimate spinning wheel view that supports dynamic content and rich customization.

The ultimate spinning wheel control that supports dynamic content and rich customization. Main Features ?? Dynamic content, supports texts, images, an

Sherzod Khashimov 250 Dec 27, 2022
A universal iOS Game using Swift and iOS SpriteKit

a universal iOS Game using Swift 4 and iOS SpriteKit.

KooFrank 455 Oct 22, 2022