Java_Chess

.idea
    .name 5 B
    artifacts
       Chess_jar.xml 371 B
    compiler.xml 734 B
    copyright
    description.html 97 B
    encodings.xml 171 B
    libraries
       jansi_1_11.xml 214 B
    misc.xml 5 KB
    modules.xml 261 B
    project-template.xml 91 B
    scopes
       scope_settings.xml 143 B
    uiDesigner.xml 8 KB
    vcs.xml 176 B
    workspace.xml 61 KB
Chess.iml 1 KB
Doxyfile 101 KB
GUI_Manual_Testplan.pdf 437 KB
Graphics
    blackBerolinaPawn.png 1 KB
    blackBishop.png 5 KB
    blackKing.png 8 KB
    blackKnight.png 6 KB
    blackPawn.png 2 KB
    blackQueen.png 8 KB
    blackRook.png 3 KB
    blackWazir.png 1 KB
    whiteBerolinaPawn.png 2 KB
    whiteBishop.png 7 KB
    whiteKing.png 8 KB
    whiteKnight.png 7 KB
    whitePawn.png 4 KB
    whiteQueen.png 10 KB
    whiteRook.png 4 KB
    whiteWazir.png 2 KB
README 342 B
jansi-1.11.jar 111 KB
src
    CHANGES 1001 B
    GUI
       Controller.java 15 KB
       Main.java 360 B
       View.java 14 KB
       textPanel.java 776 B
    Game
       Board.java 5 KB
       CLI.java 5 KB
       Command.java 1022 B
       GameManager.java 11 KB
       GameType.java 74 B
       MoveHandler.java 1 KB
       Player.java 133 B
    META-INF
       MANIFEST.MF 53 B
    Main.java 154 B
    Pieces
       BerolinaPawn.java 1 KB
       Bishop.java 480 B
       BoardSquare.java 4 KB
       King.java 470 B
       Knight.java 846 B
       MoveType.java 530 B
       Pawn.java 1 KB
       Queen.java 474 B
       Rook.java 471 B
       Wazir.java 627 B
    TODO 176 B
    Tests
       BoardTest.java 2 KB
       GameManagerTest.java 21 KB
BoardSquare.java
package Pieces;

import Game.*;

public class BoardSquare {

    public int x;
    public int y;

    /**
     * ASCII char representing the piece for PGN notation and the CLI
     */
    public char symbol;

    /**
     * The name of the image for this piece
     */
    public String imagename;

    /**
     * Specifies if the piece can move horizontally.
     */
    boolean horiz;

    /**
     * Specifies if the piece can move vertically.
     */
    boolean vert;

    /**
     * Specifies if the piece can move diagonally.
     */
    boolean diag;
    /**
     * Specifies if the piece can move bidirectioanlly.
     */
    boolean bidirectional;

    /**
     * Number of squares the piece can move, 0 if infinite.
     */
    int limit;


    /**
     * Player who owns this piece.
     */
    public Player owner;

    /**
     * Used for pawn first move.
     */
    public boolean hasMoved;

    public BoardSquare(){
        this.hasMoved = false;
        horiz = false;
        vert = false;
        diag = false;
        bidirectional = false;
        limit = 1;

        symbol = ' ';
        imagename = null;
    }
    public BoardSquare(int x, int y, Player player){
        this();
        this.x = x;
        this.y = y;
        this.owner = player;
    }

    /**
    Make a copy of the current piece.
     */
    public BoardSquare copy(BoardSquare old){
        BoardSquare ret = null;
        try {
             ret = old.getClass().newInstance();
        } catch (InstantiationException e){
            System.out.println("Exception!");
        } catch (IllegalAccessException e){
            System.out.println("Exception!");
        }

        return ret;
    }

    /**
    Check if this move is allowed with this Piece's moveset.

    This function can be replaced in inherited classes if needed, for the default chess pieces this was only overridden for the Pieces.Knight.

    @param gameBoard The game board to check the move with
    @param startSquare Starting position
    @param destSquare ending position
    @return true on success, false on not allowed move.
     */
    public boolean MoveThis(Board gameBoard, BoardSquare startSquare, BoardSquare destSquare){

        MoveType moveType = MoveHandler.DetermineType(startSquare, destSquare);
        //Attempt special moves such as pawn capture, pawn first move
        SpecialMoveReturn special = startSquare.SpecialMove(startSquare, destSquare, moveType, gameBoard);
        if(special == SpecialMoveReturn.INVALID)
            return false;
        if(special == SpecialMoveReturn.VALID)
            return true;


        //Return 0 if this Piece is not allowed to move vertically.
        if(moveType.direction == MoveType.Direction.VERT && !startSquare.vert)
            return false;

        if(moveType.direction == MoveType.Direction.HORIZ && !startSquare.horiz)//Return 0 if this Piece is not allowed to move horizontally.
            return false;

        if(moveType.direction == MoveType.Direction.DIAG && !startSquare.diag)//Return 0 if this Piece is not allowed to move diagonally.
            return false;

        if(gameBoard.findPieces(startSquare, destSquare, Math.abs(moveType.distance)))//Return 0 if pieces are in the way
            return false;

        if(moveType.distance==0)//Return 0 if distance is 0.
            return false;

        if(moveType.distance<0 && !startSquare.bidirectional)//Return 0 if this Piece is not allowed to move backwards.
            return false;

        if(startSquare.limit != 0 && startSquare.limit < Math.abs(moveType.distance))//Return if the Piece attempts to move farther than allowed.
            return false;//move refused


        return true;

    }

    /**
    Function to use a piece's special/custom defined move.

    The only default chess Piece using this function is the Pieces.Pawn.

     @param startSquare Starting position
     @param destSquare ending position
     @param moveType a MoveType containing the type of move being attempted.
     @return a SpecialMoveReturn enum.
     */
    public SpecialMoveReturn SpecialMove(BoardSquare startSquare, BoardSquare destSquare, MoveType moveType, Board gameBoard){
        return SpecialMoveReturn.NONEXISTANT;
    }

    /**
     * Signifies if a special move was not found, not allowed, or is allowed.
     */
    public enum SpecialMoveReturn{
        VALID, INVALID, NONEXISTANT
    }

}