2019-07-07 13:53:57 +02:00
|
|
|
package dev.kske.chess.game;
|
|
|
|
|
|
|
|
import dev.kske.chess.board.Board;
|
2020-01-19 22:12:33 +01:00
|
|
|
import dev.kske.chess.board.Move;
|
2019-07-07 13:53:57 +02:00
|
|
|
import dev.kske.chess.board.Piece.Color;
|
|
|
|
|
|
|
|
/**
|
2020-01-19 22:12:33 +01:00
|
|
|
* Acts as the interface between the {@link Game} class and some kind of move
|
|
|
|
* generation backend implemented as a subclass.<br>
|
|
|
|
* <br>
|
2019-07-07 13:53:57 +02:00
|
|
|
* Project: <strong>Chess</strong><br>
|
|
|
|
* File: <strong>Player.java</strong><br>
|
|
|
|
* Created: <strong>06.07.2019</strong><br>
|
2020-01-19 22:12:33 +01:00
|
|
|
*
|
2019-10-26 07:55:21 +02:00
|
|
|
* @since Chess v0.1-alpha
|
|
|
|
* @author Kai S. K. Engelbart
|
2019-07-07 13:53:57 +02:00
|
|
|
*/
|
|
|
|
public abstract class Player {
|
|
|
|
|
2020-05-19 16:50:12 +02:00
|
|
|
protected final Game game;
|
|
|
|
protected final Board board;
|
2020-02-23 21:21:19 +01:00
|
|
|
|
2020-05-19 16:50:12 +02:00
|
|
|
protected String name;
|
|
|
|
protected Color color;
|
2019-07-07 13:53:57 +02:00
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* Initializes the color of this player.
|
|
|
|
*
|
2020-02-23 21:21:19 +01:00
|
|
|
* @param game the game in which this player will be used
|
2020-01-19 22:12:33 +01:00
|
|
|
* @param color the piece color that this player will control
|
|
|
|
*/
|
2020-02-23 21:21:19 +01:00
|
|
|
public Player(Game game, Color color) {
|
2020-05-19 16:50:12 +02:00
|
|
|
this.game = game;
|
|
|
|
board = game.getBoard();
|
|
|
|
this.color = color;
|
2020-02-23 21:21:19 +01:00
|
|
|
}
|
2019-07-07 13:53:57 +02:00
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* Initiates a move generation and reports the result to the game by calling
|
|
|
|
* {@link Game#onMove(Player, Move)}.
|
|
|
|
*/
|
2019-07-07 13:53:57 +02:00
|
|
|
public abstract void requestMove();
|
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* Cancels the move generation process.
|
|
|
|
*/
|
2019-07-14 12:03:45 +02:00
|
|
|
public abstract void cancelMove();
|
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* Closes all resources required for move generation.
|
|
|
|
*/
|
2019-07-18 15:01:15 +02:00
|
|
|
public abstract void disconnect();
|
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* @return the game in which this player is used
|
|
|
|
*/
|
2019-07-07 13:53:57 +02:00
|
|
|
public Game getGame() { return game; }
|
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* @return the board on which this player is used
|
|
|
|
*/
|
2019-07-07 13:53:57 +02:00
|
|
|
public Board getBoard() { return board; }
|
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* @return the color of pieces controlled by this player
|
|
|
|
*/
|
2019-07-07 13:53:57 +02:00
|
|
|
public Color getColor() { return color; }
|
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* Sets the color of pieces controlled by this player.
|
|
|
|
*
|
|
|
|
* @param color the color to set
|
|
|
|
*/
|
2019-07-07 13:53:57 +02:00
|
|
|
public void setColor(Color color) { this.color = color; }
|
2019-07-26 16:14:22 +02:00
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* @return the name of this player
|
|
|
|
*/
|
2019-07-26 16:14:22 +02:00
|
|
|
public String getName() { return name; }
|
|
|
|
|
2020-01-19 22:12:33 +01:00
|
|
|
/**
|
|
|
|
* Sets the name of this player
|
|
|
|
*
|
|
|
|
* @param name the name to set
|
|
|
|
*/
|
2019-07-26 16:14:22 +02:00
|
|
|
public void setName(String name) { this.name = name; }
|
2019-07-07 13:53:57 +02:00
|
|
|
}
|