INDAPlus21 / INDAPlus21/osveijer-sockets
Pass
- Dominant language
- Makefile
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
**Very well done Oliver!**
Fantastic done! I can only assume that this is a reuse from _DD1337 Programmering_, due to duplication, dead code, among else. For example:
_Your code_:
```rs
match self.selected_square {
Some(pos) => {
if pos == (rank, file) {
self.selected_square = None;
self.highlighted_squares = vec![];
} else if self.highlighted_squares.iter().any(|p| p == &(rank,file)) {
let msg: String = pos_string(pos) + " " + &pos_string((rank,file));
if self.sender.send(msg).is_err() {
println!("crashed");
std::process::exit(1);
}
self.selected_square = None;
self.highlighted_squares = vec![];
} else {
self.selected_square = Some((rank, file));
self.highlighted_squares = vec![];
let c = get_colour(self.game.board[rank][file]);
if c != None {
if c.unwrap() == self.game.active {
self.highlighted_squares = pos_coord_vec(self.game.get_possible_moves(pos_string((rank,file))));
};
};
}
},
None => {
self.selected_square = Some((rank, file));
self.highlighted_squares = Vec::new();
let c = get_colour(self.game.board[rank][file]);
if c != None {
if c.unwrap() == self.game.active {
self.highlighted_squares = pos_coord_vec(self.game.get_possible_moves(pos_string((rank,file))));
};
};
}
}
```
_Refactored code_:
```rs
match self.selected_square {
Some(_pos) if _pos == (rank, file) => {
self.selected_square = None;
self.highlighted_squares = Vec::new();
},
Some(_pos) if self.highlighted_squares.iter().any(|p| p == &(rank,file)) => {
self.selected_square = None;
self.highlighted_squares = Vec::new();
let msg: String = format!("{} {}", pos_string(_pos), &pos_string((rank,file));
if self.sender.send(msg).is_err() {
println!("crashed");
std::process::exit(1);
}
},
_ => {
self.selected_square = Some((rank, file));
self.highlighted_squares = Vec::new();
let c = get_colour(self.game.board[rank][file]);
if c.is_some() && c.unwrap() == self.game.active {
self.highlighted_squares = pos_coord_vec(self.gameget_possible_moves(pos_string((rank,file))));
};
}
}
```
Amazing! Thanks!
Remember:
[](https://www.reddit.com/r/rustjerk/)
Keep it up!
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue contains praise and Rust code examples, but it does not identify a requested change, file, test, or acceptance criteria. Start by determining whether this is intended as a refactoring task; there is no stated definition of done or test to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- networking
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 10/100