@@ -73,10 +73,16 @@ boardDirection Bottom ForwardLeft = UpLeft
73
73
boardDirection Bottom ForwardRight = UpRight
74
74
boardDirection Bottom BackwardLeft = DownLeft
75
75
boardDirection Bottom BackwardRight = DownRight
76
+ boardDirection Bottom Forward = Up
77
+ boardDirection Bottom Backward = Down
76
78
boardDirection Top ForwardLeft = DownRight
77
79
boardDirection Top ForwardRight = DownLeft
78
80
boardDirection Top BackwardLeft = UpRight
79
81
boardDirection Top BackwardRight = UpLeft
82
+ boardDirection Top Backward = Up
83
+ boardDirection Top Forward = Down
84
+ boardDirection _ PRight = ToRight
85
+ boardDirection _ PLeft = ToLeft
80
86
81
87
boardSide :: BoardOrientation -> Side -> BoardSide
82
88
boardSide FirstAtBottom First = Bottom
@@ -98,22 +104,36 @@ playerDirection First UpLeft = ForwardLeft
98
104
playerDirection First UpRight = ForwardRight
99
105
playerDirection First DownLeft = BackwardLeft
100
106
playerDirection First DownRight = BackwardRight
107
+ playerDirection First Up = Forward
108
+ playerDirection First Down = Backward
101
109
playerDirection Second UpLeft = BackwardRight
102
110
playerDirection Second UpRight = BackwardLeft
103
111
playerDirection Second DownLeft = ForwardRight
104
112
playerDirection Second DownRight = ForwardLeft
113
+ playerDirection Second Down = Forward
114
+ playerDirection Second Up = Backward
115
+ playerDirection _ ToRight = PRight
116
+ playerDirection _ ToLeft = PLeft
105
117
106
118
oppositeDirection :: PlayerDirection -> PlayerDirection
107
119
oppositeDirection ForwardLeft = BackwardRight
108
120
oppositeDirection ForwardRight = BackwardLeft
109
121
oppositeDirection BackwardLeft = ForwardRight
110
122
oppositeDirection BackwardRight = ForwardLeft
123
+ oppositeDirection Forward = Backward
124
+ oppositeDirection Backward = Forward
125
+ oppositeDirection PRight = PLeft
126
+ oppositeDirection PLeft = PRight
111
127
112
128
neighbour :: BoardDirection -> Address -> Maybe Address
113
129
neighbour UpLeft a = aUpLeft a
114
130
neighbour UpRight a = aUpRight a
115
131
neighbour DownLeft a = aDownLeft a
116
132
neighbour DownRight a = aDownRight a
133
+ neighbour Up a = aUp a
134
+ neighbour ToRight a = aRight a
135
+ neighbour Down a = aDown a
136
+ neighbour ToLeft a = aLeft a
117
137
118
138
myNeighbour :: HasBoardOrientation rules => rules -> Side -> PlayerDirection -> Address -> Maybe Address
119
139
myNeighbour rules side dir a = neighbour (myDirection rules side dir) a
@@ -124,6 +144,10 @@ getNeighbourDirection src dst
124
144
| aUpRight src == Just dst = Just UpRight
125
145
| aDownLeft src == Just dst = Just DownLeft
126
146
| aDownRight src == Just dst = Just DownRight
147
+ | aUp src == Just dst = Just Up
148
+ | aRight src == Just dst = Just ToRight
149
+ | aDown src == Just dst = Just Down
150
+ | aLeft src == Just dst = Just ToLeft
127
151
| otherwise = Nothing
128
152
129
153
getNeighbourDirection' :: Board -> Address -> Label -> Maybe BoardDirection
@@ -432,33 +456,6 @@ kingMove side src dir n = Move src $ replicate n (Step dir False False)
432
456
firstMoveDirection :: Move -> PlayerDirection
433
457
firstMoveDirection move = sDirection $ head $ moveSteps move
434
458
435
- makeLine :: [Label ] -> [Address ]
436
- makeLine labels = map (\ l -> Address l Nothing Nothing Nothing Nothing Nothing ) labels
437
-
438
- line1labels :: [Label ]
439
- line1labels = [" a1" , " c1" , " e1" , " g1" ]
440
-
441
- line2labels :: [Label ]
442
- line2labels = [" b2" , " d2" , " f2" , " h2" ]
443
-
444
- line3labels :: [Label ]
445
- line3labels = [" a3" , " c3" , " e3" , " g3" ]
446
-
447
- line4labels :: [Label ]
448
- line4labels = [" b4" , " d4" , " f4" , " h4" ]
449
-
450
- line5labels :: [Label ]
451
- line5labels = [" a5" , " c5" , " e5" , " g5" ]
452
-
453
- line6labels :: [Label ]
454
- line6labels = [" b6" , " d6" , " f6" , " h6" ]
455
-
456
- line7labels :: [Label ]
457
- line7labels = [" a7" , " c7" , " e7" , " g7" ]
458
-
459
- line8labels :: [Label ]
460
- line8labels = [" b8" , " d8" , " f8" , " h8" ]
461
-
462
459
calcBoardHash :: Board -> BoardHash
463
460
calcBoardHash board = foldr update 0 (boardAssocs board)
464
461
where
@@ -473,11 +470,24 @@ updateBoardHash :: Board -> Label -> Piece -> BoardHash
473
470
updateBoardHash board label piece =
474
471
updateBoardHash' (randomTable board) (boardHash board) label piece
475
472
476
- buildBoard :: RandomTableProvider rnd => rnd -> BoardOrientation -> BoardSize -> Board
477
- buildBoard rnd orient bsize@ (nrows, ncols) =
478
- let mkAddress p = Address (label p) (promote p) (upLeft p) (upRight p) (downLeft p) (downRight p)
473
+ buildBoard :: (RandomTableProvider rnd , HasTopology rules ) => rnd -> rules -> BoardOrientation -> BoardSize -> Board
474
+ buildBoard rnd rules orient bsize@ (nrows, ncols) =
475
+ let mkAddress p = Address {
476
+ aLabel = label p
477
+ , aPromotionSide = promote p
478
+ , aUpLeft = upLeft p
479
+ , aUpRight = upRight p
480
+ , aDownLeft = downLeft p
481
+ , aDownRight = downRight p
482
+ , aUp = up p
483
+ , aRight = right p
484
+ , aDown = down p
485
+ , aLeft = left p
486
+ }
479
487
label (r,c) = Label (c- 1 ) (r- 1 )
480
488
489
+ diagonal = boardTopology rules == Diagonal
490
+
481
491
promote (r,_)
482
492
| r == 1 = Just $ playerSide orient Top
483
493
| r == nrows = Just $ playerSide orient Bottom
@@ -499,11 +509,30 @@ buildBoard rnd orient bsize@(nrows, ncols) =
499
509
| r- 1 < 1 || c+ 1 > ncols = Nothing
500
510
| otherwise = M. lookup (r- 1 , c+ 1 ) addresses
501
511
512
+ up (r,c)
513
+ | r+ 1 > nrows = Nothing
514
+ | otherwise = M. lookup (r+ 1 , c) addresses
515
+
516
+ down (r,c)
517
+ | r- 1 < 1 = Nothing
518
+ | otherwise = M. lookup (r- 1 , c) addresses
519
+
520
+ right (r,c)
521
+ | c+ 1 > ncols = Nothing
522
+ | otherwise = M. lookup (r, c+ 1 ) addresses
523
+
524
+ left (r,c)
525
+ | c- 1 < 1 = Nothing
526
+ | otherwise = M. lookup (r, c- 1 ) addresses
527
+
502
528
addresses = M. fromList [(p, mkAddress p) | p <- coordinates]
503
529
504
530
odds n = [1 , 3 .. n]
505
531
evens n = [2 , 4 .. n]
506
- coordinates = [(r, c) | r <- odds nrows, c <- odds ncols] ++ [(r, c) | r <- evens nrows, c <- evens ncols]
532
+
533
+ coordinates
534
+ | diagonal = [(r, c) | r <- odds nrows, c <- odds ncols] ++ [(r, c) | r <- evens nrows, c <- evens ncols]
535
+ | otherwise = [(r, c) | r <- [1 .. nrows], c <- [1 .. ncols]]
507
536
508
537
addressByLabel = buildLabelMap nrows ncols [(label p, address) | (p, address) <- M. assocs addresses]
509
538
@@ -612,9 +641,33 @@ setManyPieces addresses piece board = foldr (\a b -> setPiece a piece b) board a
612
641
setManyPieces' :: [Label ] -> Piece -> Board -> Board
613
642
setManyPieces' labels piece board = foldr (\ l b -> setPiece' l piece b) board labels
614
643
615
- board8 :: RandomTableProvider rnd => rnd -> Board
616
- board8 rnd =
617
- let board = buildBoard rnd FirstAtBottom (8 , 8 )
644
+ line1labels :: [Label ]
645
+ line1labels = [" a1" , " c1" , " e1" , " g1" ]
646
+
647
+ line2labels :: [Label ]
648
+ line2labels = [" b2" , " d2" , " f2" , " h2" ]
649
+
650
+ line3labels :: [Label ]
651
+ line3labels = [" a3" , " c3" , " e3" , " g3" ]
652
+
653
+ line4labels :: [Label ]
654
+ line4labels = [" b4" , " d4" , " f4" , " h4" ]
655
+
656
+ line5labels :: [Label ]
657
+ line5labels = [" a5" , " c5" , " e5" , " g5" ]
658
+
659
+ line6labels :: [Label ]
660
+ line6labels = [" b6" , " d6" , " f6" , " h6" ]
661
+
662
+ line7labels :: [Label ]
663
+ line7labels = [" a7" , " c7" , " e7" , " g7" ]
664
+
665
+ line8labels :: [Label ]
666
+ line8labels = [" b8" , " d8" , " f8" , " h8" ]
667
+
668
+ board8 :: (RandomTableProvider rnd , HasTopology rules ) => rnd -> rules -> Board
669
+ board8 rnd rules =
670
+ let board = buildBoard rnd rules FirstAtBottom (8 , 8 )
618
671
labels1 = line1labels ++ line2labels ++ line3labels
619
672
labels2 = line8labels ++ line7labels ++ line6labels
620
673
in setManyPieces' labels1 (Piece Man First ) $ setManyPieces' labels2 (Piece Man Second ) board
@@ -660,7 +713,7 @@ boardRep :: Board -> BoardRep
660
713
boardRep board = BoardRep $ boardAssocs board
661
714
662
715
parseBoardRep :: (GameRules rules , RandomTableProvider rnd ) => rnd -> rules -> BoardRep -> Board
663
- parseBoardRep rnd rules (BoardRep list) = foldr set (buildBoard rnd orient bsize) list
716
+ parseBoardRep rnd rules (BoardRep list) = foldr set (buildBoard rnd rules orient bsize) list
664
717
where
665
718
set (label, piece) board = setPiece' label piece board
666
719
bsize = boardSize rules
0 commit comments