1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use board::Tile;

#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Team {
    color: Tile,
    captured: u32,
}

impl Team {

	/// The `new` constructor function returns the Team.

	pub fn new(color: Tile) -> Team {
	    Team {
	    	color: color,
	    	captured: 0,
	    }
	}

	/// Create all the teams of the game.

    pub fn new_teams() -> (Team, Team) {
    	(Team::new(Tile::BLACK), Team::new(Tile::WHITE))
    }

    pub fn captured(&self) -> u32 {
        self.captured
    }

    pub fn get_tile(&self) -> Tile {
    	self.color
    }

    pub fn get_ennemy_tile(&self) -> Tile {
    	self.color.ennemy()
    }

    pub fn add_captured(&mut self, nb_captured: u32) {
        self.captured += nb_captured;
    }
}

use std::fmt::{Formatter, Display, Error};

impl Display for Team
{
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
    {
        let _ = match self.get_tile() {
            Tile::BLACK => write!(f, "black"),
            Tile::WHITE => write!(f, "white"),
            _ => panic!("forbiden team tile"),
        };
        Ok(())
    }
}

impl Default for Team {

    /// The `new` constructor function returns the interface team.

    fn default () -> Self {
        Team {
            color: Tile::default(),
            captured: 0,
        }
    }
}