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