main_solution4/knight4.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 02 Nov 2022 21:49:42 +0000
changeset 430 274c865b3878
parent 400 main_solution4/knight2.scala@e48ea8300b2d
child 432 de701b64a4e0
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
430
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
     1
// Part 4 about finding a single tour on "mutilated" chessboards
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
     2
//==============================================================
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
     3
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
     4
object M4d { 
213
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
430
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
     6
// !!! Copy any function you need from file knight1.scala !!!
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
     7
// !!! or knight2.scala or knight3.scala                  !!! 
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
     8
//
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
     9
// If you need any auxiliary function, feel free to 
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
    10
// implement it, but do not make any changes to the
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
    11
// templates below.
213
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
type Pos = (Int, Int)
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
type Path = List[Pos]
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
def print_board(dim: Int, path: Path): Unit = {
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 221
diff changeset
    17
  println()
213
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  for (i <- 0 until dim) {
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
    for (j <- 0 until dim) {
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
      print(f"${path.reverse.indexOf((i, j))}%4.0f ")
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
    }
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 221
diff changeset
    22
    println()
213
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  } 
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
}
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
430
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
    26
// ADD YOUR CODE BELOW
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
    27
//======================
213
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
430
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
    29
// (10)
274c865b3878 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
    30
def one_tour_pred(dim: Int, path: Path, n: Int, pred: Pos => Boolean): Option[Path] = ???
213
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
f968188d4a9b updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
}