progs/knight2.scala
author Christian Urban <urbanc@in.tum.de>
Wed, 31 May 2017 09:26:08 +0100
changeset 122 90dd9c6162b3
parent 50 9891c9fac37e
child 213 f968188d4a9b
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
     1
// Part 2 about finding a single tour for a board
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
     2
//================================================
4
f31c22f4f104 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
     4
// copy any function you need from file knight1.scala
4
f31c22f4f104 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
     6
type Pos = (Int, Int)    // a position on a chessboard 
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
     7
type Path = List[Pos]    // a path...a list of positions
4
f31c22f4f104 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
42
a5106bc13db6 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
     9
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
    10
//(2a) Implement a first-function that finds the first 
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
    11
// element, say x, in the list xs where f is not None. 
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
    12
// In that case return f(x), otherwise none.
42
a5106bc13db6 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
    13
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
    14
def first(xs: List[Pos], f: Pos => Option[Path]): Option[Path] = ...
44
9cfa37c91444 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 43
diff changeset
    15
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
    16
//(2b) Implement a function that uses the first-function for
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
    17
// trying out onward moves, and searches recursively for an 
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
    18
// *open* tour on a dim * dim-board.
44
9cfa37c91444 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 43
diff changeset
    19
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
    20
def first_tour(dim: Int, path: Path): Option[Path] = ...
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
    21