Git Product home page Git Product logo

chive-chess's Introduction

Chive Chess

The project captures the rules of chess, and provides a 'SinglePlayerCommandLineApp' from which the user can play against computer players. The initial computer players, 'RandomComputerPlayer' & 'HeuristicsBasedComputerPlayer' provide basic competition. More sophisticated computerised players are in development.

Motivation

To demonstrate the author's most familiar style of programming - Java in the classical object-oriented style. With usage of Java 8 functional idioms where it feels advantageous.

The game of chess is concise enough to capture the rules and knock up a rudimentary 'app' with a short period of time. But provides significant depth to try out more advanced concepts.

Additionally the author would like to improve his chess playing abilities!

Aspects of Note, Coding Choices Made

  • Unit tests: Junit testing is provided, with fluent assertions. Most attention is made to the game rules. Line coverage is around 90%.
  • Java 8's 'Optional' is used to avoid null references.
  • Java 8's functional idioms - lambda expressions, functional interfaces, Streams, e.g. MoveValidator.java.
  • Static factory methods for object construction to reduce the verbosity of creating 'new' objects.
  • Builder methods for more complex classes that require more granular control, e.g. MoveBuilder.java, ArrayBasedBoard
  • Regex used to interpret user moves from keyboard, see MoveParser
  • ...

Features Implemented

  • Basic rules of chess
  • Command line single player app
  • Draw due to insufficient material
  • Level 2 computer player that assigns a heuristic value to each possible next move and selects the best one.

Features for the Future

  • Feedback chess game/move notation to user
  • Stalemate/draw, which is handled by the app
  • Castling
  • Pawn promotion
  • Implement pawn en passant https://en.wikipedia.org/wiki/En_passant
  • Level 3 computer player uses minimax algorithm to consider the best option over a acceptable depth
  • Level 4 computer player uses minimax with alpha-beta pruning
  • Mechanism to allow computers to play each other
  • Restful API & Web based frontend in React.js

Other Considerations

  • Upgrade to Java 9/10/11

Heuristics based computer player (level 2)

  • Chooses the move with the highest move value
  • If two moves have equivalent score, one is selected at random

Move Value

Based on:

  • Can checkmate
  • Try not to stalemate or draw
  • Captures a piece (each piece has value corresponding to type not position)
  • The move will lead to a better result 1 move in the future

To do:

  • a move that evades capture should attract value
  • Any move will attract value if the to square is protected by one of it's own pieces
  • A non-capturing move will attract value if it 'checks' an opponent piece, especially so if that piece is not protected.
  • Any move will attract value if the to square is considered a 'good position'.
    Initially this will be not be related to position of the pieces.

TwoComputerPlayersCommandLineApp

Pit the computer players against each other to test the player algorithms.

Currently setup so HeuristicsBasedComputerPlayer plays white, and RandomComputerPlayer plays black.

Best result seen for HeuristicsBasedComputerPlayer is checkmate in 13 moves, by moving the rook ahead and across.

  • Todo run 1000 games and work out average victories and moves to victory.

Performance Optimizations

  • Most of the time is in validCheckOrEndGame and moveEndsGame(), and invalidExposeCheck - isPlayerInCheck, potentialMoves
  • Cache the potentialMoves() calls. There can be millions of calls to this method for single move analysis.
    And the potential moves are invariant of the position of the pieces.

chive-chess's People

Contributors

chenery avatar

Watchers

James Cloos 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.