progs/knight3.scala
author Christian Urban <urbanc@in.tum.de>
Thu, 24 Nov 2016 11:43:07 +0000
changeset 71 19dff7218b0d
parent 53 9f8751912560
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: 4
diff changeset
     1
// Part 3 about finding a single tour using the Warnsdorf Rule
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 4
diff changeset
     2
//=============================================================
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 4
diff changeset
     3
53
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
     4
// copy any function you need from files knight1.scala and
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
     5
// knight2.scala
4
f31c22f4f104 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
53
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
     7
type Pos = (Int, Int)    // a position on a chessboard 
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
     8
type Path = List[Pos]    // a path...a list of positions
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 4
diff changeset
     9
53
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    10
//(3a) Complete the function that calculates a list of onward
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    11
// moves like in (1b) but orders them according to the Warnsdorf’s 
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    12
// rule. That means moves with the fewest legal onward moves 
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    13
// should come first.
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 4
diff changeset
    14
53
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    15
def ordered_moves(dim: Int, path: Path, x: Pos): List[Pos] = ..
4
f31c22f4f104 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
53
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    17
//(3b) Complete the function that searches for a single *closed* 
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    18
// tour using the ordered moves function.
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 4
diff changeset
    19
53
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    20
def first_closed_tour_heuristic(dim: Int, path: Path): Option[Path] = ...
4
f31c22f4f104 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
53
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    22
//(3c) Same as (3b) but searches for *open* tours.
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 4
diff changeset
    23
53
9f8751912560 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
    24
def first_tour_heuristic(dim: Int, path: Path): Option[Path] = ...