diff -r 663c2a9108d1 -r 4de31fdc0d67 pre_templates4/knight1.scala --- a/pre_templates4/knight1.scala Sun Nov 01 01:21:31 2020 +0000 +++ b/pre_templates4/knight1.scala Mon Nov 02 02:31:44 2020 +0000 @@ -2,7 +2,7 @@ //=============================================== -object CW8a { +object CW9a { // If you need any auxiliary function, feel free to // implement it, but do not make any changes to the @@ -17,7 +17,7 @@ //(1) Complete the function that tests whether the position x // is inside the board and not yet element in the path. -//def is_legal(dim: Int, path: Path, x: Pos) : Boolean = ... +def is_legal(dim: Int, path: Path, x: Pos) : Boolean = ??? @@ -25,8 +25,7 @@ // all legal onward moves that are not already in the path. // The moves should be ordered in a "clockwise" manner. - -//def legal_moves(dim: Int, path: Path, x: Pos) : List[Pos] = ... +def legal_moves(dim: Int, path: Path, x: Pos) : List[Pos] = ??? //some testcases @@ -44,9 +43,9 @@ // given path. The first function counts all possible tours, // and the second collects all tours in a list of paths. -//def count_tours(dim: Int, path: Path) : Int = ... +def count_tours(dim: Int, path: Path) : Int = ??? -//def enum_tours(dim: Int, path: Path) : List[Path] = ... +def enum_tours(dim: Int, path: Path) : List[Path] = ??? //(4) Implement a first-function that finds the first @@ -54,7 +53,7 @@ // In that case Return f(x), otherwise None. If possible, // calculate f(x) only once. -//def first(xs: List[Pos], f: Pos => Option[Path]) : Option[Path] = ... +def first(xs: List[Pos], f: Pos => Option[Path]) : Option[Path] = ??? // testcases @@ -69,14 +68,10 @@ // trying out onward moves, and searches recursively for a // knight tour on a dim * dim-board. - -//def first_tour(dim: Int, path: Path) : Option[Path] = ... +def first_tour(dim: Int, path: Path) : Option[Path] = ??? - - - /* Helper functions @@ -95,16 +90,14 @@ // running count_tours - - // for printing a board def print_board(dim: Int, path: Path): Unit = { - println + println() for (i <- 0 until dim) { for (j <- 0 until dim) { print(f"${path.reverse.indexOf((j, dim - i - 1))}%3.0f ") } - println + println() } }