Skip to content

Commit 00cf728

Browse files
committed
Various updates and style changes
1 parent 8c66724 commit 00cf728

File tree

6 files changed

+40
-50
lines changed

6 files changed

+40
-50
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014, Julien Tanguy
1+
Copyright (c) 2015, Julien Tanguy
22

33
All rights reserved.
44

lib/Shogi/SFEN.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ sfen :: Parser Game
1212
sfen = Game <$> (boardParser <* char ' ') <*> (color <* char ' ') <*> hand <*> optional (char ' ' *> natural) <* eof
1313

1414
color :: Parser Color
15-
color = ((char 'B' *> pure Black)
16-
<|> (char 'W' *> pure White))
15+
color = (char 'B' *> pure Black)
16+
<|> (char 'W' *> pure White)
1717

1818
hand :: Parser [Piece]
1919
hand = (char '-' *> pure [])
20-
<|> (fmap concat (many pieces))
20+
<|> fmap concat (many pieces)
2121

2222
pieces :: Parser [Piece]
23-
pieces = replicate <$> (option 1 (num)) <*> piece
23+
pieces = replicate <$> option 1 num <*> piece
2424

2525
boardParser :: Parser Board
26-
boardParser = (sepBy boardLine (char '/'))
26+
boardParser = sepBy boardLine (char '/')
2727

2828
boardLine :: Parser [Square]
2929
boardLine = fmap concat $ many ( ((:[]). Just <$> piece) <|> emptySq )
3030
where
31-
emptySq = (flip replicate Nothing) <$> num
31+
emptySq = flip replicate Nothing <$> num
3232

3333
num :: Parser Int
3434
num = fmap f $ oneOf "123456789"
@@ -54,22 +54,22 @@ gold :: Parser Piece
5454
gold = Gold . colored <$> oneOf "gG"
5555

5656
rook :: Parser Piece
57-
rook = Rook <$> promoted <*> (fmap colored $ oneOf "rR")
57+
rook = Rook <$> promoted <*> fmap colored (oneOf "rR")
5858

5959
bishop :: Parser Piece
60-
bishop = Bishop <$> promoted <*> (fmap colored $ oneOf "bB")
60+
bishop = Bishop <$> promoted <*> fmap colored (oneOf "bB")
6161

6262
silver :: Parser Piece
63-
silver = Silver <$> promoted <*> (fmap colored $ oneOf "sS")
63+
silver = Silver <$> promoted <*> fmap colored (oneOf "sS")
6464

6565
knight :: Parser Piece
66-
knight = Knight <$> promoted <*> (fmap colored $ oneOf "nN")
66+
knight = Knight <$> promoted <*> fmap colored (oneOf "nN")
6767

6868
lance :: Parser Piece
69-
lance = Lance <$> promoted <*> (fmap colored $ oneOf "lL")
69+
lance = Lance <$> promoted <*> fmap colored (oneOf "lL")
7070

7171
pawn :: Parser Piece
72-
pawn = Pawn <$> promoted <*> (fmap colored $ oneOf "pP")
72+
pawn = Pawn <$> promoted <*> fmap colored (oneOf "pP")
7373

7474
-- ** Utility
7575
colored :: Char -> Color

shogi.cabal

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ library
2121
, Shogi.SFEN
2222
-- other-modules:
2323
-- other-extensions:
24-
build-depends: base >=4.6 && <4.7
25-
, ansi-wl-pprint == 0.6.*
26-
, lens == 4.1.*
27-
, text == 0.11.*
28-
, transformers == 0.3.*
24+
build-depends: base >=4.6 && <4.8
25+
, ansi-wl-pprint >= 0.6
26+
, lens >= 4.1
27+
, text >= 0.11
28+
, transformers >= 0.3
2929
, trifecta >= 1.4
3030
hs-source-dirs: lib
3131
default-language: Haskell2010
@@ -35,25 +35,25 @@ test-suite tests
3535
default-language: Haskell2010
3636
main-is: TestSuite.hs
3737
hs-source-dirs: tests
38-
build-depends: base >=4.6 && <4.7
38+
build-depends: base >=4.6 && <4.8
3939
, shogi
4040
, trifecta >= 1.4
41-
, lens == 4.1.*
41+
, lens >= 4.1
4242
, tasty >= 0.4
4343
, tasty-hunit >= 0.4
4444
Other-modules:
4545
Shogi.SFEN.Tests
4646

