88 lines
2.0 KiB
Java
88 lines
2.0 KiB
Java
package dev.kske.chess.game;
|
|
|
|
import dev.kske.chess.board.Board;
|
|
import dev.kske.chess.board.Move;
|
|
import dev.kske.chess.board.Piece.Color;
|
|
|
|
/**
|
|
* Acts as the interface between the {@link Game} class and some kind of move
|
|
* generation backend implemented as a subclass.<br>
|
|
* <br>
|
|
* Project: <strong>Chess</strong><br>
|
|
* File: <strong>Player.java</strong><br>
|
|
* Created: <strong>06.07.2019</strong><br>
|
|
*
|
|
* @since Chess v0.1-alpha
|
|
* @author Kai S. K. Engelbart
|
|
*/
|
|
public abstract class Player {
|
|
|
|
protected final Game game;
|
|
protected final Board board;
|
|
|
|
protected String name;
|
|
protected Color color;
|
|
|
|
/**
|
|
* Initializes the color of this player.
|
|
*
|
|
* @param game the game in which this player will be used
|
|
* @param color the piece color that this player will control
|
|
*/
|
|
public Player(Game game, Color color) {
|
|
this.game = game;
|
|
board = game.getBoard();
|
|
this.color = color;
|
|
}
|
|
|
|
/**
|
|
* Initiates a move generation and reports the result to the game by calling
|
|
* {@link Game#onMove(Player, Move)}.
|
|
*/
|
|
public abstract void requestMove();
|
|
|
|
/**
|
|
* Cancels the move generation process.
|
|
*/
|
|
public abstract void cancelMove();
|
|
|
|
/**
|
|
* Closes all resources required for move generation.
|
|
*/
|
|
public abstract void disconnect();
|
|
|
|
/**
|
|
* @return the game in which this player is used
|
|
*/
|
|
public Game getGame() { return game; }
|
|
|
|
/**
|
|
* @return the board on which this player is used
|
|
*/
|
|
public Board getBoard() { return board; }
|
|
|
|
/**
|
|
* @return the color of pieces controlled by this player
|
|
*/
|
|
public Color getColor() { return color; }
|
|
|
|
/**
|
|
* Sets the color of pieces controlled by this player.
|
|
*
|
|
* @param color the color to set
|
|
*/
|
|
public void setColor(Color color) { this.color = color; }
|
|
|
|
/**
|
|
* @return the name of this player
|
|
*/
|
|
public String getName() { return name; }
|
|
|
|
/**
|
|
* Sets the name of this player
|
|
*
|
|
* @param name the name to set
|
|
*/
|
|
public void setName(String name) { this.name = name; }
|
|
}
|