0
我想讓騎士從(1,1)
開始,並嘗試在整個桌子上移動。這是我的代碼:騎士爲什麼不把所有的桌子都蓋上?
canMove :: (Int -> Int) -> (Int -> Int) -> [(Int,Int)] -> Bool
canMove (x) (y) list
| (x (fst lastMove),y (snd lastMove)) `elem` list = False
| newX> 8 || newY> 8 || newX<=0 || newY<=0 = False
| otherwise = True
where lastMove = last list
newX = x (fst lastMove)
newY = y (snd lastMove)
move :: [(Int, Int)] -> [(Int, Int)]
move list
| length list == 64 = list
| canMove (+1) (+2) list = move (list ++ [(x+1,y+2)])
| canMove (+2) (+1) list = move (list ++ [(x+2,y+1)])
| canMove (subtract 1) (+2) list = move (list ++ [(x-1,y+2)])
| canMove (subtract 2) (+1) list = move (list ++ [(x-2,y+1)])
| canMove (subtract 1) (subtract 2) list = move (list ++ [(x-1,y-2)])
| canMove (subtract 2) (subtract 1) list = move (list ++ [(x-2,y-1)])
| canMove (+1) (subtract 2) list = move (list ++ [(x+1,y-2)])
| canMove (+2) (subtract 1) list = move (list ++ [(x+2,y-1)])
| otherwise = list
where lastMove = last list
x = fst lastMove
y = snd lastMove
y=length (move [(1,1)])
main = print $ y
爲什麼騎士在34
之後停下腳步?