From ee5564d86ed68e106371938ef286844185a0606a Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 16:55:58 +0100 Subject: [PATCH 01/12] chore(repo): setup codecov --- .github/workflows/ci.yml | 10 ++++++++++ codecov.yml | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 codecov.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71ec8d4..9e3263c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,6 +101,16 @@ jobs: - name: Test run: pnpm test:affected --nx-bail --base=$NX_BASE --head=$NX_HEAD + - name: Coverage + run: pnpm nx affected -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.0.1 + if: matrix.os == 'ubuntu-latest' + env: + token: ${{ secrets.CODECOV_TOKEN }} + slug: ${{ github.repository }} + cleanup: name: Cleanup runs-on: ubuntu-latest diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..ce790f4 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,21 @@ +coverage: + precision: 2 + round: down + status: + project: + board: + target: 90% + flags: + - board + patch: + default: + enabled: no + if_not_found: success + changes: + default: + enabled: no + if_not_found: success +flags: + board: + paths: + - libs/board/src From f889769ad4b8b0db0424683bbd956f2c9e335814 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 17:13:30 +0100 Subject: [PATCH 02/12] ci(repo): codecov component config --- .github/workflows/ci.yml | 1 - codecov.yml | 38 +++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e3263c..4129a22 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,7 +77,6 @@ jobs: restore-keys: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- - name: Install dependencies - if: steps.cache.outputs.cache-hit != 'true' run: pnpm install - name: Install Rust diff --git a/codecov.yml b/codecov.yml index ce790f4..f7fc698 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,21 +1,25 @@ +codecov: + notify: + require_ci_to_pass: yes + +comment: + layout: "header, diff, flags, components" + coverage: precision: 2 round: down status: - project: - board: - target: 90% - flags: - - board - patch: - default: - enabled: no - if_not_found: success - changes: - default: - enabled: no - if_not_found: success -flags: - board: - paths: - - libs/board/src + project: yes + patch: yes + changes: no + +component_management: + default_rules: + statuses: + - type: patch + target: auto + + individual_components: + - component_id: board + paths: + - "libs/board/**" From ca44f90fdfc753cf88c4772a7b292ecfdf3da1c7 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 17:19:08 +0100 Subject: [PATCH 03/12] ci(repo): update actions --- .github/workflows/ci.yml | 9 +++------ nx.json | 1 - 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4129a22..e0a76f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,18 +94,15 @@ jobs: - name: Lint run: pnpm lint:affected --nx-bail --base=$NX_BASE --head=$NX_HEAD - - name: Build - run: pnpm build:affected --nx-bail --base=$NX_BASE --head=$NX_HEAD --exclude ui - - name: Test run: pnpm test:affected --nx-bail --base=$NX_BASE --head=$NX_HEAD - name: Coverage - run: pnpm nx affected -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD + run: pnpm nx run-many -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 - if: matrix.os == 'ubuntu-latest' + if: matrix.platform == 'ubuntu-latest' env: token: ${{ secrets.CODECOV_TOKEN }} slug: ${{ github.repository }} @@ -116,6 +113,6 @@ jobs: needs: [ci] steps: - name: Delete Artifacts - uses: geekyeggo/delete-artifact@v2 + uses: geekyeggo/delete-artifact@v4 with: name: "*" diff --git a/nx.json b/nx.json index d457649..414f94a 100644 --- a/nx.json +++ b/nx.json @@ -34,7 +34,6 @@ }, "coverage": { "cache": true, - "dependsOn": ["test"], "executor": "nx:run-commands", "options": { "command": "grcov . --binary-path ./dist/libs/{projectName}/debug/deps/ -s libs/{projectName} -t lcov --branch --ignore-not-existing --ignore '../*' --ignore '/*' -o coverage/libs/{projectName}/tests.lcov" From 5868625499a8f06ab22019e80c103c898ff81807 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 17:26:07 +0100 Subject: [PATCH 04/12] ci(repo): affected coverage --- .github/workflows/ci.yml | 2 +- README.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0a76f4..1b0eafc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,7 +98,7 @@ jobs: run: pnpm test:affected --nx-bail --base=$NX_BASE --head=$NX_HEAD - name: Coverage - run: pnpm nx run-many -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD + run: pnpm nx affected -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 diff --git a/README.md b/README.md index 5a0f4eb..aff51b1 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# Draken +# Draken UCI Chess Engine + +[![codecov](https://codecov.io/gh/clemenscodes/draken/graph/badge.svg?token=XE5ZQAIUWY)](https://codecov.io/gh/clemenscodes/draken) From 5cbc6751382bf0ce6aa1d241eaf30be702c72915 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 17:28:08 +0100 Subject: [PATCH 05/12] ci(repo): install grcov in ci --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b0eafc..f766d54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,6 +88,9 @@ jobs: sudo apt-get update sudo apt-get install -y libwebkit2gtk-4.1-dev build-essential curl wget file libssl-dev libayatana-appindicator3-dev librsvg2-dev + - name: Install grcov + run: cargo install grcov + - name: Format run: pnpm fmt:check From b289f2db4d6fa4c4b6521b9aff00b01ca0d65b62 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 17:49:42 +0100 Subject: [PATCH 06/12] ci(repo): cargo cache --- .github/workflows/ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f766d54..bc52714 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,12 @@ jobs: - name: cargo cache uses: actions/cache@v4 with: - path: ${{ github.workspace }}/dist + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + dist/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} restore-keys: ${{ runner.os }}-cargo- @@ -108,7 +113,7 @@ jobs: if: matrix.platform == 'ubuntu-latest' env: token: ${{ secrets.CODECOV_TOKEN }} - slug: ${{ github.repository }} + slug: clemenscodes/draken cleanup: name: Cleanup From 5a67d7993e57137097c5b27e424d8501774102e2 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 18:10:31 +0100 Subject: [PATCH 07/12] ci(repo): downgrade codecov action --- .github/workflows/ci.yml | 2 +- libs/api/src/square.rs | 39 +++++++++++++-------------- libs/bitboard/src/lib.rs | 6 ++--- libs/board/src/fen/active_color.rs | 6 ++--- libs/board/src/fen/enpassant.rs | 7 ++--- libs/board/src/fen/mod.rs | 14 +++++----- libs/board/src/lib.rs | 12 ++++----- libs/board/src/pieces/bishop/mod.rs | 6 ++--- libs/board/src/pieces/black_pieces.rs | 16 +++++------ libs/board/src/pieces/king/mod.rs | 6 ++--- libs/board/src/pieces/knight/mod.rs | 6 ++--- libs/board/src/pieces/mod.rs | 10 +++---- libs/board/src/pieces/pawn/black.rs | 2 +- libs/board/src/pieces/pawn/white.rs | 5 ++-- libs/board/src/pieces/queen/mod.rs | 6 ++--- libs/board/src/pieces/rook/mod.rs | 6 ++--- libs/board/src/pieces/white_pieces.rs | 16 +++++------ 17 files changed, 79 insertions(+), 86 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc52714..779c177 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,7 +109,7 @@ jobs: run: pnpm nx affected -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v4.0.1 + uses: codecov/codecov-action@v3 if: matrix.platform == 'ubuntu-latest' env: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/libs/api/src/square.rs b/libs/api/src/square.rs index d8daf65..9dbb7f5 100644 --- a/libs/api/src/square.rs +++ b/libs/api/src/square.rs @@ -1,7 +1,4 @@ -use std::{ - convert::Into, - fmt::{Debug, Display}, -}; +use std::fmt::{Debug, Display}; use Square::*; pub const NUM_RANKS: usize = 8; @@ -64,7 +61,7 @@ impl TryFrom<&str> for Square { if value.len() != 2 { return Err(Self::Error::Invalid); } - return match value { + match value { "a1" => Ok(A1), "b1" => Ok(B1), "c1" => Ok(C1), "d1" => Ok(D1), "e1" => Ok(E1), "f1" => Ok(F1), "g1" => Ok(G1), "h1" => Ok(H1), "a2" => Ok(A2), "b2" => Ok(B2), "c2" => Ok(C2), "d2" => Ok(D2), @@ -82,7 +79,7 @@ impl TryFrom<&str> for Square { "a8" => Ok(A8), "b8" => Ok(B8), "c8" => Ok(C8), "d8" => Ok(D8), "e8" => Ok(E8), "f8" => Ok(F8), "g8" => Ok(G8), "h8" => Ok(H8), _ => Err(Self::Error::Invalid), - }; + } } } @@ -130,33 +127,33 @@ impl From for Square { } } -impl Into for Square { - fn into(self) -> usize { - *&self as usize +impl From for usize { + fn from(index: Square) -> Self { + index as usize } } -impl Into for Square { - fn into(self) -> u64 { - *&self as u64 +impl From for u64 { + fn from(index: Square) -> Self { + index as u64 } } -impl Into for Square { - fn into(self) -> u32 { - *&self as u32 +impl From for u32 { + fn from(index: Square) -> Self { + index as u32 } } -impl Into for Square { - fn into(self) -> u16 { - *&self as u16 +impl From for u16 { + fn from(index: Square) -> Self { + index as u16 } } -impl Into for Square { - fn into(self) -> u8 { - *&self as u8 +impl From for u8 { + fn from(index: Square) -> Self { + index as u8 } } diff --git a/libs/bitboard/src/lib.rs b/libs/bitboard/src/lib.rs index 9efc75c..9135025 100644 --- a/libs/bitboard/src/lib.rs +++ b/libs/bitboard/src/lib.rs @@ -4,7 +4,7 @@ use std::fmt::{Debug, Display}; use std::ops::*; use std::sync::LazyLock; -const SINGLE_BITS: LazyLock<[Bitboard; u64::BITS as usize]> = LazyLock::new(|| { +static SINGLE_BITS: LazyLock<[Bitboard; u64::BITS as usize]> = LazyLock::new(|| { let mut single_bits = [Bitboard::default(); u64::BITS as usize]; Square::iterate_square_indices(|rank, file| { let index: usize = Square::from_rank_file_to_index(rank, file); @@ -176,7 +176,7 @@ impl TryFrom<(usize, usize)> for Bitboard { if rank * file >= 64 { return Err(Self::Error::InvalidIndex); } - let index = (8 * rank + file) as usize; + let index = 8 * rank + file; let board = Bitboard::get_single_bit(index); Ok(board) } @@ -213,7 +213,7 @@ pub trait BitboardExt { } #[inline(always)] fn shift(bitboard: Bitboard, steps: i8) -> Bitboard { - let abs_steps = steps.abs() as u32; + let abs_steps = steps.unsigned_abs() as u32; if steps < 0 { return bitboard >> abs_steps as usize; } diff --git a/libs/board/src/fen/active_color.rs b/libs/board/src/fen/active_color.rs index 82719c7..0ccc6ee 100644 --- a/libs/board/src/fen/active_color.rs +++ b/libs/board/src/fen/active_color.rs @@ -1,7 +1,7 @@ use std::fmt::{Debug, Display}; pub const NUM_COLORS: usize = 2; -pub const COLORS: [u8; NUM_COLORS] = ['w' as u8, 'b' as u8]; +pub const COLORS: [u8; NUM_COLORS] = [b'w', b'b']; #[derive(PartialEq, Eq, Clone, Copy)] pub struct ActiveColor { @@ -34,10 +34,10 @@ impl TryFrom<&str> for ActiveColor { fn try_from(value: &str) -> Result { if value.eq("w") { - return Ok(Self { color: 'w' as u8 }); + return Ok(Self { color: b'w' }); } if value.eq("b") { - return Ok(Self { color: 'b' as u8 }); + return Ok(Self { color: b'b' }); } Err(Self::Error::Invalid) } diff --git a/libs/board/src/fen/enpassant.rs b/libs/board/src/fen/enpassant.rs index 76a7a60..d9b3f1a 100644 --- a/libs/board/src/fen/enpassant.rs +++ b/libs/board/src/fen/enpassant.rs @@ -5,6 +5,7 @@ use api::Square::{A3, A6, H3, H6}; use bitboard::Bitboard; #[derive(PartialEq, Eq, Clone, Copy)] +#[derive(Default)] pub struct EnPassant { square: Option, } @@ -79,11 +80,7 @@ impl EnPassantExt for EnPassant { } } -impl Default for EnPassant { - fn default() -> Self { - Self { square: None } - } -} + impl Display for EnPassant { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/libs/board/src/fen/mod.rs b/libs/board/src/fen/mod.rs index 981058b..3667b40 100644 --- a/libs/board/src/fen/mod.rs +++ b/libs/board/src/fen/mod.rs @@ -114,12 +114,12 @@ impl TryFrom<&str> for ForsythEdwardsNotation { if parts.len() != FEN_PARTS { return Err(Self::Error::Invalid); } - let placements = Placements::try_from(parts[0]).map_err(|err| Self::Error::InvalidPlacements(err))?; - let active_color = ActiveColor::try_from(parts[1]).map_err(|err| Self::Error::InvalidActiveColor(err))?; - let castling = Castling::try_from(parts[2]).map_err(|err| Self::Error::InvalidCastling(err))?; - let enpassant = EnPassant::try_from(parts[3]).map_err(|err| Self::Error::InvalidEnPassant(err))?; - let half_move_clock = HalfMoveClock::try_from(parts[4]).map_err(|err| Self::Error::InvalidHalfMoveClock(err))?; - let full_move_clock = FullMoveClock::try_from(parts[5]).map_err(|err| Self::Error::InvalidFullMoveClock(err))?; + let placements = Placements::try_from(parts[0]).map_err(Self::Error::InvalidPlacements)?; + let active_color = ActiveColor::try_from(parts[1]).map_err(Self::Error::InvalidActiveColor)?; + let castling = Castling::try_from(parts[2]).map_err(Self::Error::InvalidCastling)?; + let enpassant = EnPassant::try_from(parts[3]).map_err(Self::Error::InvalidEnPassant)?; + let half_move_clock = HalfMoveClock::try_from(parts[4]).map_err(Self::Error::InvalidHalfMoveClock)?; + let full_move_clock = FullMoveClock::try_from(parts[5]).map_err(Self::Error::InvalidFullMoveClock)?; let fen = Self::new(placements, active_color, castling, enpassant, half_move_clock, full_move_clock); Ok(fen) } @@ -153,7 +153,7 @@ impl Debug for ForsythEdwardsNotation { impl ForsythEdwardsNotationExt for ForsythEdwardsNotation { fn get_piece_placement_data(&self) -> Vec { - self.placements().to_string().split("/").map(String::from).collect() + self.placements().to_string().split('/').map(String::from).collect() } fn is_white(&self) -> bool { diff --git a/libs/board/src/lib.rs b/libs/board/src/lib.rs index 91f1ea6..b54108f 100644 --- a/libs/board/src/lib.rs +++ b/libs/board/src/lib.rs @@ -193,8 +193,8 @@ impl Board { pub fn get_piece_index(&self, source: Square) -> Result { let bitboard = Bitboard::from(source); let pieces = self.pieces().get_all_pieces(); - for index in 0..pieces.len() { - if Bitboard::overlap(bitboard, pieces[index]) { + for (index, piece) in pieces.iter().enumerate() { + if Bitboard::overlap(bitboard, *piece) { return Ok(index); } } @@ -256,9 +256,9 @@ impl From for Board { } } -impl Into for Board { - fn into(self) -> Bitboard { - let pieces = *self.pieces(); +impl From for Bitboard { + fn from(val: Board) -> Self { + let pieces = *val.pieces(); pieces.into() } } @@ -266,7 +266,7 @@ impl Into for Board { impl Display for Board { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Square::iterate_square_indices(|rank, file| { - let bitboard = Bitboard::try_from((rank as usize, file as usize)).unwrap(); + let bitboard = Bitboard::try_from((rank, file)).unwrap(); let symbol = self.pieces().get_piece_symbol(bitboard, UTF_SYMBOLS); write!(f, "[{symbol}]").unwrap(); if file == 7 && rank != 0 { diff --git a/libs/board/src/pieces/bishop/mod.rs b/libs/board/src/pieces/bishop/mod.rs index cdd014b..754b805 100644 --- a/libs/board/src/pieces/bishop/mod.rs +++ b/libs/board/src/pieces/bishop/mod.rs @@ -29,17 +29,17 @@ impl From for Bishop { } impl PieceExt for Bishop { - fn is_illegal_move(&self, source: Square, destination: Square, board: Board) -> bool { + fn is_illegal_move(&self, _source: Square, _destination: Square, _board: Board) -> bool { todo!() } - fn get_attacks(&self, piece: Bitboard, board: Board) -> bitboard::Bitboard { + fn get_attacks(&self, _piece: Bitboard, _board: Board) -> bitboard::Bitboard { todo!() } } impl Verify for Bishop { - fn verify(&self, source: Square, destination: Square, board: Board) -> Result { + fn verify(&self, _source: Square, _destination: Square, _board: Board) -> Result { todo!() } } diff --git a/libs/board/src/pieces/black_pieces.rs b/libs/board/src/pieces/black_pieces.rs index 9435580..e6b53ea 100644 --- a/libs/board/src/pieces/black_pieces.rs +++ b/libs/board/src/pieces/black_pieces.rs @@ -61,15 +61,15 @@ impl BlackPieces { } } -impl Into for BlackPieces { - fn into(self) -> Bitboard { +impl From for Bitboard { + fn from(val: BlackPieces) -> Self { Bitboard::merge_many(vec![ - self.rook.bitboard(), - self.knight.bitboard(), - self.bishop.bitboard(), - self.queen.bitboard(), - self.king.bitboard(), - self.pawn.bitboard(), + val.rook.bitboard(), + val.knight.bitboard(), + val.bishop.bitboard(), + val.queen.bitboard(), + val.king.bitboard(), + val.pawn.bitboard(), ]) } } diff --git a/libs/board/src/pieces/king/mod.rs b/libs/board/src/pieces/king/mod.rs index 4a7462d..c7acacf 100644 --- a/libs/board/src/pieces/king/mod.rs +++ b/libs/board/src/pieces/king/mod.rs @@ -29,17 +29,17 @@ impl From for King { } impl PieceExt for King { - fn is_illegal_move(&self, source: Square, destination: Square, board: Board) -> bool { + fn is_illegal_move(&self, _source: Square, _destination: Square, _board: Board) -> bool { todo!() } - fn get_attacks(&self, piece: Bitboard, board: Board) -> bitboard::Bitboard { + fn get_attacks(&self, _piece: Bitboard, _board: Board) -> bitboard::Bitboard { todo!() } } impl Verify for King { - fn verify(&self, source: Square, destination: Square, board: Board) -> Result { + fn verify(&self, _source: Square, _destination: Square, _board: Board) -> Result { todo!() } } diff --git a/libs/board/src/pieces/knight/mod.rs b/libs/board/src/pieces/knight/mod.rs index 6b15849..4b3ced4 100644 --- a/libs/board/src/pieces/knight/mod.rs +++ b/libs/board/src/pieces/knight/mod.rs @@ -29,17 +29,17 @@ impl From for Knight { } impl PieceExt for Knight { - fn is_illegal_move(&self, source: Square, destination: Square, board: Board) -> bool { + fn is_illegal_move(&self, _source: Square, _destination: Square, _board: Board) -> bool { todo!() } - fn get_attacks(&self, piece: Bitboard, board: Board) -> bitboard::Bitboard { + fn get_attacks(&self, _piece: Bitboard, _board: Board) -> bitboard::Bitboard { todo!() } } impl Verify for Knight { - fn verify(&self, source: Square, destination: Square, board: Board) -> Result { + fn verify(&self, _source: Square, _destination: Square, _board: Board) -> Result { todo!() } } diff --git a/libs/board/src/pieces/mod.rs b/libs/board/src/pieces/mod.rs index ed0fba2..7a0592c 100644 --- a/libs/board/src/pieces/mod.rs +++ b/libs/board/src/pieces/mod.rs @@ -69,7 +69,7 @@ pub const PIECE_BYTES: [u8; NUM_PIECES] = [ WhitePawn::symbol() as u8, ]; -pub const PIECE_INDEX_LOOKUP_MAP: LazyLock> = LazyLock::new(|| { +pub static PIECE_INDEX_LOOKUP_MAP: LazyLock> = LazyLock::new(|| { let mut piece_lookup: HashMap = HashMap::new(); for (i, &piece) in PIECE_SYMBOLS.iter().enumerate() { piece_lookup.insert(piece, i); @@ -161,7 +161,7 @@ impl Pieces { } fn merge_piece(&mut self, mut piece: Piece) { - let board = piece.get_board().clone(); + let board = *piece.get_board(); match piece { Piece::Rook(rook) => match rook { Rook::Black(_) => self.black_pieces_mut().rook_mut().bitboard_mut().self_merge(board), @@ -236,9 +236,9 @@ impl From<[[u8; 8]; 8]> for Pieces { } } -impl Into for Pieces { - fn into(self) -> Bitboard { - Bitboard::merge_many(vec![self.white_pieces().into(), self.black_pieces().into()]) +impl From for Bitboard { + fn from(val: Pieces) -> Self { + Bitboard::merge_many(vec![val.white_pieces().into(), val.black_pieces().into()]) } } diff --git a/libs/board/src/pieces/pawn/black.rs b/libs/board/src/pieces/pawn/black.rs index d0f259b..948096e 100644 --- a/libs/board/src/pieces/pawn/black.rs +++ b/libs/board/src/pieces/pawn/black.rs @@ -53,7 +53,7 @@ impl Debug for BlackPawn { } impl PieceExt for BlackPawn { - fn is_illegal_move(&self, source: Square, destination: Square, board: Board) -> bool { + fn is_illegal_move(&self, _source: Square, _destination: Square, _board: Board) -> bool { todo!() } diff --git a/libs/board/src/pieces/pawn/white.rs b/libs/board/src/pieces/pawn/white.rs index 55b6e6e..7c29f36 100644 --- a/libs/board/src/pieces/pawn/white.rs +++ b/libs/board/src/pieces/pawn/white.rs @@ -1,11 +1,10 @@ use super::{Pawn, PawnExt}; use crate::{ - moves::{encoded_move::EncodedMove, reversible::quiet::QuietMove}, pieces::{Piece, PieceExt, WhiteBishop, WhiteKnight, WhiteQueen, WhiteRook}, Board, Shift, Verify, FOURTH_RANK, }; use api::Square; -use bitboard::{Bitboard, BitboardExt}; +use bitboard::{Bitboard}; use std::fmt::{Debug, Display}; #[derive(Default, Clone, Copy, PartialEq, Eq)] @@ -54,7 +53,7 @@ impl Debug for WhitePawn { } impl PieceExt for WhitePawn { - fn is_illegal_move(&self, source: Square, destination: Square, board: Board) -> bool { + fn is_illegal_move(&self, _source: Square, _destination: Square, _board: Board) -> bool { todo!() } diff --git a/libs/board/src/pieces/queen/mod.rs b/libs/board/src/pieces/queen/mod.rs index 032d19c..d43ef90 100644 --- a/libs/board/src/pieces/queen/mod.rs +++ b/libs/board/src/pieces/queen/mod.rs @@ -29,17 +29,17 @@ impl From for Queen { } impl PieceExt for Queen { - fn is_illegal_move(&self, source: Square, destination: Square, board: Board) -> bool { + fn is_illegal_move(&self, _source: Square, _destination: Square, _board: Board) -> bool { todo!() } - fn get_attacks(&self, piece: Bitboard, board: Board) -> bitboard::Bitboard { + fn get_attacks(&self, _piece: Bitboard, _board: Board) -> bitboard::Bitboard { todo!() } } impl Verify for Queen { - fn verify(&self, source: Square, destination: Square, board: Board) -> Result { + fn verify(&self, _source: Square, _destination: Square, _board: Board) -> Result { todo!() } } diff --git a/libs/board/src/pieces/rook/mod.rs b/libs/board/src/pieces/rook/mod.rs index 80f66f8..9199da2 100644 --- a/libs/board/src/pieces/rook/mod.rs +++ b/libs/board/src/pieces/rook/mod.rs @@ -29,17 +29,17 @@ impl From for Rook { } impl PieceExt for Rook { - fn is_illegal_move(&self, source: Square, destination: Square, board: Board) -> bool { + fn is_illegal_move(&self, _source: Square, _destination: Square, _board: Board) -> bool { todo!() } - fn get_attacks(&self, piece: Bitboard, board: Board) -> bitboard::Bitboard { + fn get_attacks(&self, _piece: Bitboard, _board: Board) -> bitboard::Bitboard { todo!() } } impl Verify for Rook { - fn verify(&self, source: Square, destination: Square, board: Board) -> Result { + fn verify(&self, _source: Square, _destination: Square, _board: Board) -> Result { todo!() } } diff --git a/libs/board/src/pieces/white_pieces.rs b/libs/board/src/pieces/white_pieces.rs index 0d22311..484f5eb 100644 --- a/libs/board/src/pieces/white_pieces.rs +++ b/libs/board/src/pieces/white_pieces.rs @@ -61,15 +61,15 @@ impl WhitePieces { } } -impl Into for WhitePieces { - fn into(self) -> Bitboard { +impl From for Bitboard { + fn from(val: WhitePieces) -> Self { Bitboard::merge_many(vec![ - self.rook.bitboard(), - self.knight.bitboard(), - self.bishop.bitboard(), - self.queen.bitboard(), - self.king.bitboard(), - self.pawn.bitboard(), + val.rook.bitboard(), + val.knight.bitboard(), + val.bishop.bitboard(), + val.queen.bitboard(), + val.king.bitboard(), + val.pawn.bitboard(), ]) } } From 84fe48324b4b795d92a8d07657c9f306f47577af Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 18:13:50 +0100 Subject: [PATCH 08/12] ci(repo): succeed if grcov is already installed --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 779c177..330b92c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,7 +94,7 @@ jobs: sudo apt-get install -y libwebkit2gtk-4.1-dev build-essential curl wget file libssl-dev libayatana-appindicator3-dev librsvg2-dev - name: Install grcov - run: cargo install grcov + run: cargo install grcov || true - name: Format run: pnpm fmt:check From 47ea50d70b01208f987531edc9e1a483dd27d909 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 18:26:55 +0100 Subject: [PATCH 09/12] chore(repo): codecov components --- codecov.yml | 30 +++++++++++++++++++++++++++++ libs/board/src/fen/enpassant.rs | 5 +---- libs/board/src/pieces/pawn/white.rs | 2 +- nx.json | 10 +++++++--- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/codecov.yml b/codecov.yml index f7fc698..f1f41f6 100644 --- a/codecov.yml +++ b/codecov.yml @@ -20,6 +20,36 @@ component_management: target: auto individual_components: + - component_id: gui + paths: + - "apps/gui/**" + - component_id: api + paths: + - "libs/api/**" + - component_id: bitboard + paths: + - "libs/bitboard/**" - component_id: board paths: - "libs/board/**" + - component_id: controller + paths: + - "libs/controller/**" + - component_id: draken + paths: + - "libs/draken/**" + - component_id: engine + paths: + - "libs/engine/**" + - component_id: game + paths: + - "libs/game/**" + - component_id: model + paths: + - "libs/model/**" + - component_id: uci + paths: + - "libs/uci/**" + - component_id: view + paths: + - "libs/view/**" diff --git a/libs/board/src/fen/enpassant.rs b/libs/board/src/fen/enpassant.rs index d9b3f1a..ffbeb30 100644 --- a/libs/board/src/fen/enpassant.rs +++ b/libs/board/src/fen/enpassant.rs @@ -4,8 +4,7 @@ use api::Square; use api::Square::{A3, A6, H3, H6}; use bitboard::Bitboard; -#[derive(PartialEq, Eq, Clone, Copy)] -#[derive(Default)] +#[derive(PartialEq, Eq, Clone, Copy, Default)] pub struct EnPassant { square: Option, } @@ -80,8 +79,6 @@ impl EnPassantExt for EnPassant { } } - - impl Display for EnPassant { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let square = self.square.map_or(String::from("-"), |square| square.to_string()); diff --git a/libs/board/src/pieces/pawn/white.rs b/libs/board/src/pieces/pawn/white.rs index 7c29f36..33840bc 100644 --- a/libs/board/src/pieces/pawn/white.rs +++ b/libs/board/src/pieces/pawn/white.rs @@ -4,7 +4,7 @@ use crate::{ Board, Shift, Verify, FOURTH_RANK, }; use api::Square; -use bitboard::{Bitboard}; +use bitboard::Bitboard; use std::fmt::{Debug, Display}; #[derive(Default, Clone, Copy, PartialEq, Eq)] diff --git a/nx.json b/nx.json index 414f94a..0c3268b 100644 --- a/nx.json +++ b/nx.json @@ -41,10 +41,14 @@ }, "lint": { "cache": true, - "executor": "@monodon/rust:lint", - "outputs": ["{options.target-dir}"], + "executor": "nx:run-commands", + "configurations": { + "ci": { + "command": "cargo clippy --no-deps -p {projectName} -- -D warnings" + } + }, "options": { - "target-dir": "dist/libs/{projectName}" + "command": "cargo clippy --no-deps -p {projectName}" } }, "start": { From f99edc636f9a94e4d69ba8499c1927564272b960 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 18:27:37 +0100 Subject: [PATCH 10/12] ci(repo): upgrade codecov action --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 330b92c..efc040f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,7 +109,7 @@ jobs: run: pnpm nx affected -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 if: matrix.platform == 'ubuntu-latest' env: token: ${{ secrets.CODECOV_TOKEN }} From 4eaf6ebb4d647526dfa6afb620a774f5d64051ba Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 18:39:52 +0100 Subject: [PATCH 11/12] ci(repo): test codecov action --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efc040f..4b94443 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,11 +109,11 @@ jobs: run: pnpm nx affected -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v4.0.0 if: matrix.platform == 'ubuntu-latest' env: token: ${{ secrets.CODECOV_TOKEN }} - slug: clemenscodes/draken + slug: ${{ github.repository }} cleanup: name: Cleanup From 4495f475e1370a888f27895b413d56289aa43304 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Tue, 13 Feb 2024 18:50:12 +0100 Subject: [PATCH 12/12] ci(repo): revert codecov to v3, needs upstream fixes --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b94443..9600b2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,7 +109,7 @@ jobs: run: pnpm nx affected -t coverage --nx-bail --base=$NX_BASE --head=$NX_HEAD - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v4.0.0 + uses: codecov/codecov-action@v3 if: matrix.platform == 'ubuntu-latest' env: token: ${{ secrets.CODECOV_TOKEN }}