templates3-bak/knight2.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 05 Nov 2021 17:20:01 +0000
changeset 397 085fefce672e
parent 202 f7bcb27d1940
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
146
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
// Part 2 about finding a single tour for a board
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
//================================================
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
// copy any function you need from file knight1.scala
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
object CW7b {
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
type Pos = (Int, Int)    // a position on a chessboard 
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
type Path = List[Pos]    // a path...a list of positions
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
//(2a) Implement a first-function that finds the first 
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
//     element, say x, in the list xs where f is not None. 
147
72f7dd1a3754 updated
Christian Urban <urbanc@in.tum.de>
parents: 146
diff changeset
    14
//     In that case Return f(x), otherwise None. If possible,
146
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
//     calculate f(x) only once.
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
//def first(xs: List[Pos], f: Pos => Option[Path]) : Option[Path] = ...
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
//(2b) Implement a function that uses the first-function for
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
//     trying out onward moves, and searches recursively for a
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
//     knight tour on a dim * dim-board.
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
//def first_tour(dim: Int, path: Path) : Option[Path] = ...
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
 
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
}