Skip to content

Commit 507d497

Browse files
authored
Merge pull request #12 from clemenscodes/develop
codecov
2 parents fc8bc6f + 5334647 commit 507d497

File tree

20 files changed

+162
-98
lines changed

20 files changed

+162
-98
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ jobs:
6565
- name: cargo cache
6666
uses: actions/cache@v4
6767
with:
68-
path: ${{ github.workspace }}/dist
68+
path: |
69+
~/.cargo/bin/
70+
~/.cargo/registry/index/
71+
~/.cargo/registry/cache/
72+
~/.cargo/git/db/
73+
dist/
6974
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
7075
restore-keys: ${{ runner.os }}-cargo-
7176

@@ -77,7 +82,6 @@ jobs:
7782
restore-keys: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
7883

7984
- name: Install dependencies
80-
if: steps.cache.outputs.cache-hit != 'true'
8185
run: pnpm install
8286

8387
- name: Install Rust
@@ -89,24 +93,34 @@ jobs:
8993
sudo apt-get update
9094
sudo apt-get install -y libwebkit2gtk-4.1-dev build-essential curl wget file libssl-dev libayatana-appindicator3-dev librsvg2-dev
9195
96+
- name: Install grcov
97+
run: cargo install grcov || true
98+
9299
- name: Format
93100
run: pnpm fmt:check
94101

95102
- name: Lint
96103
run: pnpm lint:affected --nx-bail --base=$NX_BASE --head=$NX_HEAD
97104

98-
- name: Build
99-
run: pnpm build:affected --nx-bail --base=$NX_BASE --head=$NX_HEAD --exclude ui
100-
101105
- name: Test
102106
run: pnpm test:affected --nx-bail --base=$NX_BASE --head=$NX_HEAD
103107

