solutions3/knight1.scala
changeset 326 7d983ee99fcc
parent 306 63d4301a8bc6
equal deleted inserted replaced
325:26058bf089ae 326:7d983ee99fcc
    46 // 1 mark
    46 // 1 mark
    47 
    47 
    48 def legal_moves(dim: Int, path: Path, x: Pos): List[Pos] = 
    48 def legal_moves(dim: Int, path: Path, x: Pos): List[Pos] = 
    49   moves(x).filter(is_legal(dim, path, _))
    49   moves(x).filter(is_legal(dim, path, _))
    50 
    50 
       
    51 
       
    52 
    51 // testcases
    53 // testcases
    52 //assert(legal_moves(8, Nil, (2,2)) == 
    54 //assert(legal_moves(8, Nil, (2,2)) == 
    53 //  List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)))
    55 //  List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)))
    54 //assert(legal_moves(8, Nil, (7,7)) == List((6,5), (5,6)))
    56 //assert(legal_moves(8, Nil, (7,7)) == List((6,5), (5,6)))
    55 //assert(legal_moves(8, List((4,1), (1,0)), (2,2)) == 
    57 //assert(legal_moves(8, List((4,1), (1,0)), (2,2)) == 
    56 //  List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4)))
    58 //  List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4)))
    57 //assert(legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6)))
    59 //assert(legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6)))
       
    60 //assert(legal_moves(8, Nil, (0,1)) == List((1,3), (2,2), (2,0)))
    58 //assert(legal_moves(1, Nil, (0,0)) == List())
    61 //assert(legal_moves(1, Nil, (0,0)) == List())
    59 //assert(legal_moves(2, Nil, (0,0)) == List())
    62 //assert(legal_moves(2, Nil, (0,0)) == List())
    60 //assert(legal_moves(3, Nil, (0,0)) == List((1,2), (2,1)))
    63 //assert(legal_moves(3, Nil, (0,0)) == List((1,2), (2,1)))
    61 
    64 
    62 // 2 marks
    65 // 2 marks