Giter Site home page Giter Site logo

chess's Introduction

Chess

Chess in Java to exercise the usage of different serialization formats.


A small Chess game implementing the default rules by restricting movement of figures, highlighting fields and showing status messages for:

  • Movement of pieces
  • En passant
  • Castling
  • Promotion
  • Check
  • Check mate
  • Stalemate
  • 50-moves-rule

chess_default


Serialization and Deserialization

The game can be saved and loaded using any format. The interface ChessIO can be used to implement a custom format:

ChessIO#load(byte[], ChessBoard) is used to load a byte[] (the first parameter) into the ChessBoard (the second parameter).

ChessIO#save(ChessBoard) is used to serialize the current state of the ChessBoard into a byte[].

To make your own implementation show up in the load / save dialog, simply implement the ChessIO#getFileTypeDescription() and ChessIO#getFileExtension() and add the complete class name to META-INF/services/net.querz.chess.ChessIO.

There are multiple example implementations of linear reading and writing of differend kinds of formats:

Library Location Description
gson net.querz.chess.io.json Saves and loads the game's state as JSON
stax net.querz.chess.io.xml Uses the StAX library to save and load xml files
snakeyaml net.querz.chess.io.yaml Uses the snakeyaml library to save and load yml files
csv net.querz.chess.io.csv Saves and loads the game's state as CSV files
NBT net.querz.chess.io.nbt Uses Tags from my NBT library to load from and save the game's state to gzip compressed NBT files
BSON net.querz.chess.io.bson Loads from and saves the game's state to gzip compressed BSON encoded files
Ini net.querz.chess.io.ini Loads and saves the game state from and to ini files using a simple ini parser
bits net.querz.chess.io.bits An absolutely minimized proprietary format to save the game's state using bit manipulation

FigureFactory.createFigure(Color, String, String, int) can be used to make Figures from basic data. For example:

Figure figure = FigureFactory.createFigure(Color.BLACK, "queen", "c4", 6);

This would create a new instance of Queen on the field C4, which moved the first time on the 6th turn in the game. Keeping track of when the first turn of a figure occured is used to validate Castling and En Passant.

ChessBoard#setFigure(Figure) then sets the Figure to the respective field.

For serialization, the following methods will return all required information to save an entire Chess game:


Godmode

The program can be started in a Test-/Godmode by using the program argument "--godmode". This enables several functions to freely control the ChessBoard and the Pieces. Right-clicking a field shows a context menu to add and remove Pieces, and the options menu in the bottom right corner of the window can now clear the ChessBoard and increment the turn counter (therefore switching the player whose turn it is).

chess_default


chess's People

Contributors

querz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.