Skip to content

Commit 2166d4a

Browse files
committed
upgrading to the newest Rust
1 parent 9e631aa commit 2166d4a

File tree

9 files changed

+49
-48
lines changed

9 files changed

+49
-48
lines changed

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/board/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ impl Board {
560560
fn remove_stone(&mut self, c: Coord) {
561561
// Resetting the chain_id is not strictly necessary, but will
562562
// make debugging easier.
563-
self.board[c.to_index(self.size)].chain_id = -1;
563+
//self.board[c.to_index(self.size)].chain_id = -1;
564+
//removed because compiler error
564565
self.board[c.to_index(self.size)].color = Empty;
565566
}
566567

src/board/movement/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use board::Coord;
2727

2828
mod test;
2929

30-
#[derive(Debug, Eq, PartialEq, Hash, Copy)]
30+
#[derive(Debug, Eq, PartialEq, Hash, Copy, Clone)]
3131
pub enum Move {
3232
Pass(Color),
3333
Play(Color, u8, u8),

src/board/test/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn legal_moves_should_return_nothing_after_a_resign() {
142142

143143
b.play(Resign(Black));
144144

145-
assert_eq!(vec!(), b.legal_moves_without_superko_check());
145+
assert_eq!(0, b.legal_moves_without_superko_check().len());
146146
}
147147

148148
#[test]
@@ -151,7 +151,7 @@ fn legal_moves_without_eyes_should_return_nothing_after_a_resing() {
151151

152152
b.play(Resign(Black));
153153

154-
assert_eq!(vec!(), b.legal_moves_without_eyes());
154+
assert_eq!(0, b.legal_moves_without_eyes().len());
155155
}
156156

157157

src/engine/mc/amaf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ impl McEngine for AmafMcEngine {
6262
fn record_playout(stats: &mut MoveStats, playout: &PlayoutResult, won: bool) {
6363
for m in playout.moves().iter() {
6464
if won {
65-
stats.record_win(&m);
65+
stats.record_win(*m);
6666
} else {
67-
stats.record_loss(&m);
67+
stats.record_loss(*m);
6868
}
6969
}
7070
}

src/engine/mc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn finish(color: Color, game: &Game, stats: MoveStats, sender: Sender<Move>, hal
103103
}
104104
}
105105

106-
fn spin_up<'a, T: McEngine>(color: Color, config: Arc<Config>, moves: &'a Vec<Move>, game: &Game, send_result: Sender<(MoveStats<'a>, usize)>) -> (Vec<thread::JoinGuard<'a, ()>>, Vec<Sender<()>>) {
106+
fn spin_up<'a, T: McEngine>(color: Color, config: Arc<Config>, moves: &'a Vec<Move>, game: &Game, send_result: Sender<(MoveStats, usize)>) -> (Vec<thread::JoinGuard<'a, ()>>, Vec<Sender<()>>) {
107107
let mut guards = Vec::new();
108108
let mut halt_senders = Vec::new();
109109
for _ in 0..config.threads {
@@ -117,7 +117,7 @@ fn spin_up<'a, T: McEngine>(color: Color, config: Arc<Config>, moves: &'a Vec<Mo
117117
(guards, halt_senders)
118118
}
119119

120-
fn spin_up_worker<'a, T: McEngine>(color: Color, recv_halt: Receiver<()>, moves: &'a Vec<Move>, board: Board, config: Arc<Config>, send_result: Sender<(MoveStats<'a>, usize)>) -> thread::JoinGuard<'a, ()> {
120+
fn spin_up_worker<'a, T: McEngine>(color: Color, recv_halt: Receiver<()>, moves: &'a Vec<Move>, board: Board, config: Arc<Config>, send_result: Sender<(MoveStats, usize)>) -> thread::JoinGuard<'a, ()> {
121121
thread::scoped(move || {
122122
let runs = 100;
123123
let mut rng = weak_rng();

src/engine/mc/simple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ impl McEngine for SimpleMcEngine {
6262
fn record_playout(stats: &mut MoveStats, playout: &PlayoutResult, won: bool) {
6363
let m = playout.moves()[0];
6464
if won {
65-
stats.record_win(&m);
65+
stats.record_win(m);
6666
} else {
67-
stats.record_loss(&m);
67+
stats.record_loss(m);
6868
}
6969
}
7070

src/engine/move_stats/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ use std::collections::HashMap;
2828

2929
mod test;
3030

31-
pub struct MoveStats<'a> {
31+
pub struct MoveStats {
3232
color: Color,
33-
stats: HashMap<&'a Move, MoveStat>,
33+
stats: HashMap<Move, MoveStat>,
3434
}
3535

36-
impl<'a> MoveStats<'a> {
36+
impl MoveStats {
3737

3838
pub fn new(moves: &Vec<Move>, color: Color) -> MoveStats {
3939
let mut stats = HashMap::new();
40-
for m in moves.iter() {
40+
for &m in moves.iter() {
4141
stats.insert(m, MoveStat::new());
4242
}
4343
MoveStats {
@@ -46,14 +46,14 @@ impl<'a> MoveStats<'a> {
4646
}
4747
}
4848

49-
pub fn record_win(&mut self, m: &Move) {
49+
pub fn record_win(&mut self, m: Move) {
5050
match self.stats.get_mut(&m) {
5151
Some(stat) => stat.won(),
5252
None => {}
5353
}
5454
}
5555

56-
pub fn record_loss(&mut self, m: &Move) {
56+
pub fn record_loss(&mut self, m: Move) {
5757
match self.stats.get_mut(&m) {
5858
Some(stat) => stat.lost(),
5959
None => {}
@@ -73,7 +73,7 @@ impl<'a> MoveStats<'a> {
7373
let mut move_stats = MoveStat::new();
7474
for (m_new, ms) in self.stats.iter() {
7575
if ms.win_ratio() > move_stats.win_ratio() {
76-
m = **m_new;
76+
m = *m_new;
7777
move_stats = *ms;
7878
}
7979
}
@@ -92,7 +92,7 @@ impl<'a> MoveStats<'a> {
9292
}
9393

9494

95-
#[derive(Copy)]
95+
#[derive(Copy, Clone)]
9696
pub struct MoveStat {
9797
wins: usize,
9898
plays: usize

src/engine/move_stats/test.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ mod move_stats {
4545
fn returns_the_best_move() {
4646
let moves = vec![Play(Black, 1, 1), Play(Black, 2, 2)];
4747
let mut stats = MoveStats::new(&moves, Black);
48-
stats.record_win(&Play(Black, 1, 1));
49-
stats.record_loss(&Play(Black, 1, 1));
50-
stats.record_win(&Play(Black, 2, 2));
51-
stats.record_win(&Play(Black, 2, 2));
48+
stats.record_win(Play(Black, 1, 1));
49+
stats.record_loss(Play(Black, 1, 1));
50+
stats.record_win(Play(Black, 2, 2));
51+
stats.record_win(Play(Black, 2, 2));
5252
let (m, ms) = stats.best();
5353
assert_eq!(Play(Black, 2, 2), m);
5454
assert_eq!(ms.plays, 2);
@@ -59,58 +59,58 @@ mod move_stats {
5959
fn all_wins_returns_true_when_no_losses_were_recorded() {
6060
let moves = vec![Play(Black, 1, 1), Play(Black, 2, 2)];
6161
let mut stats = MoveStats::new(&moves, Black);
62-
stats.record_win(&Play(Black, 1, 1));
63-
stats.record_win(&Play(Black, 2, 2));
62+
stats.record_win(Play(Black, 1, 1));
63+
stats.record_win(Play(Black, 2, 2));
6464
assert!(stats.all_wins());
6565
}
6666

6767
#[test]
6868
fn all_wins_returns_false_when_a_loss_was_recorded() {
6969
let moves = vec![Play(Black, 1, 1), Play(Black, 2, 2)];
7070
let mut stats = MoveStats::new(&moves, Black);
71-
stats.record_loss(&Play(Black, 1, 1));
71+
stats.record_loss(Play(Black, 1, 1));
7272
assert!(!stats.all_wins());
7373
}
7474

7575
#[test]
7676
fn all_losses_returns_true_when_no_wins_were_recorded() {
7777
let moves = vec![Play(Black, 1, 1), Play(Black, 2, 2)];
7878
let mut stats = MoveStats::new(&moves, Black);
79-
stats.record_loss(&Play(Black, 1, 1));
80-
stats.record_loss(&Play(Black, 2, 2));
79+
stats.record_loss(Play(Black, 1, 1));
80+
stats.record_loss(Play(Black, 2, 2));
8181
assert!(stats.all_losses());
8282
}
8383

8484
#[test]
8585
fn all_losses_returns_false_when_a_win_was_recorded() {
8686
let moves = vec![Play(Black, 1, 1), Play(Black, 2, 2)];
8787
let mut stats = MoveStats::new(&moves, Black);
88-
stats.record_win(&Play(Black, 1, 1));
88+
stats.record_win(Play(Black, 1, 1));
8989
assert!(!stats.all_losses());
9090
}
9191

9292
#[test]
9393
fn record_win_does_nothing_for_untracked_moves() {
9494
let moves = vec!();
9595
let mut stats = MoveStats::new(&moves, Black);
96-
stats.record_win(&Play(Black, 1, 1));
96+
stats.record_win(Play(Black, 1, 1));
9797
}
9898

9999
#[test]
100100
fn record_loss_does_nothing_for_untracked_moves() {
101101
let moves = vec!();
102102
let mut stats = MoveStats::new(&moves, Black);
103-
stats.record_loss(&Play(Black, 1, 1));
103+
stats.record_loss(Play(Black, 1, 1));
104104
}
105105

106106
#[test]
107107
fn merge_merges_stats_existing_in_both() {
108108
let m = Play(Black, 1, 1);
109109
let moves = vec!(m);
110110
let mut stats = MoveStats::new(&moves, Black);
111-
stats.record_win(&m);
111+
stats.record_win(m);
112112
let mut other = MoveStats::new(&moves, Black);
113-
other.record_loss(&m);
113+
other.record_loss(m);
114114
stats.merge(&other);
115115
let ms = stats.stats.get(&m).unwrap();
116116
assert_eq!(ms.wins, 1);
@@ -124,7 +124,7 @@ mod move_stats {
124124
let mut stats = MoveStats::new(&moves, Black);
125125
let moves2 = vec!(m);
126126
let mut other = MoveStats::new(&moves2, Black);
127-
other.record_loss(&m);
127+
other.record_loss(m);
128128
stats.merge(&other);
129129
assert!(!stats.stats.get(&m).is_some());
130130
}

0 commit comments

Comments
 (0)