Skip to content

Commit 7a15e03

Browse files
committed
Parametrize Evaluator.
1 parent 59eb6fc commit 7a15e03

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/Core/Evaluator.hs

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE NamedFieldPuns #-}
2+
{-# LANGUAGE RecordWildCards #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
module Core.Evaluator where
45

@@ -17,13 +18,19 @@ loose = -maxBound
1718

1819
data SimpleEvaluator = SimpleEvaluator {
1920
seRules :: SomeRules,
21+
seNumericWeight :: Score,
2022
sePositionWeight :: Score,
21-
seKingCoef :: Score
23+
seCenterWeight :: Score,
24+
seOppositeSideWeight :: Score,
25+
seBackedWeight :: Score,
26+
seAsymetryWeight :: Score,
27+
seKingCoef :: Score,
28+
seHelpedKingCoef :: Score
2229
}
2330
deriving (Show)
2431

2532
defaultEvaluator :: GameRules rules => rules -> SimpleEvaluator
26-
defaultEvaluator rules = SimpleEvaluator (SomeRules rules) 1 3
33+
defaultEvaluator rules = SimpleEvaluator (SomeRules rules) 12 1 2 1 3 1 3 5
2734

2835
instance Evaluator SimpleEvaluator where
2936
evaluatorName _ = "simple"
@@ -35,13 +42,13 @@ instance Evaluator SimpleEvaluator where
3542
Just (Just True) -> e {sePositionWeight = 1}
3643
Just (Just False) -> e {sePositionWeight = 0}
3744

38-
evalBoard (SimpleEvaluator {seKingCoef=k, sePositionWeight, seRules=SomeRules rules}) whoAsks whoMovesNext board =
45+
evalBoard (SimpleEvaluator {seRules=SomeRules rules, ..}) whoAsks whoMovesNext board =
3946
let kingCoef side =
4047
-- King is much more useful when there are enough men to help it
4148
let (men, _) = myCounts side board
4249
in if men > 3
43-
then k+2
44-
else k
50+
then seHelpedKingCoef
51+
else seKingCoef
4552

4653
numericScore side =
4754
let (myMen, myKings) = myCounts side board
@@ -90,13 +97,13 @@ instance Evaluator SimpleEvaluator where
9097

9198
positionalScore side =
9299
let (men, kings) = myLabelsCount side board isCenter
93-
in 2 * (kingCoef side * fromIntegral kings + fromIntegral men) +
94-
fromIntegral (opponentSideCount side) +
95-
fromIntegral (3 * backedScore side) -
96-
fromIntegral (asymetry side)
100+
in seCenterWeight * (kingCoef side * fromIntegral kings + fromIntegral men) +
101+
seOppositeSideWeight * fromIntegral (opponentSideCount side) +
102+
seBackedWeight * fromIntegral (backedScore side) -
103+
seAsymetryWeight * fromIntegral (asymetry side)
97104

98-
myScore = myNumeric * 12 + (positionalScore whoAsks) * sePositionWeight
99-
opponentScore = opponentNumeric * 12 + positionalScore (opposite whoAsks) * sePositionWeight
105+
myScore = myNumeric * seNumericWeight + (positionalScore whoAsks) * sePositionWeight
106+
opponentScore = opponentNumeric * seNumericWeight + positionalScore (opposite whoAsks) * sePositionWeight
100107

101108
in if myNumeric == 0
102109
then loose

src/Rules/English.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ instance GameRules English where
3131
boardNotation r = numericNotation (boardSize r)
3232
parseNotation r = parseNumericNotation (boardSize r)
3333

34-
dfltEvaluator r = SomeEval $ (defaultEvaluator r) {seKingCoef = 2}
34+
dfltEvaluator r = SomeEval $ (defaultEvaluator r) {seKingCoef = 2, seHelpedKingCoef = 3}
3535

3636
rulesName _ = "english"
3737
updateRules r _ = r

0 commit comments

Comments
 (0)