Заменил if-else на gurads
This commit is contained in:
@@ -1,18 +1,10 @@
|
|||||||
forgivingStrategy :: (Ord t, Num t) => [Char] -> [Char] -> t -> [Char]
|
forgivingStrategy :: (Ord t, Num t) => [Char] -> [Char] -> t -> [Char]
|
||||||
forgivingStrategy opponentMoves generatedMoves n =
|
forgivingStrategy opponentMoves generatedMoves n
|
||||||
if n <= 100 && length opponentMoves /= 1
|
| n > 100 || length opponentMoves == 1 = generatedMoves
|
||||||
then
|
| n == 0 = forgivingStrategy opponentMoves (generatedMoves ++ ['С']) (n + 1)
|
||||||
( if n == 0
|
| head opponentMoves == 'С' = forgivingStrategy (tail opponentMoves) (generatedMoves ++ ['С']) (n + 1)
|
||||||
then
|
| otherwise = forgivingStrategy (tail opponentMoves) (generatedMoves ++ ['П']) (n + 1)
|
||||||
forgivingStrategy opponentMoves (generatedMoves ++ ['С']) (n + 1)
|
|
||||||
else
|
|
||||||
if head opponentMoves == 'С'
|
|
||||||
then
|
|
||||||
forgivingStrategy (tail opponentMoves) (generatedMoves ++ ['С']) (n + 1)
|
|
||||||
else
|
|
||||||
forgivingStrategy (tail opponentMoves) (generatedMoves ++ ['П']) (n + 1)
|
|
||||||
)
|
|
||||||
else generatedMoves
|
|
||||||
|
|
||||||
indexOf :: (Eq t) => [t] -> t -> Int
|
indexOf :: (Eq t) => [t] -> t -> Int
|
||||||
indexOf [] _ = -1
|
indexOf [] _ = -1
|
||||||
@@ -35,6 +27,7 @@ nashStrategy opponentMoves generatedMoves n =
|
|||||||
]
|
]
|
||||||
nextStep = cases !! indexOf results result !! 1
|
nextStep = cases !! indexOf results result !! 1
|
||||||
|
|
||||||
|
getScore :: Num t => [Char] -> [Char] -> t -> t -> (t, t)
|
||||||
getScore moves1 moves2 score1 score2 =
|
getScore moves1 moves2 score1 score2 =
|
||||||
if length moves1 == 0 then (score1, score2)
|
if length moves1 == 0 then (score1, score2)
|
||||||
else getScore (tail moves1) (tail moves2) newScore1 newScore2
|
else getScore (tail moves1) (tail moves2) newScore1 newScore2
|
||||||
|
|||||||
Reference in New Issue
Block a user