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
//
// This file is part of zero_sum.
//
// zero_sum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// zero_sum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with zero_sum. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright 2016-2017 Chris Foster
//

use impls::tak::Color;
use resolution;

/// The ways a game can end.
#[derive(Debug)]
pub enum Resolution {
    /// One player has completed a road.
    Road(Color),
    /// A player has run out of stones or the board is completely full,
    /// and one player has more flatstones.
    Flat(Color),
    /// A player has run out of stones or the board is completely full,
    /// and neither player has more flatstones.
    Draw,
}

impl resolution::Resolution for Resolution {
    /// Returns the index of the winning player (0 for white, 1 for black) if the value is either a `Road` or a `Flat`; `None` otherwise.
    fn get_winner(&self) -> Option<u8> {
        match *self {
            Resolution::Road(Color::White) |
            Resolution::Flat(Color::White) => Some(0),
            Resolution::Road(Color::Black) |
            Resolution::Flat(Color::Black) => Some(1),
            Resolution::Draw => None,
        }
    }

    /// Returns true if the value is a `Draw`.
    fn is_draw(&self) -> bool {
        match *self {
            Resolution::Draw => true,
            _ => false,
        }
    }
}