Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

Commit

Permalink
2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyRS committed Sep 2, 2018
1 parent 237cab3 commit 57b132a
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 648 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.idea/
junit/
out/
test_libs/
board.svg
*.iml
*.txt
Expand Down
3 changes: 2 additions & 1 deletion board.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
{
i3.src="board.svg?t="+new Date().getTime()+"&r="+Math.random()
};
setInterval(()=>{
setInterval(function()
{
if(lup<(new Date().getTime()-300))
{
i1.style.display="none";
Expand Down
9 changes: 2 additions & 7 deletions src/ExampleEngineVSEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sh.hell.compactchess.game.Game;
import sh.hell.compactchess.game.GameStatus;
import sh.hell.compactchess.game.Move;
import sh.hell.compactchess.game.Variant;

import java.io.FileWriter;
import java.io.IOException;
Expand Down Expand Up @@ -35,7 +34,7 @@ public static void main(String[] args) throws IOException
final NumberFormat formatter = new DecimalFormat("#0.00");
do
{
final Game game = new Game().setTimed(1000 * 60 * 5, 1000).setPlayerNames(whiteName, blackName).setTag("Event", "Engine VS Engine").start();
final Game game = new Game().setTimed(15 * 1000, 0).setPlayerNames(whiteName, blackName).setTag("Event", "Engine VS Engine").start();
FileWriter fw = new FileWriter("board.svg", false);
fw.write(game.toSVG());
fw.close();
Expand Down Expand Up @@ -64,14 +63,10 @@ else if(move == null)
move.commit();
fw.write(game.getWhiteTime() + " " + game.getBlackTime() + " +" + (game.increment / 1000) + "s\n");
fw.write("\n" + mover.name() + "'s evaluation: " + engine.getEvaluation() + "\n");
if(game.variant == Variant.STANDARD || game.variant == Variant.CHESS960)
{
fw.write("CompactChess eval.: " + formatter.format((double) game.getScore(mover) / 100) + "\n");
}
}
System.out.println(game.toString(true));
System.out.println(game.getFEN() + "\n");
System.out.println(game.getWhiteTime() + " " + game.getBlackTime() + " +" + (game.increment / 1000) + "s\n");
System.out.println(game.getWhiteTime() + " " + game.getBlackTime() + "\n");
if(game.status != GameStatus.ONGOING)
{
System.out.println(game.status.name() + " by " + game.endReason.name());
Expand Down
38 changes: 6 additions & 32 deletions src/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@ public void pgn() throws ChessException
visualize(game);
game.uciMove("h2h1q").commit();
visualize(game);
final String pgn = game.toPGN();
final String pgn = game.toPGN(false, false, true);
System.out.println(pgn);
Game game_ = Game.fromPGN(pgn).get(0);
visualize(game_);
assertTrue(pgn.contains("1. O-O-O+ { Annotation! } Ke7 2. Kb1 h1=Q *"));
assertEquals(game, game_);
assertEquals("Annotation!", game_.moves.get(0).annotation);
assertEquals("Annotation!", game_.moves.get(0).getAnnotation());
assertEquals(game, Game.fromPGN(game.toPGN(AlgebraicNotationVariation.FIDE_SAN)).get(0));
assertEquals(game, Game.fromPGN(game.toPGN(AlgebraicNotationVariation.FAN)).get(0));
assertEquals(game, Game.fromPGN(game.toPGN(AlgebraicNotationVariation.MAN)).get(0));
Expand All @@ -391,7 +391,7 @@ public void cgn() throws ChessException, IOException
visualize(game);
game.uciMove("h2h1q").commit();
visualize(game);
byte[] cgn = game.toCGN();
byte[] cgn = game.toCGN(false, false, true);
for(byte b : cgn)
{
System.out.println(String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0') + " " + new String(new byte[]{b}, Charset.forName("UTF-8")).replace("\n", "NL"));
Expand All @@ -400,8 +400,8 @@ public void cgn() throws ChessException, IOException
Game game_ = Game.fromCGN(new ByteArrayInputStream(cgn)).get(0);
visualize(game_);
assertEquals(game, game_);
assertEquals("Annotation!", game_.moves.get(0).annotation);
cgn = game.toCGN(CGNVersion.V1);
assertEquals("Annotation!", game_.moves.get(0).getAnnotation());
cgn = game.toCGN(false, false, true, CGNVersion.V1);
for(byte b : cgn)
{
System.out.println(String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0') + " " + new String(new byte[]{b}, Charset.forName("UTF-8")).replace("\n", "NL"));
Expand All @@ -410,7 +410,7 @@ public void cgn() throws ChessException, IOException
game_ = Game.fromCGN(new ByteArrayInputStream(cgn), false, CGNVersion.V1).get(0);
visualize(game_);
assertEquals(game, game_);
assertEquals("Annotation!", game_.moves.get(0).annotation);
assertEquals("Annotation!", game_.moves.get(0).getAnnotation());
}

// Engine
Expand Down Expand Up @@ -443,32 +443,6 @@ public void engine() throws ChessException, IOException
engine.dispose();
}

@Test(timeout = 10000L)
public void builtInEngine() throws ChessException
{
System.out.println("Built-in Engine\n");
Game game = new Game().loadFEN("3qk3/8/4K3/6Q1/8/8/8/8 w - -").start();
visualize(game);
Move move = game.getBestMove(1);
visualize(move.commit());
assertEquals("g5g8", move.toUCI());
game = new Game().loadFEN("k3q3/8/3N4/8/8/8/8/7K w - -").start();
visualize(game);
move = game.getBestMove(2);
visualize(move.commit());
assertEquals("d6e8", move.toUCI());
game = new Game().loadFEN("k3q3/8/5r2/3N4/8/8/8/7K w - -").start();
visualize(game);
move = game.getBestMove(3);
visualize(move.commit());
assertEquals("d5c7", move.toUCI());
game = new Game().loadFEN("4r2k/p1p1Q3/1b4P1/7p/8/2P1p3/PPP1Kp2/1RB2R2 w - - 1 34").start();
visualize(game);
move = game.getBestMove(3);
visualize(move.commit());
assertEquals("e7h7", move.toUCI());
}

@Test(timeout = 2000L)
public void engineTimeouter() throws ChessException, IOException
{
Expand Down
9 changes: 1 addition & 8 deletions src/sh/hell/compactchess/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package sh.hell.compactchess;

import sh.hell.compactchess.engine.BuiltInEngine;
import sh.hell.compactchess.engine.Engine;
import sh.hell.compactchess.exceptions.ChessException;
import sh.hell.compactchess.game.AlgebraicNotationVariation;
Expand Down Expand Up @@ -33,7 +32,6 @@ public static void main() throws IOException, ChessException
System.out.println();
System.out.println("- [C]onvert Notation");
System.out.println("- [E]ngine Operations");
System.out.println("- Engine Operations with [B]uilt-in Engine");
System.out.println("- E[x]it");
System.out.println();
do
Expand All @@ -57,11 +55,6 @@ public static void main() throws IOException, ChessException
engineOperations();
return;

case 'B':
case 'b':
engineOperations(new BuiltInEngine(3));
return;

case 'X':
case 'x':
return;
Expand Down Expand Up @@ -224,7 +217,7 @@ public static void convertNotationTo(final Game game) throws ChessException, IOE

case 'N':
case 'n':
System.out.println(game.toPGN(true, AlgebraicNotationVariation.FAN));
System.out.println(game.toPGN(AlgebraicNotationVariation.FAN));
System.out.println();
convertNotationTo(game);
return;
Expand Down
86 changes: 0 additions & 86 deletions src/sh/hell/compactchess/engine/BuiltInEngine.java

This file was deleted.

15 changes: 10 additions & 5 deletions src/sh/hell/compactchess/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Engine extends EngineBuilder
public String bestMove = null;
public String ponder = null;
public short score = 0;
Game evaluatingGame = null;
public Game evaluatingGame = null;
private Process process;
private boolean doDebug = false;
private int mateIn = 0;
Expand All @@ -38,7 +38,7 @@ public class Engine extends EngineBuilder
private OutputStreamWriter output;
private Scanner input;

Engine()
public Engine()
{
super();
this.killer = null;
Expand Down Expand Up @@ -299,7 +299,12 @@ public Move getBestMove() throws ChessException
{
return null;
}
return evaluatingGame.uciMove(this.bestMove);
Move move = evaluatingGame.uciMove(this.bestMove);
synchronized(move.annotationTags)
{
move.annotationTags.add("[%eval " + this.getEvaluation().replace(",", ".") + "]");
}
return move;
}
}

Expand Down Expand Up @@ -385,7 +390,7 @@ public Color getMater()
{
return null;
}
return this.mateIn > 0 ? evaluatingGame.toMove : (evaluatingGame.toMove == Color.WHITE ? Color.BLACK : Color.WHITE);
return this.mateIn > 0 ? evaluatingGame.toMove : (evaluatingGame.toMove.opposite());
}
}

Expand All @@ -397,7 +402,7 @@ public Color getMatee()
{
return null;
}
return (this.getMater() == Color.WHITE ? Color.BLACK : Color.WHITE);
return this.getMater().opposite();
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/sh/hell/compactchess/game/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
public enum Color
{
WHITE,
BLACK
BLACK;

public Color opposite()
{
return this == Color.WHITE ? Color.BLACK : Color.WHITE;
}
}
Loading

0 comments on commit 57b132a

Please sign in to comment.