Skip to content

Commit 430d5bb

Browse files
committedMar 21, 2019
Tune evaluator for turkish rules.
refs #26.
1 parent 3dd23f5 commit 430d5bb

10 files changed

+44
-8
lines changed
 

‎src/Core/Evaluator.hs

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{-# LANGUAGE NamedFieldPuns #-}
22
{-# LANGUAGE RecordWildCards #-}
33
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE ExistentialQuantification #-}
45
module Core.Evaluator
56
( SimpleEvaluator (..),
7+
SimpleEvaluatorInterface (..),
8+
SimpleEvaluatorSupport (..),
69
defaultEvaluator
710
) where
811

@@ -14,11 +17,12 @@ import Core.Types
1417
import Core.Board
1518

1619
data SimpleEvaluator = SimpleEvaluator {
17-
seRules :: SomeRules,
20+
seRules :: SimpleEvaluatorInterface,
1821
seUsePositionalScore :: Bool,
1922
seMobilityWeight :: ScoreBase,
2023
seCenterWeight :: ScoreBase,
2124
seOppositeSideWeight :: ScoreBase,
25+
seBorderMenBad :: Bool,
2226
seBackedWeight :: ScoreBase,
2327
seAsymetryWeight :: ScoreBase,
2428
sePreKingWeight :: ScoreBase,
@@ -27,13 +31,26 @@ data SimpleEvaluator = SimpleEvaluator {
2731
}
2832
deriving (Show)
2933

30-
defaultEvaluator :: GameRules rules => rules -> SimpleEvaluator
34+
class GameRules rules => SimpleEvaluatorSupport rules where
35+
getBackDirections :: rules -> [PlayerDirection]
36+
getBackDirections _ = [BackwardLeft, BackwardRight]
37+
38+
getForwardDirections :: rules -> [PlayerDirection]
39+
getForwardDirections _ = [ForwardLeft, ForwardRight]
40+
41+
data SimpleEvaluatorInterface = forall g. SimpleEvaluatorSupport g => SimpleEvaluatorInterface g
42+
43+
instance Show SimpleEvaluatorInterface where
44+
show (SimpleEvaluatorInterface rules) = rulesName rules
45+
46+
defaultEvaluator :: SimpleEvaluatorSupport rules => rules -> SimpleEvaluator
3147
defaultEvaluator rules = SimpleEvaluator
32-
{ seRules = SomeRules rules
48+
{ seRules = SimpleEvaluatorInterface rules
3349
, seUsePositionalScore = True
3450
, seMobilityWeight = 3
3551
, seCenterWeight = 4
3652
, seOppositeSideWeight = 4
53+
, seBorderMenBad = True
3754
, seBackedWeight = 2
3855
, seAsymetryWeight = 1
3956
, sePreKingWeight = 3
@@ -74,7 +91,7 @@ instance Default PreScore where
7491
}
7592

7693
preEval :: SimpleEvaluator -> Side -> Board -> PreScore
77-
preEval (SimpleEvaluator { seRules = SomeRules rules, ..}) side board =
94+
preEval (SimpleEvaluator { seRules = SimpleEvaluatorInterface rules, ..}) side board =
7895
let
7996
kingCoef =
8097
-- King is much more useful when there are enough men to help it
@@ -108,13 +125,13 @@ preEval (SimpleEvaluator { seRules = SomeRules rules, ..}) side board =
108125
Just back -> isPieceAt back board side
109126

110127
backedScoreOf addr =
111-
length $ filter (isBackedAt addr) [BackwardLeft, BackwardRight]
128+
length $ filter (isBackedAt addr) $ getBackDirections rules
112129

113130
backedScore =
114131
fromIntegral $ sum $ map backedScoreOf $ allMyAddresses side board
115132

116133
tempNumber (Label col row)
117-
| col == 0 || col == ncols - 1 = 0
134+
| seBorderMenBad && (col == 0 || col == ncols - 1) = 0
118135
| otherwise = case boardSide (boardOrientation rules) side of
119136
Top -> nrows - row
120137
Bottom -> row + 1
@@ -123,7 +140,7 @@ preEval (SimpleEvaluator { seRules = SomeRules rules, ..}) side board =
123140
opponentSideCount =
124141
let (men, kings) = myLabelsCount' side board tempNumber in men
125142

126-
preKing board src = sum $ map check [ForwardLeft, ForwardRight]
143+
preKing board src = sum $ map check $ getForwardDirections rules
127144
where
128145
check dir =
129146
case myNeighbour rules side dir src of

‎src/Rules/Brazilian.hs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ newtype Brazilian = Brazilian GenericRules
1818
instance HasTopology Brazilian where
1919
boardTopology _ = Diagonal
2020

21+
instance SimpleEvaluatorSupport Brazilian
22+
2123
instance Show Brazilian where
2224
show = rulesName
2325

‎src/Rules/Canadian.hs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ instance Show Canadian where
2020
instance HasTopology Canadian where
2121
boardTopology _ = Diagonal
2222

23+
instance SimpleEvaluatorSupport Canadian
24+
2325
instance GameRules Canadian where
2426
boardSize _ = (12, 12)
2527

‎src/Rules/Diagonal.hs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ instance Show DiagonalRussian where
2020
instance HasTopology DiagonalRussian where
2121
boardTopology _ = Core.Types.Diagonal
2222

23+
instance SimpleEvaluatorSupport DiagonalRussian
24+
2325
instance GameRules DiagonalRussian where
2426
initBoard rnd r =
2527
let board = buildBoard rnd r (boardOrientation r) (8, 8)

‎src/Rules/English.hs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ instance Show English where
2222
instance HasTopology English where
2323
boardTopology _ = Diagonal
2424

25+
instance SimpleEvaluatorSupport English
26+
2527
instance GameRules English where
2628
boardSize _ = boardSize Russian.russian
2729

‎src/Rules/International.hs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ instance Show International where
2323
instance HasTopology International where
2424
boardTopology _ = Diagonal
2525

26+
instance SimpleEvaluatorSupport International
27+
2628
instance GameRules International where
2729
boardSize _ = (10, 10)
2830

‎src/Rules/Russian.hs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ newtype Russian = Russian GenericRules
2020
instance Show Russian where
2121
show = rulesName
2222

23+
instance SimpleEvaluatorSupport Russian
24+
2325
instance HasTopology Russian where
2426
boardTopology _ = Diagonal
2527

‎src/Rules/Simple.hs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ newtype Simple = Simple GenericRules
1818
instance Show Simple where
1919
show = rulesName
2020

21+
instance SimpleEvaluatorSupport Simple
22+
2123
instance HasTopology Simple where
2224
boardTopology _ = Diagonal
2325

‎src/Rules/Spancirety.hs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ instance Show Spancirety where
2020
instance HasTopology Spancirety where
2121
boardTopology _ = Diagonal
2222

23+
instance SimpleEvaluatorSupport Spancirety
24+
2325
instance GameRules Spancirety where
2426
initBoard rnd r =
2527
let board = buildBoard rnd r (boardOrientation r) (8, 10)

‎src/Rules/Turkish.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ instance Show Turkish where
2323
instance HasTopology Turkish where
2424
boardTopology _ = Orthogonal
2525

26+
instance SimpleEvaluatorSupport Turkish where
27+
getBackDirections _ = [Backward]
28+
2629
instance GameRules Turkish where
2730
initBoard rnd r =
2831
let board = buildBoard rnd r (boardOrientation r) (8, 8)
@@ -34,7 +37,7 @@ instance GameRules Turkish where
3437

3538
boardSize _ = (8, 8)
3639

37-
dfltEvaluator r = SomeEval $ defaultEvaluator r
40+
dfltEvaluator r = SomeEval $ (defaultEvaluator r) {seKingCoef = 5, seHelpedKingCoef = 6, seBorderMenBad = False}
3841

3942
boardNotation _ = chessNotation
4043

0 commit comments

Comments
 (0)
Please sign in to comment.