# Path: src/check_goban_moved.py
# def check_goban_moved(prev_corners, current_corners):
#     """Comprobamos si es posible el movimiento de tablero detectado.
# 
#     :Param prev_corners: corners detectados anteriormente
#     :Type prev_corners: list
#     :Param current_corners: corners detectados actualmente
#     :Type current_corners: list
#     :Return: True si el tablero se ha movido
#     :Rtype: bool """
# 
#     if not prev_corners or not current_corners:
#         return True
#     dist_min_of_movement = get_max_edge(prev_corners)/(2*GOBAN_SIZE)
#     " Comprobamos primero si existe mucho movimiento. "
#     dist = []
#     directions = []
#     for i in xrange(NUM_EDGES):
#         dist.append(abs(distance(prev_corners[i], current_corners[i])))
#         directions.append(direction(prev_corners[i], current_corners[i]))
#     f = lambda x: x>1
#     dist_list = filter(f, dist)
#     if len(dist_list) > 2:
#         # min_mov=1/3 square TODO check impossible movement (Direcction)
#         min_mov = get_max_edge(prev_corners)/((GOBAN_SIZE-1)*3.0)
#         dist_list.sort()
#         if (dist_list[-1] - dist_list[0]) < min_mov:
#             return check_directions(directions)
#         elif (dist_list[-1] - dist_list[-3]) < min_mov:
#             return check_directions(directions)
#         else:
#             return False
#     else:
#         return False


from src.check_goban_moved import check_goban_moved
from cv import LoadImageM
from cv import CV_LOAD_IMAGE_COLOR
from nose.tools import *
import unittest
import os
    import cPickle as pickle
    import pickle
                ('img0014.png', 'img0013.png'), ('img0004.png', 'img0001.png'))


    def images_false(self):
        return (('img0001.png'), ('img0004.png'), ('img0007.png'), ('img0010.png'))


    def select_corners_false(self, n):
        path = 'tests/images/'
        image1 = self.images_false()[n]
        txt1 = image1.replace('.png', '.txt')
        with open(path + txt1) as f:
            corners_img1 = pickle.load(f)
        return corners_img1, corners_img1


    def select_corners_true(self, n):
        path = 'tests/images/'
        image1, image2 = self.images_true()[n]
        txt1 = image1.replace('.png', '.txt')
        txt2 = image2.replace('.png', '.txt')
        with open(path + txt1) as f:
            corners_img1 = pickle.load(f)
        with open(path + txt2) as f:
            corners_img2 = pickle.load(f)
        return corners_img1, corners_img2
        

    def test_check_goban_moved_true1(self):
        corners_img1, corners_img2 = self.select_corners_true(1)

# Path: src/check_goban_moved.py
# def check_goban_moved(prev_corners, current_corners):
#     """Comprobamos si es posible el movimiento de tablero detectado.
# 
#     :Param prev_corners: corners detectados anteriormente
#     :Type prev_corners: list
#     :Param current_corners: corners detectados actualmente
#     :Type current_corners: list
#     :Return: True si el tablero se ha movido
#     :Rtype: bool """
# 
#     if not prev_corners or not current_corners:
#         return True
#     dist_min_of_movement = get_max_edge(prev_corners)/(2*GOBAN_SIZE)
#     " Comprobamos primero si existe mucho movimiento. "
#     dist = []
#     directions = []
#     for i in xrange(NUM_EDGES):
#         dist.append(abs(distance(prev_corners[i], current_corners[i])))
#         directions.append(direction(prev_corners[i], current_corners[i]))
#     f = lambda x: x>1
#     dist_list = filter(f, dist)
#     if len(dist_list) > 2:
#         # min_mov=1/3 square TODO check impossible movement (Direcction)
#         min_mov = get_max_edge(prev_corners)/((GOBAN_SIZE-1)*3.0)
#         dist_list.sort()
#         if (dist_list[-1] - dist_list[0]) < min_mov:
#             return check_directions(directions)
#         elif (dist_list[-1] - dist_list[-3]) < min_mov:
#             return check_directions(directions)
#         else:
#             return False
#     else:
#         return False


# Path: tests/check_goban_moved_tests.py
from src.check_goban_moved import check_goban_moved
from cv import LoadImageM
from cv import CV_LOAD_IMAGE_COLOR
from nose.tools import *
import unittest
import os
    import cPickle as pickle
    import pickle

                ('img0014.png', 'img0013.png'), ('img0004.png', 'img0001.png'))


    def images_false(self):
        return (('img0001.png'), ('img0004.png'), ('img0007.png'), ('img0010.png'))


    def select_corners_false(self, n):
        path = 'tests/images/'
        image1 = self.images_false()[n]
        txt1 = image1.replace('.png', '.txt')
        with open(path + txt1) as f:
            corners_img1 = pickle.load(f)
        return corners_img1, corners_img1


    def select_corners_true(self, n):
        path = 'tests/images/'
        image1, image2 = self.images_true()[n]
        txt1 = image1.replace('.png', '.txt')
        txt2 = image2.replace('.png', '.txt')
        with open(path + txt1) as f:
            corners_img1 = pickle.load(f)
        with open(path + txt2) as f:
            corners_img2 = pickle.load(f)
        return corners_img1, corners_img2
        

    def test_check_goban_moved_true1(self):
        corners_img1, corners_img2 = self.select_corners_true(1)

        assert_true(check_goban_moved(corners_img1, corners_img2))