assignment2021scala/main4/knight2.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Tue, 08 Nov 2022 18:35:41 +0000
changeset 434 8c5804b2f9d2
parent 415 fced9a61c881
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
415
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
// Core Part about finding a single tour for a board using the
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
// Warnsdorf Rule
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
//==============================================================
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
object M4b {
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
// !!! Copy any function you need from file knight1.scala !!!
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
//
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
// If you need any auxiliary functions, feel free to 
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
// implement them, but do not make any changes to the
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
// templates below.
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    14
type Pos = (Int, Int)    // a position on a chessboard 
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
type Path = List[Pos]    // a path...a list of positions
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    17
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    18
//(6) Complete the function that calculates a list of onward
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    19
//    moves like in (2) but orders them according to Warnsdorf’s 
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    20
//    rule. That means moves with the fewest legal onward moves 
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    21
//    should come first.
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    22
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    23
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    24
def ordered_moves(dim: Int, path: Path, x: Pos) : List[Pos] = ???
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    25
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    26
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    27
//(7) Complete the function that searches for a single *closed* 
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    28
//    tour using the ordered_moves function from (6). This
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    29
//    function will be tested on a 6 x 6 board. 
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    30
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    31
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    32
def first_closed_tour_heuristics(dim: Int, path: Path) : Option[Path] = ???
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    33
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    34
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    35
//(8) Same as (7) but searches for *non-closed* tours. This 
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    36
//    version of the function will be called with dimensions of 
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    37
//    up to 30 * 30.
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
def first_tour_heuristics(dim: Int, path: Path) : Option[Path] = ???
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    40
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    41
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
}