Skip to content

Commit 516a1e3

Browse files
committed
first
0 parents  commit 516a1e3

File tree

6 files changed

+305
-0
lines changed

6 files changed

+305
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

.vscode/launch.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
// IntelliSense を使用して利用可能な属性を学べます。
3+
// 既存の属性の説明をホバーして表示します。
4+
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug executable 'TetrisAIrs'",
11+
"cargo": {
12+
"args": [
13+
"build",
14+
"--bin=TetrisAIrs",
15+
"--package=TetrisAIrs"
16+
],
17+
"filter": {
18+
"name": "TetrisAIrs",
19+
"kind": "bin"
20+
}
21+
},
22+
"args": [],
23+
"cwd": "${workspaceFolder}"
24+
},
25+
{
26+
"type": "lldb",
27+
"request": "launch",
28+
"name": "Debug unit tests in executable 'TetrisAIrs'",
29+
"cargo": {
30+
"args": [
31+
"test",
32+
"--no-run",
33+
"--bin=TetrisAIrs",
34+
"--package=TetrisAIrs"
35+
],
36+
"filter": {
37+
"name": "TetrisAIrs",
38+
"kind": "bin"
39+
}
40+
},
41+
"args": [],
42+
"cwd": "${workspaceFolder}"
43+
}
44+
]
45+
}

Cargo.lock

+92
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "TetrisAIrs"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
num = "*"

src/environment.rs

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
use num;
2+
use num::traits::FromPrimitive;
3+
pub struct Vector2 {
4+
pub x: i32,
5+
pub y: i32,
6+
}
7+
8+
impl Vector2 {
9+
pub fn new(x: i32, y: i32) -> Vector2 {
10+
Vector2 { x: x, y: y }
11+
}
12+
}
13+
14+
pub enum MinoKind {
15+
S,
16+
Z,
17+
L,
18+
J,
19+
O,
20+
I,
21+
T,
22+
Null,
23+
}
24+
pub enum Rotation {
25+
Zero,
26+
Right,
27+
Turn,
28+
Left,
29+
}
30+
impl FromPrimitive for Rotation {
31+
fn from_i64(n: i64) -> Option<Rotation> {
32+
match n {
33+
0 => Some(Rotation::Zero),
34+
1 => Some(Rotation::Right),
35+
2 => Some(Rotation::Turn),
36+
_ => None,
37+
}
38+
}
39+
fn from_u64(n: u64) -> Option<Rotation> {
40+
match n {
41+
0 => Some(Rotation::Zero),
42+
1 => Some(Rotation::Right),
43+
2 => Some(Rotation::Turn),
44+
_ => None,
45+
}
46+
}
47+
}
48+
49+
pub enum Rotate {
50+
Right,
51+
Left,
52+
}
53+
pub struct Mino {
54+
pub MinoKind: MinoKind,
55+
pub Rotation: Rotation,
56+
pub Position: i64,
57+
}
58+
59+
impl Mino {
60+
pub fn new(MinoKind: MinoKind, Rotation: Rotation, Position: i64) -> Mino {
61+
Mino {
62+
MinoKind: MinoKind,
63+
Rotation: Rotation,
64+
Position: Position,
65+
}
66+
}
67+
68+
pub fn Init(&mut self, position: i64) {
69+
if position == -1 {
70+
self.Position = -1;
71+
} else {
72+
self.Position = position;
73+
}
74+
}
75+
76+
pub fn Move(&mut self, x: i32, y: i32) {
77+
if x != i32::MAX {
78+
for i in 0..4 {
79+
Self::AddPosition(&mut self.Position, x.into(), i, true);
80+
}
81+
}
82+
83+
if y != i32::MAX {
84+
for i in 0..4 {
85+
Self::AddPosition(&mut self.Position, y.into(), i, false);
86+
}
87+
}
88+
}
89+
90+
pub fn MoveForSRS(&mut self, srstest: [[Vector2; 1]; 1], rotate: Rotate, rotation: Rotation) {
91+
if let rotate = Rotate::Right {
92+
let value = rotation as usize;
93+
94+
for i in 0..4 {
95+
Self::AddPosition(&mut self.Position, srstest[value][i].x.into(), i, true);
96+
Self::AddPosition(&mut self.Position, srstest[value][i].y.into(), i, false);
97+
}
98+
} else {
99+
for i in 0..4 {}
100+
}
101+
102+
fn RoteteEnum(rotate: Rotate, rotation: Rotation, invert: bool) -> Rotation {
103+
if invert {
104+
if let mut rotate = Rotate::Left {
105+
rotate = Rotate::Right;
106+
} else {
107+
rotate = Rotate::Left;
108+
}
109+
}
110+
111+
let mut rotation = rotation as usize;
112+
113+
if let rotate = Rotate::Right {
114+
rotation += 1;
115+
116+
if rotation == Rotation::Left as usize + 1 {
117+
rotation = Rotation::Zero as usize;
118+
}
119+
} else {
120+
rotation -= 1;
121+
122+
if rotation == Rotation::Zero as usize - 1 {
123+
rotation = Rotation::Left as usize;
124+
}
125+
}
126+
Rotation::from_usize(rotation as usize).unwrap()
127+
}
128+
}
129+
130+
pub fn AddPosition(array: &mut i64, mut value: i64, mut index: usize, isX: bool) {
131+
if index == usize::MAX {
132+
index = 0;
133+
} else {
134+
index = 4 - index - 1;
135+
}
136+
137+
for i in 0..4 * index {
138+
value *= 10;
139+
}
140+
if isX {
141+
value *= 100;
142+
}
143+
144+
*array += value;
145+
}
146+
}
147+
148+
struct Environment {}
149+
150+
impl Environment {}

src/main.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use crate::environment::Vector2;
2+
mod environment;
3+
4+
fn main() {
5+
let data = Vector2::new(0, 1);
6+
7+
println!("{}:{}", &data.x, &data.y);
8+
}

0 commit comments

Comments
 (0)