Code Monkey home page Code Monkey logo

unichess's Introduction

Detailed information can be found in the api docs

♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟
♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖

***

Starting a Game

// Create two Player Objects.
Player<String> p1 = new Player<>("player one", Game.Color.WHITE);
Player<String> p2 = new Player<>("player two", Game.Color.BLACK);

// Create a new Game Object using your players.
Game chessGame = new Game(p1, p2);

Advancing a game

To advance a game, just call chessGame.advance() with a valid algebraic notation string.

Game.GameEvent gameResponse = chessGame.advance("ph4");

The game will attempt to make the move 'ph4' for the current player.

Next we need to check what the game response was:

switch(gameResponse){
	
	// everything went well and the turn has been switched
	case OK:
		break;
	
	// The algebraic notation string needs to be more specific, the turn is the same
	case AMBIGUOUS:
		System.out.println("Ambiguous Move.");
		break;
	
	// The input was gibberish, the turn is the same
	case INVALID:
		System.out.println("Invalid Move.");
		break; 
	
	// The move was valid, but not legal in the current board state
	case ILLEGAL:
		System.out.println("Illegal Move.");					
		break;
	
	// The move put the opposing player in check
	case CHECK:
		System.out.println("You are in check!");
		break;
	
	// The move put the opposing player in checkmate
	case CHECKMATE:
		System.out.println("Checkmate. "+chessGame.getDormantPlayer().getID()+" wins!");
		System.exit(0);
		break;
	
	// The move put the opposing player in stalemate
	case STALEMATE:
		System.out.println("Stalemate. "+chessGame.getDormantPlayer().getID()+" wins!");
		break;
	
	// Both Player objects had their draw fields set to true
	case DRAW:
		System.out.println("Draw!");
		break;
		
}

Printing a game

chessGame.getCurrentBoard().toString();

Will return a string representation of a board, using the Game setting for unicode chars.

A sample board state:

  A  B  C  D  E  F  G  H
8|♜||♞||♝||♛||♚||♝||♞||♜|8
7|♟||♟||♟||♟||♟||♟||♟||♟|7
6| ||·|| ||·|| ||·|| ||·|6
5|·|| ||·|| ||·|| ||·|| |5
4| ||·|| ||·|| ||·|| ||·|4
3|·|| ||·|| ||·|| ||·|| |3
2|♙||♙||♙||♙||♙||♙||♙||♙|2
1|♖||♘||♗||♕||♔||♗||♘||♖|1
  A  B  C  D  E  F  G  H

That's it!

You only have to write code to respond to those events and feed in moves, uniChess will do the rest.

unichess's People

Contributors

cschlisner avatar

Watchers

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