templates2/knight3.scala
author Christian Urban <urbanc@in.tum.de>
Thu, 07 Dec 2017 12:05:10 +0000
changeset 164 637301a9cb0f
parent 146 ed68f7239293
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
146
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
// Part 3 about finding a single tour using the Warnsdorf Rule
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
//=============================================================
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
// copy any function you need from files knight1.scala and
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
// knight2.scala
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
object CW7c {
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
type Pos = (Int, Int)    // a position on a chessboard 
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
type Path = List[Pos]    // a path...a list of positions
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
//(3a) Complete the function that calculates a list of onward
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
//     moves like in (1b) but orders them according to Warnsdorf’s 
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
//     rule. That means moves with the fewest legal onward moves 
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
//     should come first.
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
//def ordered_moves(dim: Int, path: Path, x: Pos) : List[Pos] = ..
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
//(3b) Complete the function that searches for a single *closed* 
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
//     tour using the ordered moves function.
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
//def first_closed_tour_heuristic(dim: Int, path: Path) : Option[Path] = ...
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
//(3c) Same as (3b) but searches for *non-closed* tours. However, 
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
//     you have to be careful to write a tail-recursive version as this 
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
//     function will be called with dimensions of up to 40 * 40.
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
//def first_tour_heuristic(dim: Int, path: Path) : Option[Path] = ...
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
ed68f7239293 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
}