Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
DIvAndrey authored Sep 18, 2023
1 parent 6ba9448 commit 4f30b22
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 20 deletions.
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ tokio = { version = "1.32.0", features = ["sync"] }
async-recursion = "1.0.4"
genawaiter = "0.99.1"
snap = "1.1.0"
#brotli = "3.3.4"

[profile.release]
opt-level = 3
overflow-checks = false
debug-assertions = false
lto = "thin"
panic = "abort"
incremental = false
codegen-units = 16
rpath = false
Binary file modified docs/checkers_cpu.wasm
Binary file not shown.
12 changes: 6 additions & 6 deletions src/app/game_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub async fn draw_game_frame(params: &mut AllParams) {
.auto_sized()
.anchor(Align2::CENTER_CENTER, egui::Vec2::ZERO)
.show(egui_ctx, |ui| {
ui.label(text.as_str());
ui.label(&text);
if ui.button("New game").clicked() {
params.current_scene = Scene::Menu;
for player in &mut params.game_params.players {
Expand Down Expand Up @@ -262,14 +262,14 @@ pub async fn draw_game_frame(params: &mut AllParams) {
} else {
format!("{:.2}", eval_abs)
};
let measurements = measure_text(text.as_str(), Some(params.ui_params.font), font_size, 0.5);
let measurements = measure_text(&text, Some(params.ui_params.font), font_size, 0.5);
let text_x = if eval >= 0.0 {
x_offset + board_width * 0.005
} else {
x_offset + board_width * 0.995 - measurements.width
};
draw_text_ex(
text.to_string().as_str(),
&text,
text_x,
(y_offset + measurements.offset_y) * 0.5,
TextParams {
Expand All @@ -295,7 +295,7 @@ pub async fn draw_game_frame(params: &mut AllParams) {
let font_size = min_res * 0.02;
if x == 0 {
draw_text_ex(
(8 - y).to_string().as_str(),
&(8 - y).to_string(),
real_x1 + board_letters_offset,
real_y1 + font_size + board_letters_offset,
TextParams {
Expand All @@ -308,7 +308,7 @@ pub async fn draw_game_frame(params: &mut AllParams) {
}
if y == 7 {
draw_text_ex(
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'][x].to_string().as_str(),
&['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'][x].to_string(),
real_x1 + cell_size - font_size - board_letters_offset,
real_y1 + cell_size - board_letters_offset,
TextParams {
Expand Down Expand Up @@ -366,5 +366,5 @@ pub async fn draw_game_frame(params: &mut AllParams) {
}
}

draw_text(format!("FPS: {}", get_fps()).as_str(), 10.0, 20.0, 18.0, BLACK);
draw_text(&format!("FPS: {}", get_fps()), 10.0, 20.0, 18.0, BLACK);
}
16 changes: 12 additions & 4 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,17 @@ impl Game {
}

fn make_cutting_move(&mut self, from: i8, to: i8) {
assert_eq!(get_bit(self.not_empty, from), 1);
assert_eq!(get_bit(self.not_empty, to), 0);
#[cfg(debug_assertions)]
{
assert_eq!(get_bit(self.not_empty, from), 1);
assert_eq!(get_bit(self.not_empty, to), 0);
}
let mut curr_cell = from;
let diff = to - from;
let delta = diff.signum() * if diff % 7 == 0 {
7
} else {
#[cfg(debug_assertions)]
assert_eq!(diff % 9, 0);
9
};
Expand Down Expand Up @@ -311,8 +315,10 @@ impl Game {
let cells_to_capture: u64 = enemy & diagonal;
let magic_i = ((cells_to_capture.wrapping_mul(magic_num)) >> MAGIC_RSHIFT) as usize;
let after_capture = MOVES_WITH_CAPTURES[MAX_POSITION_MAGIC_INDEX * from as usize + magic_i];
assert_ne!(before_blocker, 1);
assert_ne!(after_capture, 1);
#[cfg(debug_assertions)]{
assert_ne!(before_blocker, 1);
assert_ne!(after_capture, 1);
}
let mut can_move_to = before_blocker & after_capture;
while can_move_to != 0 {
let mask = last_bit(can_move_to);
Expand Down Expand Up @@ -450,6 +456,7 @@ impl Game {
let blockers: u64 = self.not_empty & DIAGONALS[coord as usize];
let magic_i = ((blockers.wrapping_mul(MAGIC_NUMBERS[coord as usize])) >> MAGIC_RSHIFT) as usize;
let mut can_move_to = MOVES_WITHOUT_CAPTURES[MAX_POSITION_MAGIC_INDEX * coord as usize + magic_i];
#[cfg(debug_assertions)]
assert_ne!(can_move_to, 1, "{coord} {blockers:b} {magic_i} {can_move_to:b}");
while can_move_to != 0 {
let mask = last_bit(can_move_to);
Expand Down Expand Up @@ -498,6 +505,7 @@ impl Game {
impl PartialEq for Game {
fn eq(&self, other: &Self) -> bool {
let res = (self.not_empty, self.is_white, self.is_queen, self.current_player, self.boring_moves_counter) == (other.not_empty, other.is_white, other.is_queen, other.current_player, self.boring_moves_counter);
#[cfg(debug_assertions)]
if res {
assert_eq!(self.eval_white, other.eval_white);
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/magic_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::constants::{MOVES_WITHOUT_CAPTURES_COMPRESSED, MOVES_WITH_CAPTURES_CO

lazy_static! {
pub static ref MOVES_WITHOUT_CAPTURES: &'static [u64] = {
let mut result = unsafe {
let result = unsafe {
alloc::alloc(alloc::Layout::array::<u8>(DECOMPRESSED_SIZE).unwrap())
};
let slice = unsafe {
Expand All @@ -17,7 +17,7 @@ lazy_static! {
};

pub static ref MOVES_WITH_CAPTURES: &'static [u64] = {
let mut result = unsafe {
let result = unsafe {
alloc::alloc(alloc::Layout::array::<u8>(DECOMPRESSED_SIZE).unwrap())
};
let slice = unsafe {
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ pub mod constants;
pub mod game;
pub mod useful_functions;

use std::fs::File;
use std::io::Write;
use egui_macroquad::macroquad;
use egui_macroquad::macroquad::prelude::*;
use app::all_params::scene::Scene;
Expand Down Expand Up @@ -79,6 +77,12 @@ async fn main() {
// file.write(compressed.as_slice()).unwrap();
// }

// fn main() {
// let mut file1 = File::open(r"C:\Scripts\RustRover\rust_checkers-main\data\moves_without_captures.bin").unwrap();
// let mut file2 = File::create(r"C:\Scripts\RustRover\rust_checkers-main\data\moves_without_captures.bin.brotli").unwrap();
// brotli::BrotliCompress(&mut file1, &mut file2, &BrotliEncoderParams::default()).unwrap();
// }

//
// use std::fs::File;
// use std::io::{Read, Write};
Expand Down
22 changes: 16 additions & 6 deletions src/useful_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn last_bit(x: u64) -> u64 {

#[inline(always)]
pub fn first_bit(x: u64) -> u64 {
#[cfg(debug_assertions)]
assert_ne!(x, 0);
0x8000_0000_0000_0000u64.wrapping_shr(x.leading_zeros())
}
Expand Down Expand Up @@ -48,23 +49,32 @@ pub fn get_bit_i_or(mask: u64, val: i8) -> i8 {

#[inline(always)]
pub fn conv_1d_to_2d(i: i8) -> (usize, usize) {
assert!(i >= 0, "i = {}", i);
assert!(i < 64, "i = {}", i);
#[cfg(debug_assertions)]
{
assert!(i >= 0, "i = {}", i);
assert!(i < 64, "i = {}", i);
}
((7 - (i & 0b111)) as usize, (7 - i / 8) as usize)
}

#[inline(always)]
pub fn conv_1d_to_2d_i8(i: i8) -> (i8, i8) {
assert!(i >= 0, "i = {}", i);
assert!(i < 64, "i = {}", i);
#[cfg(debug_assertions)]
{
assert!(i >= 0, "i = {}", i);
assert!(i < 64, "i = {}", i);
}
((7 - (i & 0b111)), (7 - (i >> 3)))
}

#[inline(always)]
pub fn conv_2d_to_1d(x: usize, y: usize) -> i8 {
let i = 63 - x as i8 - 8 * y as i8;
assert!(i >= 0, "i = {}", i);
assert!(i < 64, "i = {}", i);
#[cfg(debug_assertions)]
{
assert!(i >= 0, "i = {}", i);
assert!(i < 64, "i = {}", i);
}
i
}

Expand Down

0 comments on commit 4f30b22

Please sign in to comment.