INDAPlus21 / INDAPlus21/melg-chess-gui
Pass
- Dominant language
- Rust
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
**Very well done Marcus!**
One complaint(!): The window is tiny. Also, black text on a dark-blue background is not great design.
A note: if-let-statements and match-statements can scope your value extractions.
_Example 1: Your code_:
```rust
if self.game.board.contains_key(position) {
let piece = self.game.board.get(position).unwrap();
// Select piece to move
if /*...*/ {
//...
let moves = self.game.get_possible_moves(position.to_string());
if moves.is_none() {
//...
} else {
//...
for _move in moves.unwrap().iter() {/*...*/}
//...
}
} else {/*...*/}
} else {/*...*/}
```
_Example 1: With if-let and match_:
```rust
if let Some(_piece) = self.game.board.get(position) {
// Select piece to move
if /*...*/ {
//...
match self.game.get_possible_moves(position.to_string()) {
Some(_moves) => {
//...
for _move in _moves.iter() {/*...*/}
//...
},
None => //...
}
} else {/*...*/}
} else {/*...*/}
```
_Example 2: Your code_:
```rust
// Select promotion
let selected_piece = match x_tile {
8 => Some(PieceType::Queen(self.game.active_color)),
9 => Some(PieceType::Knight(self.game.active_color)),
10 => Some(PieceType::Rook(self.game.active_color)),
11 => Some(PieceType::Bishop(self.game.active_color)),
_ => None,
};
if selected_piece.is_some() {
self.game.promotion[match self.game.active_color {
Colour::White => 0,
Colour::Black => 1,
}] = selected_piece.unwrap();
}
```
_Example 2: With if-let_:
```rust
// Select promotion
if let Some(_selected_piece) = match x_tile {
8 => Some(PieceType::Queen(self.game.active_color)),
9 => Some(PieceType::Knight(self.game.active_color)),
10 => Some(PieceType::Rook(self.game.active_color)),
11 => Some(PieceType::Bishop(self.game.active_color)),
_ => None,
} {
self.game.promotion[match self.game.active_color {
Colour::White => 0,
Colour::Black => 1,
}] = _selected_piece;
}
```
However, observe how functional expressions complicates code, hence single-use variables can ease readability, which is one of the criterias for good code design. Additionally, one big readability fallgroup is uninformative comments.
_Example 2: With if-let_:
```rust
// Get selected active promotion piece type.
let selected_piece = match x_tile {
8 => Some(PieceType::Queen(self.game.active_color)),
9 => Some(PieceType::Knight(self.game.active_color)),
10 => Some(PieceType::Rook(self.game.active_color)),
11 => Some(PieceType::Bishop(self.game.active_color)),
_ => None,
};
// Save promotion piece type, if any piece type was selected.
if let Some(_selected_piece) = selected_piece {
let active_colour_code = match self.game.active_color {
Colour::White => 0,
Colour::Black => 1,
}
self.game.promotion[active_colour_code] = _selected_piece;
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
No files, tests, or entry points are named. Start by locating the window setup and the Rust code shown in the issue, then review the sizing, color contrast, value extraction, and comments; done means the reported design and readability concerns are addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- design, desktop
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100