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