|      1  |         | 
|      2 //import scala.concurrent._ |         | 
|      3 //import scala.concurrent.duration._ |         | 
|      4 //import ExecutionContext.Implicits.global |         | 
|      5 //import scala.language.postfixOps  |         | 
|      6  |         | 
|      7 type Pos = (Int, Int) |         | 
|      8 type Path = List[Pos] |         | 
|      9  |         | 
|     10 def add_pair_urban(x: Pos)(y: Pos): Pos =  |         | 
|     11   (x._1 + y._1, x._2 + y._2) |         | 
|     12  |         | 
|     13 def is_legal_urban(dim: Int, path: Path)(x: Pos): Boolean =  |         | 
|     14   0 <= x._1 && 0 <= x._2 && x._1 < dim && x._2 < dim && !path.contains(x) |         | 
|     15  |         | 
|     16 def moves_urban(x: Pos): List[Pos] =  |         | 
|     17   List(( 1,  2),( 2,  1),( 2, -1),( 1, -2), |         | 
|     18        (-1, -2),(-2, -1),(-2,  1),(-1,  2)).map(add_pair_urban(x)) |         | 
|     19  |         | 
|     20 def legal_moves_urban(dim: Int, path: Path, x: Pos): List[Pos] =  |         | 
|     21   moves_urban(x).filter(is_legal_urban(dim, path)) |         | 
|     22  |         | 
|     23 def correct_urban(dim: Int)(p: Path): Boolean = p match { |         | 
|     24   case Nil => true |         | 
|     25   case x::Nil => true |         | 
|     26   case x::y::p =>  |         | 
|     27     if (legal_moves_urban(dim, p, y).contains(x)) correct_urban(dim)(y::p) else false |         | 
|     28 } |         | 
|     29  |         | 
|     30 def correct_closed_urban(dim: Int)(p: Path) = |         | 
|     31   correct_urban(6)(p) &&  moves_urban(p.head).contains(p.last) |         | 
|     32  |         | 
|     33 //lazy val f = Future { |         | 
|     34  |         | 
|     35   val tsc = CW7c.first_closed_tour_heuristic(6, List((3, 3))).get |         | 
|     36   assert(correct_closed_urban(6)(tsc) == true) |         | 
|     37  |         | 
|     38 //} |         | 
|     39  |         | 
|     40 //Await.result(f, 300 second) |         |