| 145 |      1 | 
 | 
| 162 |      2 | //import scala.concurrent._
 | 
|  |      3 | //import scala.concurrent.duration._
 | 
|  |      4 | //import ExecutionContext.Implicits.global
 | 
|  |      5 | //import scala.language.postfixOps 
 | 
| 145 |      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 | 
 | 
| 168 |     30 | 
 | 
|  |     31 | // !!!!!!! the futures need to be removed...otherwise funny results
 | 
| 162 |     32 | //lazy val f1 = Future {
 | 
| 145 |     33 | 
 | 
|  |     34 |   val ts8 = CW7c.first_tour_heuristic(8, List((0,0))).get
 | 
|  |     35 |   assert(correct_urban(8)(ts8) == true)
 | 
|  |     36 | 
 | 
| 162 |     37 | //}
 | 
| 145 |     38 | 
 | 
| 162 |     39 | //Await.result(f1, 360 second)
 | 
| 145 |     40 | 
 | 
|  |     41 | 
 | 
| 162 |     42 | //lazy val f2 = Future {
 | 
| 145 |     43 | 
 | 
|  |     44 |   val ts40 = CW7c.first_tour_heuristic(40, List((0,0))).get
 | 
|  |     45 |   assert(correct_urban(40)(ts40) == true)
 | 
|  |     46 | 
 | 
| 162 |     47 | //}
 | 
| 145 |     48 | 
 | 
| 162 |     49 | //Await.result(f2, 360 second)
 |