Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40d06aaceb | ||
|
|
d36ef92b3e | ||
|
|
5da99ed444 | ||
|
|
90c8c9882b | ||
|
|
9ab067ae7d | ||
|
|
ac9f7fede4 |
No files matched your search
+1
-1
@@ -6,6 +6,6 @@
|
||||
Cargo.lock
|
||||
|
||||
# асеты
|
||||
#assets/**/*
|
||||
assets/**/*
|
||||
!assets/shaders/
|
||||
!assets/shaders/**/*
|
||||
@@ -4,11 +4,3 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.18"
|
||||
|
||||
[profildev]
|
||||
opt-level = 1
|
||||
debug = true
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 771 KiB |
@@ -0,0 +1,10 @@
|
||||
mod trajectory;
|
||||
pub use trajectory::*;
|
||||
|
||||
mod movement_mask;
|
||||
pub use movement_mask::mov_mask;
|
||||
|
||||
struct Board<const N: usize> {
|
||||
layers: [[u64; 2]; N],
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod board;
|
||||
use board::*;
|
||||
|
||||
+16
-84
@@ -1,96 +1,28 @@
|
||||
use bevy::{prelude::*, ui::RelativeCursorPosition};
|
||||
mod chess_engines;
|
||||
use chess_engines::board::*;
|
||||
|
||||
mod render_bitmask;
|
||||
use render_bitmask::*;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
|
||||
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 full: u64 = 0xfefefefefefefefe;
|
||||
|
||||
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 own: u64 = 0xffff002100000000;
|
||||
|
||||
))
|
||||
.insert(RelativeCursorPosition::default());
|
||||
});
|
||||
let wr: u64 = 0x000000000004c83b;
|
||||
|
||||
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 bish: u64 = 0x0000002100000000;
|
||||
|
||||
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)),
|
||||
let ans: u64 = trajectory(bish, full, own, wr, -7, None);
|
||||
|
||||
));
|
||||
});
|
||||
}
|
||||
render_board(BoardColor::Solid(':'), vec![(ans & wr,'t'), (ans, 'm'), (bish, 'a')]);
|
||||
|
||||
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{
|
||||
print!("\n");
|
||||
|
||||
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'];
|
||||
render_board(BoardColor::Solid(':'), vec![(wr, 'k'), (own, 'w')]);
|
||||
|
||||
** output_text = format!("{}|{}|{}", cx[x], cy[y], m);
|
||||
} else {
|
||||
** output_text = " ".to_string();
|
||||
}
|
||||
print!("\n");
|
||||
|
||||
render_board(BoardColor::Solid('`'), vec![(!mov_mask(3), 'a'), (!mov_mask(-2), 'c')]);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user