Skip to content

Commit

Permalink
Liquid new update release
Browse files Browse the repository at this point in the history
  • Loading branch information
jalpp authored Apr 16, 2024
1 parent 6a62b41 commit de38448
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 293 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ quit (Quit the engine)
```
git clone LiseChessEngine
cd LiseChessEngine/src/main/java/engine/UCIStarter
cd LiseChessEngine/src
java -jar LISEBOT.jar
mvn clean
mvn compile
mvn package
java -jar 4.0-SNAPSHOT.jar
```
Expand All @@ -77,6 +83,8 @@ Please only challenge white side casual/rated

Play Lise [Here](https://lichess.org/@/LISEBOT)

(Please note the Lichess bot may be down some days, due to maintaince/resource limit)

# Authors
@jalpp

Expand Down
30 changes: 2 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Liquid</artifactId>
<version>1.0-SNAPSHOT</version>
<version>4.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
Expand All @@ -19,16 +19,6 @@
</plugins>
</build>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>https://jcenter.bintray.com/</url>
</repository>
<repository>
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
Expand All @@ -44,29 +34,13 @@
<dependency>
<groupId>io.github.tors42</groupId>
<artifactId>chariot</artifactId>
<version>0.0.78</version>
</dependency>
<dependency>
<groupId>io.github.sornerol</groupId>
<artifactId>chesscom-pubapi-wrapper</artifactId>
<version>1.4.4</version>
<version>0.0.85</version>
</dependency>
<dependency>
<groupId>com.github.bhlangonijr</groupId>
<artifactId>chesslib</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.0</version>
</dependency>
</dependencies>

</project>
121 changes: 81 additions & 40 deletions src/main/java/engine/LichessBotRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import chariot.Client;
import chariot.model.Enums;
import chariot.model.Enums.Speed;
import chariot.model.Event;
import chariot.model.GameStateEvent;
import chariot.model.VariantType;
import chariot.model.Enums.Speed;

import com.github.bhlangonijr.chesslib.*;
import com.github.bhlangonijr.chesslib.move.Move;

Expand All @@ -20,63 +19,61 @@ public class LichessBotRunner {
private static boolean isRapid;
private static boolean isBlitz;
private static boolean isCla;

private static Liquid_Levels level;



public LichessBotRunner(){
public LichessBotRunner() {

}


public static void main(String[] args) {

var client = Client.auth(System.getenv("BOT-TOKEN"));
var client = Client.auth(System.getenv("LICHESS_TOKEN"));
var bot = client.bot();
var events = bot.connect().stream();
var username = client.account().profile().get().name().toLowerCase();
String[] s = {"maia1", "maia5", "maia9", "charibot", "TurtleBot", "SxRandom", "zeekat", "knucklefish"};
String[] s = {"maia9", "lynx_bot"};
int picker = s.length;
int index = new Random().nextInt(picker);
String botname = s[index];

try {
level = LiquidSearchEngine.determineAdaptability(botname);
bot.challengeKeepAlive(botname, challengeBuilder -> challengeBuilder.clockRapid10m0s().rated(false).color(Enums.ColorPref.white));
}catch (Exception e){
bot.challengeKeepAlive(botname, challengeBuilder -> challengeBuilder.clockRapid15m10s().rated(false).color(Enums.ColorPref.white));
System.out.println("Challenged: " + botname);
level = Liquid_Levels.BEAST;
} catch (Exception e) {
System.out.println("Failed Challege " + botname);
}

events.forEach(event -> {
switch (event.type()) {
case challenge -> {
var challenge = (Event.ChallengeEvent) event;
System.out.println(challenge);
boolean isPlaying = Client.basic().users().byId("LISEBOT").get().accountStats().playing() > 1;
boolean std = challenge.challenge().gameType().variant() == VariantType.Variant.standard;
boolean isRated = challenge.challenge().gameType().rated();
isRapid = challenge.challenge().gameType().timeControl().speed().name().equalsIgnoreCase("rapid");
isBlitz = challenge.challenge().gameType().timeControl().speed().name().equalsIgnoreCase("blitz");
isCla = challenge.challenge().gameType().timeControl().speed().name().equalsIgnoreCase("classical");
if(!Objects.equals(challenge.challenge().players().challengerOpt().get().user().name(), "LISEBOT")){
level = LiquidSearchEngine.determineAdaptability(challenge.challenge().players().challengerOpt().get().user().name());
if (!isRated) {
if (!Objects.equals(challenge.challenge().players().challengerOpt().get().user().name(), "LISEBOT")) {
level = LiquidSearchEngine.determineAdaptability(challenge.challenge().players().challengerOpt().get().user().name());
}
} else {
level = Liquid_Levels.BEAST;
}

boolean isCoores = challenge.challenge().gameType().timeControl().speed() == Speed.correspondence;
boolean isblackside = challenge.challenge().colorInfo().request().name().equalsIgnoreCase("white");
boolean isRandom = challenge.challenge().colorInfo().request().name().equalsIgnoreCase("random");
System.out.println(challenge);
if (std && !isCoores && !isblackside && !isPlaying && !isRandom) {
if (std && !isCoores && !isPlaying && !isRated) {
bot.acceptChallenge(event.id());
} else if (isCoores) {
bot.declineChallenge(event.id(), Enums.DeclineReason.Provider::timeControl);

} else if (isblackside || isRandom) {
bot.declineChallenge(event.id(), Enums.DeclineReason.Provider::generic);
} else if (isPlaying){
} else if (isPlaying) {
bot.declineChallenge(event.id(), Enums.DeclineReason.Provider::later);
}
else {
} else if (isRated) {
bot.declineChallenge(event.id(), Enums.DeclineReason.casual);
} else {
bot.declineChallenge(event.id(), Enums.DeclineReason.Provider::variant);
}
}
Expand All @@ -86,7 +83,6 @@ public static void main(String[] args) {
bot.chatSpectators(event.id(), "Thanks for watching!");
}
case gameStart -> {

bot.chatSpectators(event.id(), "Running Lise Mode " + level.toString());
var gameEvents = bot.connectToGame(event.id()).stream();
var board = new Board();
Expand All @@ -98,23 +94,62 @@ public static void main(String[] args) {
case opponentGone -> bot.abort(event.id());
case gameFull -> {
try {

isWhite[0] = ((GameStateEvent.Full) gameEvent).white().name().toLowerCase().equals(username);

System.out.println(isWhite[0]);
System.out.println(gameEvent);
isWhite[0] = ((GameStateEvent.Full) gameEvent).white().name().toLowerCase().equalsIgnoreCase(username);
if (isWhite[0]) {
try {

var move = engine.findBestMoveBasedOnLevels(level, board);
bot.move(event.id(), move.toString());
bot.move(event.id(), move);
board.doMove(move);

System.out.println(move);

} catch (Exception e) {
bot.resign(event.id());
}
}

boolean isbotuser = Client.basic().users().byId(((GameStateEvent.Full) gameEvent).white().name()).get().title().orElse("").equalsIgnoreCase("bot");
System.out.println(isbotuser);
if (isbotuser && !isWhite[0]) {
var names = ((GameStateEvent.Full) gameEvent).state().moves().split(" ");
var whiteTurn = names.length % 2 == 0;

if (!whiteTurn) {
try {
var name = names[names.length - 1];
var from = Square.fromValue(name.substring(0, 2).toUpperCase());
var to = Square.fromValue(name.substring(2, 4).toUpperCase());
if (names.length == 5) {
var type = PieceType.fromSanSymbol(name.substring(4).toUpperCase());
var piece = Piece.make(Side.WHITE, type);
var move = new Move(from, to, piece);
board.doMove(move);
} else {
var move = new Move(from, to);
board.doMove(move);
}
} catch (Exception e) {
bot.resign(event.id());
}
}

var move = engine.findBestMoveBasedOnLevels(level, board);
if (LiquidSearchEngine.isValidMove(move)) {
System.out.println(move + "Valid move " + board.getSideToMove() + " " + board.getFen());
bot.move(event.id(), move);
board.doMove(move);
System.out.println(board);
} else {
System.out.println(move + "Invalid move " + board.getSideToMove() + " " + board.getFen());
String sideMove = StockFish.getBestMove(13, board.getFen());
bot.move(event.id(), sideMove);
board.doMove(sideMove);
System.out.println(board);
}
}


} catch (Exception e) {
bot.resign(event.id());
System.out.println(e.getMessage());
Expand All @@ -127,15 +162,14 @@ public static void main(String[] args) {
var names = ((GameStateEvent.State) gameEvent).moves().split(" ");
var whiteTurn = names.length % 2 == 0;

System.out.println(whiteTurn);
if (isWhite[0] == whiteTurn) {
try {
var name = names[names.length - 1];
var from = Square.fromValue(name.substring(0, 2).toUpperCase());
var to = Square.fromValue(name.substring(2, 4).toUpperCase());
if (names.length == 5) {
var type = PieceType.fromSanSymbol(name.substring(4).toUpperCase());
var piece = Piece.make(whiteTurn ? Side.WHITE : Side.BLACK, type);
var piece = Piece.make(Side.WHITE, type);
var move = new Move(from, to, piece);
board.doMove(move);
} else {
Expand All @@ -146,31 +180,39 @@ public static void main(String[] args) {
bot.resign(event.id());
}

if(board.getMoveCounter() > 10 && isRapid){
if (board.getMoveCounter() > 10 && isRapid) {
Thread.sleep(new Random().nextInt(0, 10000));
} else if (board.getMoveCounter() > 10 && isBlitz) {
Thread.sleep(new Random().nextInt(0, 5000));
} else if (board.getMoveCounter() > 10 && isCla) {
Thread.sleep(new Random().nextInt(0, 40000));
} else{
} else {
Thread.sleep(0);
}


if(board.isKingAttacked()){
if (board.isKingAttacked()) {
bot.chat(event.id(), "yo watch out!");
bot.chatSpectators(event.id(), "seems like someone's king attacked lol");
}

if(board.isRepetition()){
if (board.isRepetition()) {
bot.chat(event.id(), "lets repeat I want draw");
bot.chatSpectators(event.id(), "he really trying for draw LOL");
}

bot.chatSpectators(event.id(), "Lise Eval: " + engine.evaluateBoard() + " Stockfish Eval: " + StockFish.getEvalForFEN(13, board.getFen()));
var move = engine.findBestMoveBasedOnLevels(level, board);
bot.move(event.id(), move.toString());
board.doMove(move);
if (LiquidSearchEngine.isValidMove(move)) {
System.out.println(move + "Valid move " + board.getSideToMove() + " " + board.getFen());
bot.move(event.id(), move);
board.doMove(move);
} else {
System.out.println(move + "Invalid move " + board.getSideToMove() + " " + board.getFen());
String sideMove = StockFish.getBestMove(13, board.getFen());
bot.move(event.id(), sideMove);
board.doMove(sideMove);

}

}

Expand All @@ -189,5 +231,4 @@ public static void main(String[] args) {
}



}
Loading

0 comments on commit de38448

Please sign in to comment.