From 3262c4c38d74576cf507069a13740f1345d38dd1 Mon Sep 17 00:00:00 2001 From: garethgeorge Date: Wed, 11 Oct 2023 19:00:13 -0700 Subject: [PATCH] configure github pages deployer --- .github/workflows/deploy.yaml | 49 ++++++++++++++++++++++++++++++ chessbot/src/evaluator/nneteval.rs | 6 ++++ chessbot/src/main.rs | 4 +-- chessbot/src/search/alphabeta.rs | 2 +- chessbot/src/search/mod.rs | 2 +- chessbot/src/ui.rs | 2 +- modeltraining/training.py | 3 +- web/src/lib.rs | 3 +- 8 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..c6e1e5f --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,49 @@ +name: Build and Deploy +on: + push: + branches: + - "master" + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - uses: actions/setup-node@v3 + with: + node-version: "20" + - name: build + run: | + cd web + npm install + npm run build + - name: archive web build + uses: actions/upload-artifact@v3 + with: + name: github-pages + path: ./web/dist + + deploy: + needs: build + + # Grant GITHUB_TOKEN the permissions required to make a Pages deployment + permissions: + pages: write # to deploy to Pages + id-token: write # to verify the deployment originates from an appropriate source + + # Deploy to the github-pages environment + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + # Specify runner + deployment step + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 + with: + artifact_name: github-pages \ No newline at end of file diff --git a/chessbot/src/evaluator/nneteval.rs b/chessbot/src/evaluator/nneteval.rs index ef1ef9c..d7f10dd 100644 --- a/chessbot/src/evaluator/nneteval.rs +++ b/chessbot/src/evaluator/nneteval.rs @@ -101,6 +101,12 @@ impl NnetEval { impl Evaluator for NnetEval { fn evaluate(&self, board: &chess::Board) -> anyhow::Result { + match board.status() { + chess::BoardStatus::Ongoing => {} + chess::BoardStatus::Checkmate => return Ok(-10000.0), + chess::BoardStatus::Stalemate => return Ok(-9000.0), + } + let tensor = NnetEval::board_to_input(board).context("failed to create tensor for board")?; let output = self diff --git a/chessbot/src/main.rs b/chessbot/src/main.rs index 79df651..4be647b 100644 --- a/chessbot/src/main.rs +++ b/chessbot/src/main.rs @@ -1,6 +1,6 @@ -use std::str::FromStr; -use chess::{ChessMove, MoveGen}; + + use chessbot::search::{alphabeta::AlphaBeta, MoveSearch}; mod evaluator; diff --git a/chessbot/src/search/alphabeta.rs b/chessbot/src/search/alphabeta.rs index abe5c3e..a5e351d 100644 --- a/chessbot/src/search/alphabeta.rs +++ b/chessbot/src/search/alphabeta.rs @@ -3,7 +3,7 @@ use chess::ChessMove; use chess::MoveGen; use crate::evaluator::Evaluator; -use crate::evaluator::PointsEval; + use super::MoveSearch; use super::ScoredMove; diff --git a/chessbot/src/search/mod.rs b/chessbot/src/search/mod.rs index a62f31a..3dfa723 100644 --- a/chessbot/src/search/mod.rs +++ b/chessbot/src/search/mod.rs @@ -1,4 +1,4 @@ -use chess::{Board, ChessMove, Color, MoveGen}; +use chess::{Board}; pub mod alphabeta; pub mod simpleminmax; diff --git a/chessbot/src/ui.rs b/chessbot/src/ui.rs index 8c4450e..c9991c4 100644 --- a/chessbot/src/ui.rs +++ b/chessbot/src/ui.rs @@ -1,4 +1,4 @@ -use chess::{Board, ChessMove, Color, File, Game, MoveGen, Rank, Square}; +use chess::{Board, Color, File, Rank, Square}; use colored::Colorize; pub fn display_board(board: &Board, ascii: bool) -> String { diff --git a/modeltraining/training.py b/modeltraining/training.py index 39eb575..34a8469 100644 --- a/modeltraining/training.py +++ b/modeltraining/training.py @@ -52,7 +52,8 @@ def __getitem__(self, idx): assert(len(bitvec) == lib.game.tensor_packed_len) bin = np.frombuffer(bitvec, dtype=np.uint8) bin = np.unpackbits(bin, axis=0).astype(np.single)[0:lib.game.tensor_len] - score = math.copysign(math.log2(abs(score / 10.0) + 1), score) # the more extreme the win the less we weight it, we just want to bias towards winning. + score = score / 100.0 + # score = math.copysign(math.log2(abs(score / 10.0) + 1), score) # the more extreme the win the less we weight it, we just want to bias towards winning. return { 'binary': bin, 'eval': np.array([score]).astype(np.single) diff --git a/web/src/lib.rs b/web/src/lib.rs index 465358b..40392d2 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -1,8 +1,7 @@ use std::str::FromStr; use chessbot::{ - evaluator::{self, Evaluator}, - search::simpleminmax::SimpleMinMax, + evaluator::{self}, search::{alphabeta::AlphaBeta, MoveSearch}, }; use wasm_bindgen::prelude::*;