|      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  |         | 
|     31 // !!!!!!! the futures need to be removed...otherwise funny results |         | 
|     32 //lazy val f1 = Future { |         | 
|     33  |         | 
|     34   val ts8 = CW7c.first_tour_heuristic(8, List((0,0))).get |         | 
|     35   assert(correct_urban(8)(ts8) == true) |         | 
|     36  |         | 
|     37 //} |         | 
|     38  |         | 
|     39 //Await.result(f1, 360 second) |         | 
|     40  |         | 
|     41  |         | 
|     42 //lazy val f2 = Future { |         | 
|     43  |         | 
|     44   val ts40 = CW7c.first_tour_heuristic(40, List((0,0))).get |         | 
|     45   assert(correct_urban(40)(ts40) == true) |         | 
|     46  |         | 
|     47 //} |         | 
|     48  |         | 
|     49 //Await.result(f2, 360 second) |         |