All Projects → marianogappa → Ostinato

marianogappa / Ostinato

Licence: mit
A chess library that runs on the server (Scala) and on the browser (ScalaJS).

Programming Languages

scala
5932 projects
scalajs
39 projects

Labels

Projects that are alternatives of or similar to Ostinato

Patchbay
An alternative Secure Scuttlebutt client interface that is fully compatible with Patchwork
Stars: ✭ 325 (+673.81%)
Mutual labels:  chess
Chessground
Mobile/Web chess UI for lichess.org
Stars: ✭ 503 (+1097.62%)
Mutual labels:  chess
Game Server
Distributed Java game server, including cluster management server, gateway server, hall server, game logic server, background monitoring server and a running web version of fishing. State machine, behavior tree, A* pathfinding, navigation mesh and other AI tools
Stars: ✭ 916 (+2080.95%)
Mutual labels:  chess
Tensorflow chessbot
Predict chessboard FEN layouts from images using TensorFlow
Stars: ✭ 362 (+761.9%)
Mutual labels:  chess
Pychess
PyChess - a chess client for Linux/Windows
Stars: ✭ 414 (+885.71%)
Mutual labels:  chess
Reddit Pgn To Gif
Converts PGN from /r/chess into gifs hosted on imgur and leaves a reddit comment
Stars: ✭ 16 (-61.9%)
Mutual labels:  chess
Lucaschess
Chess GUI
Stars: ✭ 305 (+626.19%)
Mutual labels:  chess
Countergo
UCI chess engine (golang)
Stars: ✭ 32 (-23.81%)
Mutual labels:  chess
Chessandcard 2dx
收集 cocos2d-x 的棋牌项目,投稿啊,投稿。
Stars: ✭ 477 (+1035.71%)
Mutual labels:  chess
Ancientbeast
Turn Based Strategy Game. Master your beasts! 🐺
Stars: ✭ 907 (+2059.52%)
Mutual labels:  chess
Maia Chess
Maia is a human-like neural network chess engine trained on millions of human games.
Stars: ✭ 360 (+757.14%)
Mutual labels:  chess
Stockfish Mac
Beautiful, powerful chess app for the Mac
Stars: ✭ 404 (+861.9%)
Mutual labels:  chess
Pgnstats
parses PGN files and extracts statistics for chess games
Stars: ✭ 16 (-61.9%)
Mutual labels:  chess
Summer
这是一个支持分布式和集群的java游戏服务器框架,可用于开发棋牌、回合制等游戏。基于netty实现高性能通讯,支持tcp、http、websocket等协议。支持消息加解密、攻击拦截、黑白名单机制。封装了redis缓存、mysql数据库的连接与使用。轻量级,便于上手。
Stars: ✭ 336 (+700%)
Mutual labels:  chess
Colamone js
A two-player strategy board game /オリジナルのボードゲームを作ってみる。
Stars: ✭ 13 (-69.05%)
Mutual labels:  chess
Fishnet
Distributed Stockfish analysis for lichess.org
Stars: ✭ 306 (+628.57%)
Mutual labels:  chess
Realchess
Mod for Minetest to play a realistic chess game (GUI-based)
Stars: ✭ 5 (-88.1%)
Mutual labels:  chess
Sunfish rs
Rust rewrite of the sunfish simple chess engine
Stars: ✭ 41 (-2.38%)
Mutual labels:  chess
Cc65 Chess
Portable chess game in C. Commodore 64, Apple 2, Atari, Oric, Commander X16, curses terminal, etc.
Stars: ✭ 21 (-50%)
Mutual labels:  chess
Chess Variants Training
Chess Variants Training is a website where you can improve at chess variants.
Stars: ✭ 18 (-57.14%)
Mutual labels:  chess

Ostinato A chess library that runs on the server (Scala), on the browser (ScalaJS) and on the REPL.

Build Status GitHub license

Blogpost

Best introduction to the library with code examples in JavaScript, Scala and in the REPL.

Chess Game Parser (using ChessBoardJS)

