templates2/knight3.scala
author Christian Urban <urbanc@in.tum.de>
Sat, 16 Jun 2018 00:07:32 +0100
changeset 182 d3d912d7e17f
parent 146 61d9a5ac6430
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 3 about finding a single tour using the Warnsdorf Rule
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 files knight1.scala and
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
// knight2.scala
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
object CW7c {
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
type Pos = (Int, Int)    // a position on a chessboard 
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
type Path = List[Pos]    // a path...a list of positions
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
//(3a) Complete the function that calculates a list of onward
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
//     moves like in (1b) but orders them according to Warnsdorf’s 
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
//     rule. That means moves with the fewest legal onward moves 
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
//     should come first.
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 ordered_moves(dim: Int, path: Path, x: Pos) : List[Pos] = ..
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
//(3b) Complete the function that searches for a single *closed* 
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
//     tour using the ordered moves function.
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_closed_tour_heuristic(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
//(3c) Same as (3b) but searches for *non-closed* tours. However, 
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
//     you have to be careful to write a tail-recursive version as this 
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
//     function will be called with dimensions of up to 40 * 40.
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
//def first_tour_heuristic(dim: Int, path: Path) : Option[Path] = ...
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
61d9a5ac6430 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
}