@@ -7,21 +7,21 @@ import com.github.daenyth.taklib.RuleSet.GameRule
77import scala .annotation .tailrec
88import scalax .collection .GraphEdge .UnDiEdge
99import scalax .collection .immutable .Graph
10- import scalaz . Ordering .{ EQ , GT , LT }
11- import scalaz . std . anyVal . intInstance
12- import scalaz . std . option ._
13- import scalaz . std . vector ._
14- import scalaz .syntax .either ._
15- import scalaz .syntax .foldable ._
16- import scalaz . syntax . order . _
17- import scalaz . syntax . semigroup . _
18- import scalaz .{ Equal , NonEmptyList , Semigroup , \ / }
10+ import cats . instances . int . _
11+ import cats . instances . option . _
12+ import cats . syntax . either ._
13+ import cats . syntax . order ._
14+ import cats .syntax .list ._
15+ import cats .syntax .semigroup ._
16+ import cats .{ Semigroup , Eq => Equal }
17+ import cats . data . NonEmptyList
18+ import cats . kernel . Comparison .{ EqualTo , GreaterThan , LessThan }
1919
2020sealed trait GameEndResult
2121object GameEndResult {
2222 implicit val gerInstance : Semigroup [GameEndResult ] with Equal [GameEndResult ] =
2323 new Semigroup [GameEndResult ] with Equal [GameEndResult ] {
24- override def append (f1 : GameEndResult , f2 : => GameEndResult ) = (f1, f2) match {
24+ override def combine (f1 : GameEndResult , f2 : GameEndResult ): GameEndResult = (f1, f2) match {
2525 case (DoubleRoad , _) => DoubleRoad
2626 case (_, DoubleRoad ) => DoubleRoad
2727 case (Draw , r : RoadWin ) => r
@@ -36,7 +36,7 @@ object GameEndResult {
3636 case (_, w : WinByResignation ) => w
3737 }
3838
39- override def equal (a1 : GameEndResult , a2 : GameEndResult ): Boolean = (a1, a2) match {
39+ override def eqv (a1 : GameEndResult , a2 : GameEndResult ): Boolean = (a1, a2) match {
4040 case (DoubleRoad , DoubleRoad ) => true
4141 case (Draw , Draw ) => true
4242 case (RoadWin (p1), RoadWin (p2)) => p1 == p2
@@ -151,15 +151,15 @@ object DefaultRules extends RuleSet {
151151
152152object Game {
153153
154- def ofSize (size : Int ): String \/ Game = ofSize(size, DefaultRules )
154+ def ofSize (size : Int ): Either [ String , Game ] = ofSize(size, DefaultRules )
155155
156- def ofSize (size : Int , rules : RuleSet ): String \/ Game =
156+ def ofSize (size : Int , rules : RuleSet ): Either [ String , Game ] =
157157 rules.stoneCounts.keySet
158158 .contains(size)
159159 .guard(s " Bad game size: $size" )
160160 .map { _ =>
161161 val b = Board .ofSize(size)
162- new Game (size, 1 , rules, NonEmptyList ((StartGameWithBoard (b), b)))
162+ new Game (size, 1 , rules, NonEmptyList ((StartGameWithBoard (b), b), Nil ))
163163 }
164164
165165 // Start at turn 3 to make the "play opponent's stone" rule easier
@@ -168,19 +168,19 @@ object Game {
168168 board.size,
169169 turnNumber,
170170 DefaultRules ,
171- NonEmptyList ((StartGameWithBoard (board), board))
171+ NonEmptyList ((StartGameWithBoard (board), board), Nil )
172172 )
173173
174- def fromPtn (ptn : String ): String \/ MoveResult [Game ] =
174+ def fromPtn (ptn : String ): Either [ String , MoveResult [Game ] ] =
175175 PtnParser .parseEither(PtnParser .ptn(DefaultRules ), ptn).map(_._2)
176176
177- def fromTps (tps : String ): String \/ Game =
177+ def fromTps (tps : String ): Either [ String , Game ] =
178178 TpsParser .parse(TpsParser .tps, tps) match {
179179 case TpsParser .Success ((board, turn, nextPlayer), _) =>
180180 // We use one turn for each player's action, Tps uses turn as a move for both players with a move counter between them
181181 val turnNumber = (2 * turn) + nextPlayer.fold(1 , 0 )
182- Game .fromBoard(board, turnNumber).right
183- case err : TpsParser .NoSuccess => err.msg.left
182+ Game .fromBoard(board, turnNumber).asRight
183+ case err : TpsParser .NoSuccess => err.msg.asLeft
184184 }
185185
186186}
@@ -208,7 +208,7 @@ class Game private (val size: Int,
208208 def takeTurn (action : TurnAction ): MoveResult [Game ] =
209209 rules.check(this , action).getOrElse {
210210 currentBoard.applyAction(nextPlayer, action).flatMap { nextState =>
211- val newHistory = (action, nextState) < :: history
211+ val newHistory = (action, nextState) :: history
212212 val game = new Game (size, turnNumber + 1 , rules, newHistory)
213213 game.winner match {
214214 case Some (gameEnd) => GameOver (gameEnd, game)
@@ -235,7 +235,7 @@ class Game private (val size: Int,
235235 }
236236
237237 def winner : Option [GameEndResult ] =
238- ( roads : Vector [GameEndResult ]).suml1Opt |+| flatWin
238+ Semigroup [GameEndResult ].combineAllOption(roads) |+| flatWin
239239
240240 private def roads : Vector [RoadWin ] = {
241241 def mkGraph (xs : Set [BoardIndex ]): Graph [BoardIndex , UnDiEdge ] = {
@@ -297,10 +297,10 @@ class Game private (val size: Int,
297297 if (! emptySpaceAvailable
298298 || whiteCount == reserve
299299 || blackCount == reserve) {
300- Some (whiteFlats cmp blackFlats match {
301- case LT => FlatWin (Black )
302- case EQ => Draw
303- case GT => FlatWin (White )
300+ Some (whiteFlats comparison blackFlats match {
301+ case LessThan => FlatWin (Black )
302+ case EqualTo => Draw
303+ case GreaterThan => FlatWin (White )
304304 })
305305 } else None
306306 case stack :: rest =>
0 commit comments