430
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
// Part 4 about finding a single tour on "mutilated" chessboards
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
//==============================================================
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
|
432
|
4 |
object M4d {
|
|
5 |
|
|
6 |
// !!! Copy any function you need from file knight1.scala !!!
|
|
7 |
// !!! or knight2.scala or knight3.scala !!!
|
|
8 |
//
|
|
9 |
// If you need any auxiliary function, feel free to
|
|
10 |
// implement it, but do not make any changes to the
|
|
11 |
// templates below.
|
430
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
type Pos = (Int, Int)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
type Path = List[Pos]
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
def print_board(dim: Int, path: Path): Unit = {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
println()
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
for (i <- 0 until dim) {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
19 |
for (j <- 0 until dim) {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
20 |
print(f"${path.reverse.indexOf((i, j))}%4.0f ")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
21 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
println()
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
25 |
|
432
|
26 |
// ADD YOUR CODE BELOW
|
|
27 |
//======================
|
430
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
28 |
|
432
|
29 |
// (10)
|
|
30 |
def one_tour_pred(dim: Int, path: Path, n: Int, pred: Pos => Boolean): Option[Path] = ???
|
430
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
31 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
33 |
}
|