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
use board::{GoBoard, Tile};

fn test_pawn(
	board: &GoBoard,
	(x, y): (usize, usize),
	vec_coord: &Vec<(usize, usize)>
) -> bool {
	board.check_index((x, y)) &&
			board.get((x, y)) == Tile::FREE &&
			vec_coord.iter().find(|&r| *r == (x, y)).is_none()
}

fn get_neighbors(x: usize, y: usize) -> Vec<(usize, usize)> {
	if x > 0 && y > 0 {
		return vec!((x - 1, y),  (x, y - 1), (x - 1, y - 1), (x + 1, y - 1),
			(x + 1, y), (x, y + 1), (x + 1, y + 1), (x - 1, y + 1));
	}
	let mut to_return = vec!((x + 1, y), (x, y + 1), (x + 1, y + 1));
	if x > 0 {
		to_return.extend(vec!((x - 1, y), (x - 1, y + 1)));
	}
	if y > 0 {
		to_return.extend(vec!((x, y - 1), (x + 1, y - 1)));
	}
    to_return
}

pub fn move_to_evaluate(board: &GoBoard) -> Vec<(usize, usize)> {
	let mut to_return = Vec::new();
	for (y, line) in board.tiles.iter().enumerate() {
		for (x, tile) in line.iter().enumerate() {
			if tile.is_pawn() {
				// I don't really understand why x and y need to be reversed.
				let neighbors = get_neighbors(y, x);
				for neighbor in neighbors {
					if !test_pawn(board, neighbor, &to_return) {
						continue ;
					}
					to_return.push(neighbor);
				}
			}
		}
	}
	to_return
}