Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
Слияние с qbot
Browse files Browse the repository at this point in the history
  • Loading branch information
Chae4ek committed Aug 5, 2021
1 parent 04e8762 commit e23401e
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 155 deletions.
20 changes: 10 additions & 10 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.deeplay</groupId>
<artifactId>QChess</artifactId>
<version>0.0.1</version>
</parent>

<artifactId>QChess-client</artifactId>
<version>0.0.1</version>

<build>
<plugins>
Expand Down Expand Up @@ -63,20 +72,11 @@
<version>0.0.1</version>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>QChess</artifactId>
<groupId>io.deeplay</groupId>
<version>0.0.1</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<version>0.0.1</version>

</project>
10 changes: 5 additions & 5 deletions client/src/main/java/io/deeplay/qchess/client/dao/GameDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ public static void setEnemy(PlayerType playerType) {
Database.getInstance().setEnemyType(playerType);
}

/** @return тип игрока клиента */
public static PlayerType getMyType() {
return Database.getInstance().getMyType();
}

/** Устанавливает тип игрока клиента */
public static void setMyType(PlayerType playerType) {
Database.getInstance().setMyType(playerType);
}

/** @return тип игрока клиента */
public static PlayerType getMyType() {
return Database.getInstance().getMyType();
}

/** @return настройки текущей игры */
public static GameSettings getGameSettings() {
return Database.getInstance().getGameSettings();
Expand Down
22 changes: 11 additions & 11 deletions clientserverconversation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.deeplay</groupId>
<artifactId>QChess</artifactId>
<version>0.0.1</version>
</parent>

<artifactId>QChess-client-server-conversation</artifactId>
<version>0.0.1</version>

<dependencies>
<!-- Gson -->
<dependency>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.7</version>
</dependency>
<!-- QChess modules -->
Expand All @@ -19,19 +28,10 @@
</dependency>
</dependencies>

<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>QChess</artifactId>
<groupId>io.deeplay</groupId>
<version>0.0.1</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<version>0.0.1</version>

</project>
20 changes: 10 additions & 10 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.deeplay</groupId>
<artifactId>QChess</artifactId>
<version>0.0.1</version>
</parent>

<artifactId>QChess-core</artifactId>
<version>0.0.1</version>

<build>
<plugins>
Expand Down Expand Up @@ -56,20 +65,11 @@
<version>0.0.1</version>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>QChess</artifactId>
<groupId>io.deeplay</groupId>
<version>0.0.1</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<version>0.0.1</version>

</project>
24 changes: 12 additions & 12 deletions game/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.deeplay</groupId>
<artifactId>QChess</artifactId>
<version>0.0.1</version>
</parent>

<artifactId>QChess-game</artifactId>
<version>0.0.1</version>

<build>
<plugins>
Expand Down Expand Up @@ -52,31 +61,22 @@
<dependency>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
<scope>test</scope>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<!-- Gson -->
<dependency>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.7</version>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>QChess</artifactId>
<groupId>io.deeplay</groupId>
<version>0.0.1</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<maven.test.skip>false</maven.test.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<version>0.0.1</version>

</project>
2 changes: 1 addition & 1 deletion game/src/main/java/io/deeplay/qchess/game/Selfplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void run() throws ChessError {
// TODO: отправлять ответ GameResponse, что ход некорректный
throw new IllegalArgumentException("некорректный ход");
}
egd.updateEndGameStatus();
egd.updateEndGameStatus(currentPlayerToMove.getColor());
}
switch (egd.getGameResult()) {
case NOTHING -> throw new ChessError(GAME_RESULT_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class EndGameDetector {
Arrays.asList(FigureType.KING, FigureType.KNIGHT, FigureType.KNIGHT));

private final GameSettings gs;
private EndGameType prevGameResult = EndGameType.NOTHING;
private EndGameType gameResult = EndGameType.NOTHING;

public EndGameDetector(GameSettings gs) {
Expand All @@ -34,42 +35,70 @@ public EndGameType getGameResult() {
return gameResult;
}

public void resetGameResult() {
public void resetEndGameStatus() {
gameResult = EndGameType.NOTHING;
}

public void revertEndGameStatus() {
gameResult = prevGameResult;
}

public EndGameType updateEndGameStatus() {
prevGameResult = gameResult;
gameResult = EndGameType.NOTHING;
if (isStalemate(Color.WHITE)) {
gameResult =
isCheck(Color.WHITE)
? EndGameType.CHECKMATE_TO_WHITE
: EndGameType.STALEMATE_TO_WHITE;
} else if (isStalemate(Color.BLACK)) {
gameResult =
isCheck(Color.BLACK)
? EndGameType.CHECKMATE_TO_BLACK
: EndGameType.STALEMATE_TO_BLACK;
} else {
if (isDrawWithRepetitions()) gameResult = EndGameType.DRAW_WITH_REPETITIONS;
else if (isDrawWithNotEnoughMaterialForCheckmate())
gameResult = EndGameType.DRAW_WITH_NOT_ENOUGH_MATERIAL;
else if (isDrawWithPeaceMoves()) gameResult = EndGameType.DRAW_WITH_PEACE_MOVE_COUNT;
}
return gameResult;
}

/** @return результат игры для цвета color */
public EndGameType updateGameResult(Color color) {
return updateGameResult(gs.moveSystem.getAllCorrectMovesSilence(color), color);
public EndGameType updateEndGameStatus(Color color) {
return updateEndGameStatus(gs.moveSystem.getAllCorrectMovesSilence(color), color);
}

/**
* @param allMoves все доступные ходы цвета color
* @return результат игры для цвета color, у которого все доступные ходы в allMoves
*/
public EndGameType updateGameResult(List<Move> allMoves, Color color) {
public EndGameType updateEndGameStatus(List<Move> allMoves, Color color) {
gameResult = EndGameType.NOTHING;
if (isStalemate(allMoves)) {
gameResult = isCheck(color) ? EndGameType.CHECKMATE : EndGameType.STALEMATE;
gameResult =
isCheck(color)
? color == Color.WHITE
? EndGameType.CHECKMATE_TO_WHITE
: EndGameType.CHECKMATE_TO_BLACK
: color == Color.WHITE
? EndGameType.STALEMATE_TO_WHITE
: EndGameType.STALEMATE_TO_BLACK;
} else {
isDraw();
if (isDrawWithRepetitions()) gameResult = EndGameType.DRAW_WITH_REPETITIONS;
else if (isDrawWithNotEnoughMaterialForCheckmate())
gameResult = EndGameType.DRAW_WITH_NOT_ENOUGH_MATERIAL;
else if (isDrawWithPeaceMoves()) gameResult = EndGameType.DRAW_WITH_PEACE_MOVE_COUNT;
}
return gameResult;
}

/** @return true, если это не ничья */
public boolean isDraw() {
boolean isDraw = false;
if (isDrawWithPeaceMoves()) {
gameResult = EndGameType.DRAW_WITH_PEACE_MOVE_COUNT;
isDraw = true;
} else if (isDrawWithRepetitions()) {
gameResult = EndGameType.DRAW_WITH_REPETITIONS;
isDraw = true;
} else if (isDrawWithNotEnoughMaterialForCheckmate()) {
gameResult = EndGameType.DRAW_WITH_NOT_ENOUGH_MATERIAL;
isDraw = true;
}
return isDraw;
return isDrawWithRepetitions()
|| isDrawWithNotEnoughMaterialForCheckmate()
|| isDrawWithPeaceMoves();
}

/**
Expand Down Expand Up @@ -195,7 +224,9 @@ public enum EndGameType {
DRAW_WITH_PEACE_MOVE_COUNT,
DRAW_WITH_REPETITIONS,
DRAW_WITH_NOT_ENOUGH_MATERIAL,
CHECKMATE,
STALEMATE
CHECKMATE_TO_BLACK,
CHECKMATE_TO_WHITE,
STALEMATE_TO_BLACK,
STALEMATE_TO_WHITE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public int getMoveCounts(Color color) {
for (Figure f : board.getFigures(color))
for (Move m : f.getAllMoves(gs)) {
if (m.getMoveType() == MoveType.TURN_INTO
|| m.getMoveType() == MoveType.TURN_INTO_ATTACK) {
|| m.getMoveType() == MoveType.TURN_INTO_ATTACK) {
m.setTurnInto(FigureType.QUEEN); // только для проверки виртуального хода
}
if (isCorrectVirtualMoveSilence(m)) count++;
Expand Down
5 changes: 2 additions & 3 deletions game/src/main/java/io/deeplay/qchess/game/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ public Cell findKingCell(Color color) {
/** 0 - нет возможности рокироваться, 1 - левая рокировка возможна, 2 - правая, 3 - обе */
public int isCastlingPossible(Color color) throws ChessError {
Figure king = findKing(color);
if (king == null)
throw new ChessError(KING_NOT_FOUND);
if (king == null) throw new ChessError(KING_NOT_FOUND);
if (king.wasMoved()) return 0;
return (isNotLeftRookStandardMoved(color) ? 1 : 0)
+ (isNotRightRookStandardMoved(color) ? 2 : 0);
Expand Down Expand Up @@ -442,7 +441,7 @@ public Figure removeFigureUglyWithoutRecalcHash(Cell cell) {
public boolean isEmptyCell(Cell cell) {
int column = cell.column;
int row = cell.row;
if(column >= 0 && row >= 0 && column < boardSize && row < boardSize)
if (column >= 0 && row >= 0 && column < boardSize && row < boardSize)
return cells[row][column] == null;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ public void test() throws ChessError {
"QUIET_MOVE",
"END"
};
while (gs.endGameDetector.updateEndGameStatus() == EndGameType.NOTHING) {
while (gs.endGameDetector.updateEndGameStatus(game.getCurrentPlayerToMove().getColor())
== EndGameType.NOTHING) {
if (!strs[i].equals("END")) {
Move move = Selfplay.createMove(strs[i++], strs[i++], strs[i++]);
boolean moveT = game.move(move);
Expand Down
10 changes: 5 additions & 5 deletions game/src/test/resources/logback-game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@
</appender>

<!-- Для вывода результатов игр с сервера -->
<appender class="ch.qos.logback.classic.sift.SiftingAppender" name="SIFTER">
<appender name="SIFTER" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<defaultValue>ALL</defaultValue>
<key>path</key>
<defaultValue>ALL</defaultValue>
</discriminator>

<sift>
<appender class="ch.qos.logback.core.FileAppender" name="FILE-${path}">
<appender name="FILE-${path}" class="ch.qos.logback.core.FileAppender">
<file>target/logs/rooms/${path}.log</file>

<encoder>
<pattern>%msg%n</pattern>
</encoder>

<file>target/logs/rooms/${path}.log</file>
</appender>
</sift>
</appender>
Expand Down
Loading

0 comments on commit e23401e

Please sign in to comment.