Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "Sources/ChessKitEngineCore/Engines/lc0"]
path = Sources/ChessKitEngineCore/Engines/lc0
url = https://github.com/chesskit-app/lc0.git
[submodule "Sources/ChessKitEngineCore/Engines/arasan-chess"]
path = Sources/ChessKitEngineCore/Engines/arasan-chess
url = git@github.com:ameter/arasan-chess.git
27 changes: 25 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ let package = Package(
dependencies: ["ChessKitEngineCore"],
resources: [
.copy("Resources/192x15_network"),
.copy("Resources/nn-1337b1adec5b.nnue")
.copy("Resources/nn-1337b1adec5b.nnue"),
.copy("Resources/book.bin")
]
),
.target(
Expand All @@ -31,7 +32,17 @@ let package = Package(
.headerSearchPath("Engines/lc0/src"),
.headerSearchPath("Engines/lc0/subprojects/eigen-3.4.0"),
.define("NNUE_EMBEDDING_OFF"),
.define("NO_PEXT")
.define("NO_PEXT"),
// Arasan
.headerSearchPath("Engines/arasan-chess/src"),
.headerSearchPath("Engines/arasan-chess/src/nnue"),
.define("ARASAN_VERSION=v24.0.0"),
.define("_64BIT"),
.define("USE_INTRINSICS"),
.define("USE_ASM"),
.define("SYZYGY_TBS"),
.define("SMP"),
.define("SMP_STATS"),
],
linkerSettings: [
.linkedLibrary("z")
Expand All @@ -48,6 +59,18 @@ let package = Package(
// MARK: - ChessKitEngineCore excludes

package.targets.first { $0.name == "ChessKitEngineCore" }?.exclude = [
// Arasan
"Engines/arasan-chess/src/arasanx.cpp",
"Engines/arasan-chess/src/unit.cpp",
"Engines/arasan-chess/src/tuner.cpp",
"Engines/arasan-chess/src/tune.cpp",
"Engines/arasan-chess/src/topo.cpp",
"Engines/arasan-chess/src/bitbase.cpp",
"Engines/arasan-chess/src/util",
"Engines/arasan-chess/src/nnue/test",
"Engines/arasan-chess/src/syzygy/src/apps",
"Engines/arasan-chess/src/syzygy/src/tbchess.c",
"Engines/arasan-chess/src/nnueintf.cpp",
// lc0
"Engines/lc0/build",
"Engines/lc0/cross-files",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ The following engines are currently supported:
| :---: | --- | :---: | :---: | :---: |
| <img src="https://stockfishchess.org/images/logo/icon_512x512.png" width="25" /> | [Stockfish](https://stockfishchess.org) | [15.1](https://github.com/official-stockfish/Stockfish/tree/sf_15.1) | [GPL v3](https://github.com/official-stockfish/Stockfish/blob/sf_15.1/Copying.txt) | [🔗](https://github.com/official-stockfish/Stockfish/tree/sf_15.1#the-uci-protocol-and-available-options)
| <img src="https://lczero.org/images/logo.svg" width="25" /> | [lc0](https://lczero.org) | [0.29](https://github.com/LeelaChessZero/lc0/tree/v0.29.0) | [GPL v3](https://github.com/LeelaChessZero/lc0/blob/v0.29.0/COPYING) | [🔗](https://github.com/LeelaChessZero/lc0/wiki/Lc0-options)
| <img src="https://www.arasanchess.org/arasan2.gif" width="25" /> | [Arasan](https://www.arasanchess.org) | [24.0.0](https://github.com/jdart1/arasan-chess/tree/v24.0.0) | [MIT License](https://github.com/jdart1/arasan-chess/blob/v24.0.0/LICENSE) | [🔗](https://github.com/jdart1/arasan-chess/tree/v24.0.0#uci-options)

## Author

Expand Down
13 changes: 13 additions & 0 deletions Sources/ChessKitEngine/EngineType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ public enum EngineType: Int {

case stockfish
case lc0
case arasan

/// Internal mapping from Swift to Obj-C type.
var objc: EngineType_objc {
switch self {
case .stockfish: return .stockfish
case .lc0: return .lc0
case .arasan: return .arasan
}
}

Expand All @@ -24,6 +26,7 @@ public enum EngineType: Int {
switch self {
case .stockfish: return "Stockfish"
case .lc0: return "LeelaChessZero (Lc0)"
case .arasan: return "Arasan"
}
}

Expand All @@ -32,6 +35,7 @@ public enum EngineType: Int {
switch self {
case .stockfish: return "15.1"
case .lc0: return "0.29"
case .arasan: return "24.0.0"
}
}

Expand Down Expand Up @@ -59,6 +63,15 @@ public enum EngineType: Int {
weights != nil ?
.setoption(id: "WeightsFile", value: weights!) : nil
].compactMap { $0 }
case .arasan:
let openingBook = Bundle.module.url(forResource: "book", withExtension: "bin")?
.absoluteString
.replacingOccurrences(of: "file://", with: "")

return [
openingBook != nil ?
.setoption(id: "BookPath", value: openingBook!) : nil
].compactMap { $0 }
}
}

Expand Down
Binary file added Sources/ChessKitEngine/Resources/book.bin
Binary file not shown.
3 changes: 3 additions & 0 deletions Sources/ChessKitEngineCore/EngineMessenger/EngineMessenger.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ - (id)initWithEngineType: (EngineType_objc) type {
case EngineTypeLc0:
_engine = new Lc0Engine();
break;
case EngineTypeArasan:
_engine = new ArasanEngine();
break;
}

_engine->initialize();
Expand Down
1 change: 1 addition & 0 deletions Sources/ChessKitEngineCore/Engines/AvailableEngines.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

#import "../Engines/Extensions/stockfish+engine.h"
#import "../Engines/Extensions/lc0+engine.h"
#import "../Engines/Extensions/arasan+engine.h"

#endif /* AvailableEngines_h */
3 changes: 2 additions & 1 deletion Sources/ChessKitEngineCore/Engines/EngineType_objc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

typedef NS_ENUM(NSInteger, EngineType_objc) {
EngineTypeStockfish,
EngineTypeLc0
EngineTypeLc0,
EngineTypeArasan
};

#endif /* EngineType_objc_h */
73 changes: 73 additions & 0 deletions Sources/ChessKitEngineCore/Engines/Extensions/arasan+engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// arasan+engine.cpp
//
// Created by Chris Ameter on 10/10/23.
//

#import "arasan+engine.h"

#include "../arasan-chess/src/types.h"
#include "../arasan-chess/src/globals.h"
#include "../arasan-chess/src/options.h"
#include "../arasan-chess/src/protocol.h"

#include <iostream>
#include <fstream>

Protocol *protocol;
Board board;

void ArasanEngine::initialize() {
signal(SIGINT,SIG_IGN);

// Show a message on the console
std::cout << "Arasan " Arasan_Version << ' ' << Arasan_Copyright << std::endl;
// Must use unbuffered console
setbuf(stdin,NULL);
setbuf(stdout, NULL);
std::cout.rdbuf()->pubsetbuf(NULL, 0);
std::cin.rdbuf()->pubsetbuf(NULL, 0);

Bitboard::init();
Board::init();
globals::initOptions();
Attacks::init();
Scoring::init();
Search::init();
if (!globals::initGlobals(true)) {
globals::cleanupGlobals();
exit(-1);
}

struct rlimit rl;
const rlim_t STACK_MAX = static_cast<rlim_t>(globals::LINUX_STACK_SIZE);
auto result = getrlimit(RLIMIT_STACK, &rl);
if (result == 0)
{
if (rl.rlim_cur < STACK_MAX)
{
rl.rlim_cur = STACK_MAX;
result = setrlimit(RLIMIT_STACK, &rl);
if (result)
{
std::cerr << "failed to increase stack size" << std::endl;
exit(-1);
}
}
}

bool ics = true, trace = false, cpusSet = false, memorySet = false;

protocol = new Protocol(board, trace, ics, cpusSet, memorySet);
// Begins protocol (UCI) run loop, listening on standard input
// protocol->poll(globals::polling_terminated);
}

void ArasanEngine::deinitialize() {
globals::cleanupGlobals();
delete protocol;
}

void ArasanEngine::send_command(const std::string &cmd) {
protocol->do_command(cmd, board);
}
21 changes: 21 additions & 0 deletions Sources/ChessKitEngineCore/Engines/Extensions/arasan+engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// arasan+engine.h
//
// Created by Chris Ameter on 10/10/23.
//

#ifndef arasan_engine_h
#define arasan_engine_h

#import "engine.h"
#import <string>

/// Arasan implementation of `Engine`.
class ArasanEngine: public Engine {
public:
void initialize();
void deinitialize();
void send_command(const std::string &cmd);
};

#endif /* arasan_engine_h */
1 change: 1 addition & 0 deletions Sources/ChessKitEngineCore/Engines/arasan-chess
Submodule arasan-chess added at c4786a
17 changes: 17 additions & 0 deletions Tests/ChessKitEngineTests/EngineTests/ArasanTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ArasanTests.swift
//
// Created by Chris Ameter on 10/20/23.
//

import XCTest
@testable import ChessKitEngine

final class ArasanTests: BaseEngineTests {

override func setUp() {
engineType = .arasan
super.setUp()
}

}