updatd
authorChristian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 16 Dec 2016 13:25:08 +0000
changeset 87 9384b8c98014
parent 86 f8a781322499
child 88 990a1531135d
updatd
marking/knight3b_test.scala
marking/mark02b
marking/mk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/marking/knight3b_test.scala	Fri Dec 16 13:25:08 2016 +0000
@@ -0,0 +1,39 @@
+
+import scala.concurrent._
+import scala.concurrent.duration._
+import ExecutionContext.Implicits.global
+import scala.language.postfixOps 
+
+
+def add_pair_urban(x: Pos)(y: Pos): Pos = 
+  (x._1 + y._1, x._2 + y._2)
+
+def is_legal_urban(dim: Int, path: Path)(x: Pos): Boolean = 
+  0 <= x._1 && 0 <= x._2 && x._1 < dim && x._2 < dim && !path.contains(x)
+
+def moves_urban(x: Pos): List[Pos] = 
+  List(( 1,  2),( 2,  1),( 2, -1),( 1, -2),
+       (-1, -2),(-2, -1),(-2,  1),(-1,  2)).map(add_pair_urban(x))
+
+def legal_moves_urban(dim: Int, path: Path, x: Pos): List[Pos] = 
+  moves_urban(x).filter(is_legal_urban(dim, path))
+
+def correct_urban(dim: Int)(p: Path): Boolean = p match {
+  case Nil => true
+  case x::Nil => true
+  case x::y::p => 
+    if (legal_moves_urban(dim, p, y).contains(x)) correct_urban(dim)(y::p) else false
+}
+
+def correct_closed_urban(dim: Int)(path: Path): Boolean = 
+  correct_urban(dim)(path) && moves_urban(path.head).contains(path.last)
+
+
+lazy val f = Future {
+
+  val tsc = first_tour(6, List((3, 3))).get
+  assert(correct_closed_urban(6)(tsc) == true)
+
+}
+
+Await.result(f, 300 second)
--- a/marking/mark02b	Tue Dec 13 13:02:52 2016 +0000
+++ b/marking/mark02b	Fri Dec 16 13:25:08 2016 +0000
@@ -12,7 +12,7 @@
 echo "" >> $out
 
 function scala_vars {
-   (egrep 'var|return|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
+   (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
 }
 
 
@@ -65,6 +65,20 @@
   tsts1=$(( 1 ))     
 fi
 
+if [ $tsts1 -eq 0 ]
+then
+  echo " ordered_moves(8, List((3,4), (3,2)), (1, 3)) == List((0,1), (0,5), (2,1), (2,5))" | tee -a $out
+  echo " ordered_moves(8, List((4,0)), (0,0)) == List((2,1), (1,2))" | tee -a $out
+  echo " ordered_moves(8, List((0,4)), (0,0)) == List((1,2), (2,1))" | tee -a $out
+  
+  if (scala_assert "knight3.scala.bak" "../../../marking/knight3a_test.scala")
+  then
+    echo "  --> success" | tee -a $out
+    marks=$(( marks + 1 ))
+  else
+    echo "  --> test failed" | tee -a $out
+  fi
+fi
 
 
 
--- a/marking/mk	Tue Dec 13 13:02:52 2016 +0000
+++ b/marking/mk	Fri Dec 16 13:25:08 2016 +0000
@@ -5,6 +5,7 @@
 for sd in k*; do
   cd $sd
   echo $sd
+  touch .
   #../mark
   ../mark01b
   cd ..