Tool to paste any chess match in any known notation and browse through the moves via Chessboard. Also play from any board state against the AI, or convert to any other notation.

Chess Game (using ChessBoardJS)

Play a Chess Match against the AI. A hacker will be able to play from whatever board starting position, as white or black, configuring AI's strength and enabling debug mode.

Chess Game Notation Converter

Convert any pasted chess match in any known notation to any other known notation.

Chess Auto-play (using ChessBoardJS)

Two AI's playing each other (making random moves).

Scaladoc

Features

  • Supporting the following Chess notations (with variants): PGN, Algebraic, Figurine, Coordinate, Descriptive, ICCF, Smith and FEN
  • Random and Basic AI available based on minimax with alpha-beta pruning
  • Compiled for JVM and JS => can serve as backend or in the frontend
  • Fully stateless design => thread-safe & scalable; no shared mutable state & no side-effects
  • Functional design; no nulls or exception handling x Object Oriented design with inheritance but no downcasting
  • ostinato.js on the front-end, Akka HTTP Server on the back-end
  • Docker Hub image available; Kubernetes deployment, service and auto-scaling examples on the blogpost

Importing a ChessBoard

$ sbt pack && scala -cp target/pack/lib/ostinato_2.12-1.0.2.jar

scala> import ostinato.chess.core._
import ostinato.chess.core._

// Import a chessboard by drawing it
scala> val game = ChessGame.fromGridString(
        """........
          |........
          |........
          |...♜....
          |........
          |........
          |........
          |........""".stripMargin, turn = BlackChessPlayer).get


