2 Commits
Author SHA1 Message Date
lemon-cat f9ce81ff07 some fix and new bug 2026-09-21 22:52:15 +03:00
lemon-cat ffe4b48479 add coordinate and chessboard 2026-09-16 00:09:21 +03:00
10 changed files with 93 additions and 141 deletions

No files matched your search

+1 -1
View File
@@ -6,6 +6,6 @@
Cargo.lock Cargo.lock
# асеты # асеты
assets/**/* #assets/**/*
!assets/shaders/ !assets/shaders/
!assets/shaders/**/* !assets/shaders/**/*
+8
View File
@@ -4,3 +4,11 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
bevy = "0.18"
[profildev]
opt-level = 1
debug = true
[profile.dev.package."*"]
opt-level = 3
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 771 KiB

-10
View File
@@ -1,10 +0,0 @@
mod trajectory;
pub use trajectory::*;
mod movement_mask;
pub use movement_mask::mov_mask;
struct Board<const N: usize> {
layers: [[u64; 2]; N],
}
-33
View File
@@ -1,33 +0,0 @@
pub fn mov_mask(mut x: i8) -> u64{
let mut mask: u64;
if x == 0 {
return 0xffffffffffffffff;
} else {
if x > 0 {
mask = 1;
x -= 1;
} else {
mask = 128;
x += 1;
}
}
while x != 0{
if x > 0 {
mask |= mask << 1;
x -= 1;
} else {
mask |= mask >> 1;
x += 1;
}
}
mask |= mask << 8;
mask |= mask << 16;
mask |= mask << 32;
!mask
}
-29
View File
@@ -1,29 +0,0 @@
pub fn trajectory(mut position: u64, mask: u64, own_position: u64, enemy_position: u64, shift: i8, mut range: Option<u8>) -> u64 {
let combined_mask = mask & !own_position;
let mut l: u64 = 0;
while position != 0 && range != Some(0) {
position = shift_i8(position, shift);
position = position & combined_mask;
l = l | position;
position = position & !enemy_position;
if let Some(ref mut n) = range {
*n -= 1;
}
}
l
}
fn shift_i8(value: u64, amount: i8) -> u64{
if amount >= 0 {
value << amount
} else {
value >> (-amount)
}
}
-3
View File
@@ -1,3 +0,0 @@
pub mod board;
use board::*;
+84 -16
View File
@@ -1,28 +1,96 @@
mod chess_engines; use bevy::{prelude::*, ui::RelativeCursorPosition};
use chess_engines::board::*;
mod render_bitmask;
use render_bitmask::*;
fn main() { fn main() {
println!("Hello, world!");
let full: u64 = 0xfefefefefefefefe; App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: (800, 800).into(),
title: "local-chess".into(),
..default()
}),
..default()
}))
.add_systems(Startup, setup)
.add_systems(Update, relative_cursor_position_system)
.run();
}
let own: u64 = 0xffff002100000000; fn setup(mut commands: Commands, assets: Res<AssetServer>) {
commands.spawn(Camera2d);
commands
.spawn(Node {
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
flex_direction: FlexDirection::Column,
..default()
})
.with_children(|parent| {
parent
.spawn((
Node {
width: px(512),
height: px(512),
margin: UiRect::bottom(px(15)),
..default()
},
ImageNode::new(assets.load("scene/chessboard.png")),
let wr: u64 = 0x000000000004c83b; ))
.insert(RelativeCursorPosition::default());
});
let bish: u64 = 0x0000002100000000; commands
.spawn(Node {
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
flex_direction: FlexDirection::Column,
left: percent(-40.0),
top: percent(-40.0),
..default()
})
.with_children(|parent| {
parent.spawn((
Text::new("who"),
let ans: u64 = trajectory(bish, full, own, wr, -7, None); TextFont {
font: assets.load("fonts/Baskerville Bold Italic.ttf").into(),
//font_size: FontSize::Px(33.0),
font_size: 50.0,
..default()
},
TextColor(Color::srgb(1.0, 0.5, 1.0)),
render_board(BoardColor::Solid(':'), vec![(ans & wr,'t'), (ans, 'm'), (bish, 'a')]); ));
});
}
print!("\n"); fn relative_cursor_position_system(rcp: Single<&RelativeCursorPosition>, text: Single<&mut Text>){
//let ratio;
let is_white = true;
let mut output_text = text.into_inner();
if let Some(pos) = rcp.normalized{
render_board(BoardColor::Solid(':'), vec![(wr, 'k'), (own, 'w')]); let mut x = ((pos.x + 0.5) * 8.0) as usize + 1;
let mut y;
if is_white {
y = ((pos.y - 0.5) * -8.0 ) as usize + 1;
} else {
y = ((pos.y + 0.5) * 8.0) as usize + 1;
}
let m = ((y - 1) * 8) + x-1;
x = (pos.x > -0.5 && pos.x < 0.5) as usize * x;
let cx = [' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
y = (pos.y > -0.5 && pos.y < 0.5) as usize * y;
let cy = [' ', '1', '2', '3', '4', '5', '6', '7', '8'];
print!("\n"); ** output_text = format!("{}|{}|{}", cx[x], cy[y], m);
} else {
render_board(BoardColor::Solid('`'), vec![(!mov_mask(3), 'a'), (!mov_mask(-2), 'c')]); ** output_text = " ".to_string();
}
} }
-49
View File
@@ -1,49 +0,0 @@
pub enum BoardColor {
Solid(char),
Checkerboard(char, char),
}
pub fn render_u64(a: u64) {
let mut p: u64 = 1 << 56;
for _ in 0..8 {
for x in 0..8 {
if (p << x as u64) & a == 0 {
print!("0");
} else {
print!("1");
}
}
p = p >> 8;
print!("\n")
}
}
pub fn render_board(background: BoardColor, layers: Vec<(u64, char)>){
let mut p: u64 = 1 << 56;
for y in 0..8 {
for x in 0..8 {
if let Some((_, ch)) = layers.iter().find(|(a, _)| (p << x as u64) & a > 0) {
print!("{}", ch)
} else {
match background {
BoardColor::Solid(a) => {
print!("{}", a)
},
BoardColor::Checkerboard(a, b) => {
if (x + y) % 2 == 0 {
print!("{}", a)
} else {
print!("{}", b)
}
}
}
}
}
p = p >> 8;
print!("\n")
}
}