4747
executable shogi
4848
main-is: Main.hs
49-
other-modules: Game.UI
49+
other-modules: UI
5050
-- other-extensions:
51-
build-depends: base >=4.6 && <4.7
52-
, ansi-wl-pprint == 0.6.*
53-
, lens == 4.1.*
54-
, ncurses == 0.2.*
55-
, text == 0.11.*
56-
, transformers == 0.3.*
51+
build-depends: base >=4.6 && <4.8
52+
, ansi-wl-pprint >= 0.6
53+
, lens >= 4.1
54+
, ncurses >= 0.2.8
55+
, text >= 0.11
56+
, transformers >= 0.3
5757
, trifecta >= 1.4
5858
, shogi
5959
hs-source-dirs: src

src/Game/Util.hs

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Main.hs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11

22
module Main where
33

4-
import Control.Monad.Trans.RWS
54
import Control.Monad.Trans.RWS
65
import Data.Monoid
7-
import qualified Data.Text.IO as TIO
86
import Text.PrettyPrint.ANSI.Leijen
97
import Text.Trifecta (parseString, Result(..))
108
import UI.NCurses
119

12-
import Shogi.Board
13-
import Shogi.Game
1410
import Shogi.SFEN
15-
import Game.UI
11+
import UI
1612

17-
-- initialSFEN = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL B -"
18-
initialSFEN = "7r1/6B1p/6Bsk/9/7P1/9/9/9/9 B 2S"
13+
initialSFEN :: String
14+
initialSFEN = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL B -"
15+
-- initialSFEN = "7r1/6B1p/6Bsk/9/7P1/9/9/9/9 B 2S"
1916

2017
main :: IO ()
2118
main = case parseString sfen mempty initialSFEN of
2219
Failure xs -> putDoc xs
2320
Success g -> runCurses $ do
2421
setEcho False
2522
w <- defaultWindow
26-
_ <- runRWST (mainLoop) w (UIState (g) (0,0))
23+
_ <- runRWST mainLoop w (UIState g (0,0))
2724
return ()
2825

src/Game/UI.hs renamed to src/UI.hs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-#LANGUAGE OverloadedStrings #-}
2-
module Game.UI where
2+
module UI where
33

44
import Control.Lens
55
import Control.Monad
@@ -10,7 +10,6 @@ import UI.NCurses
1010

1111
import Shogi.Board
1212
import Shogi.Game
13-
import Game.Util
1413

1514
data UIState = UIState { _game :: Game, _current :: (Integer,Integer)}
1615

@@ -56,16 +55,16 @@ drawGame g = do
5655
updateBoard :: Board -> Update ()
5756
updateBoard b = forM_ [0..8] $ \i -> (forM_ [0..8] $ \j -> do
5857
moveCursor (2*i+2) (3*j+1)
59-
drawText (showSq ((b!!(fromInteger i))!!(fromInteger j)))
58+
drawText (showSq (b !! fromInteger i !! fromInteger j))
6059
)
6160

6261
update :: RWST Window [Move] UIState Curses ()
6362
update = do
6463
w <- ask
65-
g <- gets (view (game))
64+
g <- gets (view game)
6665
(ci,cj) <- gets (view current)
6766
lift $ updateWindow w (drawGame g >> moveCursor (2*ci+2) (3*cj+2))
68-
lift $ render
67+
lift render
6968

7069
mainLoop :: RWST Window [Move] UIState Curses ()
7170
mainLoop = loop where
@@ -80,10 +79,10 @@ mainLoop = loop where
8079
' ' -> modify (game.player %~ togglePlayer) >> loop
8180
_ -> loop
8281
Just (EventSpecialKey k) -> case k of
83-
KeyUpArrow -> modify (current %~ (mapFst $ inBounds . subtract 1)) >> loop
84-
KeyDownArrow -> modify (current %~ (mapFst $ inBounds . (1+))) >> loop
85-
KeyLeftArrow -> modify (current %~ (mapSnd $ inBounds . subtract 1)) >> loop
86-
KeyRightArrow -> modify (current %~ (mapSnd $ inBounds . (1+))) >> loop
82+
KeyUpArrow -> modify (current . _1 %~ (inBounds . subtract 1)) >> loop
83+
KeyDownArrow -> modify (current . _1 %~ (inBounds . (1+))) >> loop
84+
KeyLeftArrow -> modify (current . _2 %~ (inBounds . subtract 1)) >> loop
85+
KeyRightArrow -> modify (current . _2 %~ (inBounds . (1+))) >> loop
8786
_ -> loop
8887
_ -> loop
8988
inBounds = (`mod` 9) . (9+)

0 commit comments

Comments
 (0)