// Get available actions (note that the board keeps track of turns; 0 actions for white here!)
scala> val actions = game.board.actions
actions: Set[ostinato.chess.core.ChessAction] = Set(Black's Rook moves to a5, Black's Rook moves to d2, 
Black's Rook moves to d3, ...)

// Print them out! 
scala> actions map game.board.doAction foreach (b => println(b.get + "\n"))
// -> Shows on console (outlined horizontally for brevity)
...♜....    ........    ........    ........    ........    ........    ........
........    ........    ........    ........    ........    ........    ........
........    ...♜....    ........    ........    ........    ........    ........
........    ........    .♜......    ♜.......    .....♜..    ........    ....♜...
........    ........    ........    ........    ........    ........    ........
........    ........    ........    ........    ........    ........    ........
........    ........    ........    ........    ........    ...♜....    ........
........    ........    ........    ........    ........    ........    ........

........    ........    ........    ........    ........    ........    ........
........    ...♜....    ........    ........    ........    ........    ........
........    ........    ........    ........    ........    ........    ........
........    ........    .......♜    ......♜.    ..♜.....    ........    ........
........    ........    ........    ........    ........    ........    ...♜....
........    ........    ........    ........    ........    ...♜....    ........
........    ........    ........    ........    ........    ........    ........
...♜....    ........    ........    ........    ........    ........    ........

Importing a game from any known notation, without specifying which one

it("should parse the same game in different notations") {
      val pgn =
        Notation.parseMatchString("""[Event "Ostinato Testing"]
                                    |[Site "Buenos Aires, Argentina"]
                                    |[Date "2015.??.??"]
                                    |[Round "1"]
                                    |[Result "½–½"]
                                    |[White "Fake Player 1"]
                                    |[Black "Fake Player 2"]
                                    |
                                    |1. e4 e6 2. d4 d5 3. Nc3 Bb4 4. Bb5+ Bd7 5. Bxd7+ Qxd7 6. Nge2
                                    |dxe4 7. 0-0
                                    |""".stripMargin)

      val algebraic =
        Notation.parseMatchString("""e4 e6
                                    |d4 d5
                                    |Nc3 Bb4
                                    |Bb5+ Bd7
                                    |Bxd7+ Qxd7
                                    |Nge2 dxe4
                                    |0-0""".stripMargin)

      val figurine =
        Notation.parseMatchString("""e4 e6
                                    |d4 d5
                                    |♘c3 ♝b4
                                    |♗b5+ ♝d7
                                    |♗xd7+ ♛xd7
                                    |♘ge2 dxe4
                                    |0-0""".stripMargin)

      val coordinate =
        Notation.parseMatchString("""
                                    |1. e2-e4 e7-e6
                                    |2. d2-d4 d7-d5
                                    |3. b1-c3 f8-b4
                                    |4. f1-b5+ c8-d7
                                    |5. b5xd7+ d8xd7
                                    |6. g1-e2 d5xe4
                                    |7. 0-0""".stripMargin)

      val descriptive =
        Notation.parseMatchString("""
                                    |1. P-K4 P-K3
                                    |2. P-Q4 P-Q4
                                    |3. N-QB3 B-N5
                                    |4. B-N5ch B-Q2
                                    |5. BxBch QxB
                                    |6. KN-K2 PxP
                                    |7. 0-0
                                    |""".stripMargin)

      val iccf =
        Notation.parseMatchString("""
                                    |1. 5254 5756
                                    |2. 4244 4745
                                    |3. 2133 6824
                                    |4. 6125 3847
                                    |5. 2547 4847
                                    |6. 7152 4554
                                    |7. 5171""".stripMargin)

      val smith =
        Notation.parseMatchString("""
                                    |1. e2e4  e7e6
                                    |2. d2d4  d7d5
                                    |3. b1c3  f8b4
                                    |4. f1b5  c8d7
                                    |5. b5d7b d8d7b
                                    |6. g1e2  d5e4p
                                    |7. e1g1c""".stripMargin)

      Set(pgn, algebraic, figurine, coordinate, descriptive, iccf, smith) foreach {
        case Right(parsedGame) ⇒
          parsedGame.size shouldBe 13
          parsedGame.last shouldBe (CastlingAction.whiteKingside(), ChessGame.fromString(
            """♜♞..♚.♞♜
              |♟♟♟♛.♟♟♟
              |....♟...
              |........
              |.♝.♙♟...
              |..♘.....
              |♙♙♙.♘♙♙♙
              |♖.♗♕.♖♔.""".stripMargin, turn = BlackChessPlayer, castlingAvailable = castlingOnlyBlackAvailable,
            fullMoveNumber = 7, halfMoveClock = 1
          ).board)
        case _ ⇒
          fail
      }
    }

Some illustrative tests

  • En Passant
    it("should not find en passant take move for black pawn, since king would be threatened") {
      val game = ChessGame.fromGridString(
        """....♖...
          |........
          |...↓....
          |...♙♟...
          |........
          |........
          |....♚...
          |........""".stripMargin).get

      game.whitePlayer.pawns.head.actions(game.board).size shouldBe 1
    }
  • Algebraic Notation
CastlingAction.blackQueenside().toAn shouldBe "0-0-0"
TakeMovement(♝(XY(1, 3), WhiteChessPlayer), XY(1, -1), ♞(XY(2, 2), BlackChessPlayer)).toAn shouldBe "Bxc6"
  • FEN Notation importing/exporting
    it("should encode this board") {
      ChessGame.fromGridString(
        """.......♔
          |........
          |♚.♙.....
          |.......♟
          |........
          |........
          |........
          |........""".stripMargin).get.board.toFen shouldBe "7K/8/k1P5/7p/8/8/8/8"
    }
    it("should decode a chess setup with black en passant in FEN Notation") {
      ChessGame.fromFen("rnbqkbnr/p1pppppp/8/1p6/8/8/PPPPPPPP/RNBQKBNR w KQkq b6 4 5") shouldBe
      Some(ChessGame.fromGridString(
      """♜♞♝♛♚♝♞♜
        |♟.♟♟♟♟♟♟
        |.↓......
        |.♟......
        |........
        |........
        |♙♙♙♙♙♙♙♙
        |♖♘♗♕♔♗♘♖""".stripMargin, turn = WhiteChessPlayer, castlingFullyAvailable, 5, 4).get)
    }    
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].