Skip to content

Commit

Permalink
Merge pull request #12 from clemenscodes/develop
Browse files Browse the repository at this point in the history
codecov
  • Loading branch information
clemenscodes authored Feb 13, 2024
2 parents fc8bc6f + 5334647 commit 507d497
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 98 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-

Expand All @@ -77,7 +82,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
Expand All @@ -89,24 +93,34 @@ 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 || true

- name: Format
run: pnpm fmt:check

- 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

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
if: matrix.platform == 'ubuntu-latest'
env:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ${{ github.repository }}

cleanup:
name: Cleanup
runs-on: ubuntu-latest
needs: [ci]
steps:
- name: Delete Artifacts
uses: geekyeggo/delete-artifact@v2
uses: geekyeggo/delete-artifact@v4
with:
name: "*"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
55 changes: 55 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
codecov:
notify:
require_ci_to_pass: yes

comment:
layout: "header, diff, flags, components"

coverage:
precision: 2
round: down
status:
project: yes
patch: yes
changes: no

component_management:
default_rules:
statuses:
- type: patch
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/**"
39 changes: 18 additions & 21 deletions libs/api/src/square.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
convert::Into,
fmt::{Debug, Display},
};
use std::fmt::{Debug, Display};
use Square::*;

pub const NUM_RANKS: usize = 8;
Expand Down Expand Up @@ -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),
Expand All @@ -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),
};
}
}
}

Expand Down Expand Up @@ -130,33 +127,33 @@ impl From<u8> for Square {
}
}

impl Into<usize> for Square {
fn into(self) -> usize {
*&self as usize
impl From<Square> for usize {
fn from(index: Square) -> Self {
index as usize
}
}

impl Into<u64> for Square {
fn into(self) -> u64 {
*&self as u64
impl From<Square> for u64 {
fn from(index: Square) -> Self {
index as u64
}
}

impl Into<u32> for Square {
fn into(self) -> u32 {
*&self as u32
impl From<Square> for u32 {
fn from(index: Square) -> Self {
index as u32
}
}

impl Into<u16> for Square {
fn into(self) -> u16 {
*&self as u16
impl From<Square> for u16 {
fn from(index: Square) -> Self {
index as u16
}
}

impl Into<u8> for Square {
fn into(self) -> u8 {
*&self as u8
impl From<Square> for u8 {
fn from(index: Square) -> Self {
index as u8
}
}

Expand Down
6 changes: 3 additions & 3 deletions libs/bitboard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions libs/board/src/fen/active_color.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -34,10 +34,10 @@ impl TryFrom<&str> for ActiveColor {

fn try_from(value: &str) -> Result<Self, Self::Error> {
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)
}
Expand Down
8 changes: 1 addition & 7 deletions libs/board/src/fen/enpassant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use api::Square;
use api::Square::{A3, A6, H3, H6};
use bitboard::Bitboard;

#[derive(PartialEq, Eq, Clone, Copy)]
#[derive(PartialEq, Eq, Clone, Copy, Default)]
pub struct EnPassant {
square: Option<Square>,
}
Expand Down Expand Up @@ -79,12 +79,6 @@ 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 {
let square = self.square.map_or(String::from("-"), |square| square.to_string());
Expand Down
14 changes: 7 additions & 7 deletions libs/board/src/fen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -153,7 +153,7 @@ impl Debug for ForsythEdwardsNotation {

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

fn is_white(&self) -> bool {
Expand Down
12 changes: 6 additions & 6 deletions libs/board/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ impl Board {
pub fn get_piece_index(&self, source: Square) -> Result<usize, ()> {
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);
}
}
Expand Down Expand Up @@ -256,17 +256,17 @@ impl From<ForsythEdwardsNotation> for Board {
}
}

impl Into<Bitboard> for Board {
fn into(self) -> Bitboard {
let pieces = *self.pieces();
impl From<Board> for Bitboard {
fn from(val: Board) -> Self {
let pieces = *val.pieces();
pieces.into()
}
}

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 {
Expand Down
6 changes: 3 additions & 3 deletions libs/board/src/pieces/bishop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ impl From<WhiteBishop> 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<u16, ()> {
fn verify(&self, _source: Square, _destination: Square, _board: Board) -> Result<u16, ()> {
todo!()
}
}
Expand Down
16 changes: 8 additions & 8 deletions libs/board/src/pieces/black_pieces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ impl BlackPieces {
}
}

impl Into<Bitboard> for BlackPieces {
fn into(self) -> Bitboard {
impl From<BlackPieces> 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(),
])
}
}
6 changes: 3 additions & 3 deletions libs/board/src/pieces/king/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ impl From<BlackKing> 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<u16, ()> {
fn verify(&self, _source: Square, _destination: Square, _board: Board) -> Result<u16, ()> {
todo!()
}
}
Expand Down
Loading

0 comments on commit 507d497

Please sign in to comment.