108+
- name: Coverage
109+
run: pnpm nx affected -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD
110+
111+
- name: Upload coverage reports to Codecov
112+
uses: codecov/codecov-action@v3
113+
if: matrix.platform == 'ubuntu-latest'
114+
env:
115+
token: ${{ secrets.CODECOV_TOKEN }}
116+
slug: ${{ github.repository }}
117+
104118
cleanup:
105119
name: Cleanup
106120
runs-on: ubuntu-latest
107121
needs: [ci]
108122
steps:
109123
- name: Delete Artifacts
110-
uses: geekyeggo/delete-artifact@v2
124+
uses: geekyeggo/delete-artifact@v4
111125
with:
112126
name: "*"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# Draken
1+
# Draken UCI Chess Engine
2+
3+
[![codecov](https://codecov.io/gh/clemenscodes/draken/graph/badge.svg?token=XE5ZQAIUWY)](https://codecov.io/gh/clemenscodes/draken)

codecov.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
codecov:
2+
notify:
3+
require_ci_to_pass: yes
4+
5+
comment:
6+
layout: "header, diff, flags, components"
7+
8+
coverage:
9+
precision: 2
10+
round: down
11+
status:
12+
project: yes
13+
patch: yes
14+
changes: no
15+
16+
component_management:
17+
default_rules:
18+
statuses:
19+
- type: patch
20+
target: auto
21+
22+
individual_components:
23+
- component_id: gui
24+
paths:
25+
- "apps/gui/**"
26+
- component_id: api
27+
paths:
28+
- "libs/api/**"
29+
- component_id: bitboard
30+
paths:
31+
- "libs/bitboard/**"
32+
- component_id: board
33+
paths:
34+
- "libs/board/**"
35+
- component_id: controller
36+
paths:
37+
- "libs/controller/**"
38+
- component_id: draken
39+
paths:
40+
- "libs/draken/**"
41+
- component_id: engine
42+
paths:
43+
- "libs/engine/**"
44+
- component_id: game
45+
paths:
46+
- "libs/game/**"
47+
- component_id: model
48+
paths:
49+
- "libs/model/**"
50+
- component_id: uci
51+
paths:
52+
- "libs/uci/**"
53+
- component_id: view
54+
paths:
55+
- "libs/view/**"

libs/api/src/square.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::{
2-
convert::Into,
3-
fmt::{Debug, Display},
4-
};
1+
use std::fmt::{Debug, Display};
52
use Square::*;
63

74
pub const NUM_RANKS: usize = 8;
@@ -64,7 +61,7 @@ impl TryFrom<&str> for Square {
6461
if value.len() != 2 {
6562
return Err(Self::Error::Invalid);
6663
}
67-
return match value {
64+
match value {
6865
"a1" => Ok(A1), "b1" => Ok(B1), "c1" => Ok(C1), "d1" => Ok(D1),
6966
"e1" => Ok(E1), "f1" => Ok(F1), "g1" => Ok(G1), "h1" => Ok(H1),
7067
"a2" => Ok(A2), "b2" => Ok(B2), "c2" => Ok(C2), "d2" => Ok(D2),
@@ -82,7 +79,7 @@ impl TryFrom<&str> for Square {
8279
"a8" => Ok(A8), "b8" => Ok(B8), "c8" => Ok(C8), "d8" => Ok(D8),
8380
"e8" => Ok(E8), "f8" => Ok(F8), "g8" => Ok(G8), "h8" => Ok(H8),
8481
_ => Err(Self::Error::Invalid),
85-
};
82+
}
8683
}
8784
}
8885

@@ -130,33 +127,33 @@ impl From<u8> for Square {
130127
}
131128
}
132129

133-
impl Into<usize> for Square {
134-
fn into(self) -> usize {
135-
*&self as usize
130+
impl From<Square> for usize {
131+
fn from(index: Square) -> Self {
132+
index as usize
136133
}
137134
}
138135

139-
impl Into<u64> for Square {
140-
fn into(self) -> u64 {
141-
*&self as u64
136+
impl From<Square> for u64 {
137+
fn from(index: Square) -> Self {
138+
index as u64
142139
}
143140
}
144141

145-
impl Into<u32> for Square {
146-
fn into(self) -> u32 {
147-
*&self as u32
142+
impl From<Square> for u32 {
143+
fn from(index: Square) -> Self {
144+
index as u32
148145
}
149146
}
150147

151-
impl Into<u16> for Square {
152-
fn into(self) -> u16 {
153-
*&self as u16
148+
impl From<Square> for u16 {
149+
fn from(index: Square) -> Self {
150+
index as u16
154151
}
155152
}
156153

157-
impl Into<u8> for Square {
158-
fn into(self) -> u8 {
159-
*&self as u8
154+
impl From<Square> for u8 {
155+
fn from(index: Square) -> Self {
156+
index as u8
160157
}
161158
}
162159

libs/bitboard/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt::{Debug, Display};
44
use std::ops::*;
55
use std::sync::LazyLock;
66

7-
const SINGLE_BITS: LazyLock<[Bitboard; u64::BITS as usize]> = LazyLock::new(|| {
7+
static SINGLE_BITS: LazyLock<[Bitboard; u64::BITS as usize]> = LazyLock::new(|| {
88
let mut single_bits = [Bitboard::default(); u64::BITS as usize];
99
Square::iterate_square_indices(|rank, file| {
1010
let index: usize = Square::from_rank_file_to_index(rank, file);
@@ -176,7 +176,7 @@ impl TryFrom<(usize, usize)> for Bitboard {
176176
if rank * file >= 64 {
177177
return Err(Self::Error::InvalidIndex);
178178
}
179-
let index = (8 * rank + file) as usize;
179+
let index = 8 * rank + file;
180180
let board = Bitboard::get_single_bit(index);
181181
Ok(board)
182182
}
@@ -213,7 +213,7 @@ pub trait BitboardExt {
213213
}
214214
#[inline(always)]
215215
fn shift(bitboard: Bitboard, steps: i8) -> Bitboard {
216-
let abs_steps = steps.abs() as u32;
216+
let abs_steps = steps.unsigned_abs() as u32;
217217
if steps < 0 {
218218
return bitboard >> abs_steps as usize;
219219
}

libs/board/src/fen/active_color.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::{Debug, Display};
22

33
pub const NUM_COLORS: usize = 2;
4-
pub const COLORS: [u8; NUM_COLORS] = ['w' as u8, 'b' as u8];
4+
pub const COLORS: [u8; NUM_COLORS] = [b'w', b'b'];
55

66
#[derive(PartialEq, Eq, Clone, Copy)]
77
pub struct ActiveColor {
@@ -34,10 +34,10 @@ impl TryFrom<&str> for ActiveColor {
3434

3535
fn try_from(value: &str) -> Result<Self, Self::Error> {
3636
if value.eq("w") {
37-
return Ok(Self { color: 'w' as u8 });
37+
return Ok(Self { color: b'w' });
3838
}
3939
if value.eq("b") {
40-
return Ok(Self { color: 'b' as u8 });
40+
return Ok(Self { color: b'b' });
4141
}
4242
Err(Self::Error::Invalid)
4343
}

libs/board/src/fen/enpassant.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use api::Square;
44
use api::Square::{A3, A6, H3, H6};
55
use bitboard::Bitboard;
66

7-
#[derive(PartialEq, Eq, Clone, Copy)]
7+
#[derive(PartialEq, Eq, Clone, Copy, Default)]
88
pub struct EnPassant {
99
square: Option<Square>,
1010
}
@@ -79,12 +79,6 @@ impl EnPassantExt for EnPassant {
7979
}
8080
}
8181

82-
impl Default for EnPassant {
83-
fn default() -> Self {
84-
Self { square: None }
85-
}
86-
}
87-
8882
impl Display for EnPassant {
8983
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9084
let square = self.square.map_or(String::from("-"), |square| square.to_string());

libs/board/src/fen/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ impl TryFrom<&str> for ForsythEdwardsNotation {
114114
if parts.len() != FEN_PARTS {
115115
return Err(Self::Error::Invalid);
116116
}
117-
let placements = Placements::try_from(parts[0]).map_err(|err| Self::Error::InvalidPlacements(err))?;
118-
let active_color = ActiveColor::try_from(parts[1]).map_err(|err| Self::Error::InvalidActiveColor(err))?;
119-
let castling = Castling::try_from(parts[2]).map_err(|err| Self::Error::InvalidCastling(err))?;
120-
let enpassant = EnPassant::try_from(parts[3]).map_err(|err| Self::Error::InvalidEnPassant(err))?;
121-
let half_move_clock = HalfMoveClock::try_from(parts[4]).map_err(|err| Self::Error::InvalidHalfMoveClock(err))?;
122-
let full_move_clock = FullMoveClock::try_from(parts[5]).map_err(|err| Self::Error::InvalidFullMoveClock(err))?;
117+
let placements = Placements::try_from(parts[0]).map_err(Self::Error::InvalidPlacements)?;
118+
let active_color = ActiveColor::try_from(parts[1]).map_err(Self::Error::InvalidActiveColor)?;
119+
let castling = Castling::try_from(parts[2]).map_err(Self::Error::InvalidCastling)?;
120+
let enpassant = EnPassant::try_from(parts[3]).map_err(Self::Error::InvalidEnPassant)?;
121+
let half_move_clock = HalfMoveClock::try_from(parts[4]).map_err(Self::Error::InvalidHalfMoveClock)?;
122+
let full_move_clock = FullMoveClock::try_from(parts[5]).map_err(Self::Error::InvalidFullMoveClock)?;
123123
let fen = Self::new(placements, active_color, castling, enpassant, half_move_clock, full_move_clock);
124124
Ok(fen)
125125
}
@@ -153,7 +153,7 @@ impl Debug for ForsythEdwardsNotation {
153153

154154
impl ForsythEdwardsNotationExt for ForsythEdwardsNotation {
155155
fn get_piece_placement_data(&self) -> Vec<String> {
156-
self.placements().to_string().split("/").map(String::from).collect()
156+
self.placements().to_string().split('/').map(String::from).collect()
157157
}
158158

159159
fn is_white(&self) -> bool {

libs/board/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ impl Board {
193193
pub fn get_piece_index(&self, source: Square) -> Result<usize, ()> {
194194
let bitboard = Bitboard::from(source);
195195
let pieces = self.pieces().get_all_pieces();
196-
for index in 0..pieces.len() {
197-
if Bitboard::overlap(bitboard, pieces[index]) {
196+
for (index, piece) in pieces.iter().enumerate() {
197+
if Bitboard::overlap(bitboard, *piece) {
198198
return Ok(index);
199199
}
200200
}
@@ -256,17 +256,17 @@ impl From<ForsythEdwardsNotation> for Board {
256256
}
257257
}
258258

259-
impl Into<Bitboard> for Board {
260-
fn into(self) -> Bitboard {
261-
let pieces = *self.pieces();
259+
impl From<Board> for Bitboard {
260+
fn from(val: Board) -> Self {
261+
let pieces = *val.pieces();
262262
pieces.into()
263263
}
264264
}
265265

266266
impl Display for Board {
267267
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
268268
Square::iterate_square_indices(|rank, file| {
269-
let bitboard = Bitboard::try_from((rank as usize, file as usize)).unwrap();
269+
let bitboard = Bitboard::try_from((rank, file)).unwrap();
270270
let symbol = self.pieces().get_piece_symbol(bitboard, UTF_SYMBOLS);
271271
write!(f, "[{symbol}]").unwrap();
272272
if file == 7 && rank != 0 {

libs/board/src/pieces/bishop/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ impl From<WhiteBishop> for Bishop {
2929
}
3030

3131
impl PieceExt for Bishop {
32-
fn is_illegal_move(&self, source: Square, destination: Square, board: Board) -> bool {
32+
fn is_illegal_move(&self, _source: Square, _destination: Square, _board: Board) -> bool {
3333
todo!()
3434
}
3535

36-
fn get_attacks(&self, piece: Bitboard, board: Board) -> bitboard::Bitboard {
36+
fn get_attacks(&self, _piece: Bitboard, _board: Board) -> bitboard::Bitboard {
3737
todo!()
3838
}
3939
}
4040

4141
impl Verify for Bishop {
42-
fn verify(&self, source: Square, destination: Square, board: Board) -> Result<u16, ()> {
42+
fn verify(&self, _source: Square, _destination: Square, _board: Board) -> Result<u16, ()> {
4343
todo!()
4444
}
4545
}

0 commit comments

Comments
 (0)