Skip to content

Commit 5454de7

Browse files
author
Daniel Barclay
committed
ColoredLines: Renamed GameState -> UpperGameState.
1 parent 00d46ab commit 5454de7

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

src/main/scala/com/us/dsb/explore/algs/coloredlines/manual/game/GameState.scala renamed to src/main/scala/com/us/dsb/explore/algs/coloredlines/manual/game/UpperGameState.scala

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import cats.syntax.option._
44
import cats.syntax.either._
55
import com.us.dsb.explore.algs.coloredlines.manual.game.board.CellAddress
66
import com.us.dsb.explore.algs.coloredlines.manual.game.GameLogicSupport.MoveResult
7-
import com.us.dsb.explore.algs.coloredlines.manual.game.GameState.GameResult.Done
87
import com.us.dsb.explore.algs.coloredlines.manual.game.board.{BallKind, BoardPlus}
98
import com.us.dsb.explore.algs.coloredlines.manual.game.board.{ColumnIndex, RowIndex}
109

1110
import scala.util.Random
1211

13-
private[manual] object GameState {
12+
private[manual] object UpperGameState {
1413

1514
/**
1615
* Result of completed game.
@@ -20,35 +19,35 @@ private[manual] object GameState {
2019
private[manual] case class Done(score: Int) extends GameResult
2120
}
2221

23-
private[this] def makeInitialState(implicit rng: Random): GameState = {
22+
private[this] def makeInitialState(implicit rng: Random): UpperGameState = {
2423
val initialPlacementResult = GameLogicSupport.placeInitialBalls(BoardPlus.empty)
2524
//????? probably split GameState level from slightly lower game state
2625
// carrying board plus score (probably modifying MoveResult for that)
27-
GameState(initialPlacementResult.boardPlus, None)
26+
UpperGameState(initialPlacementResult.boardPlus, None)
2827
}
2928

30-
private[manual/*game*/] def initial(seed: Long): GameState = makeInitialState(new Random(seed))
31-
private[manual] def initial(): GameState = makeInitialState(new Random())
29+
private[manual/*game*/] def initial(seed: Long): UpperGameState = makeInitialState(new Random(seed))
30+
private[manual] def initial(): UpperGameState = makeInitialState(new Random())
3231
}
33-
import GameState._
32+
import UpperGameState._
3433

3534
//???? add random-data state
3635

3736
/** Game state AND currently controller.
3837
* @constructor
3938
* @param gameResult `None` means no win or draw yet
4039
*/
41-
private[manual] case class GameState(boardPlus: BoardPlus,
42-
gameResult: Option[GameResult]
43-
)(implicit rng: Random) {
40+
private[manual] case class UpperGameState(boardPlus: BoardPlus,
41+
gameResult: Option[GameResult]
42+
)(implicit rng: Random) {
4443

4544
//????? Probably move to GameLogicSupport
4645

4746
// ?? later refine from Either[String, ...] to "fancier" error type
4847
// Xx?? maybe add result of move (win/draw/other) with new state (so caller
4948
// doesn't have to check state's gameResult; also, think about where I'd add
5049
// game history
51-
private[manual] def tryMoveAt(tapAddress: CellAddress): Either[String, GameState] = {
50+
private[manual] def tryMoveAt(tapAddress: CellAddress): Either[String, UpperGameState] = {
5251
import GameLogicSupport.Action._
5352
val tapAction = GameLogicSupport.interpretTapLocationToTapAction(boardPlus, tapAddress)
5453
println("tryMoveAt: tapAction = " + tapAction)
@@ -76,10 +75,10 @@ private[manual] case class GameState(boardPlus: BoardPlus,
7675

7776
val nextState =
7877
if (! moveResult.boardPlus.isFull) {
79-
GameState(moveResult.boardPlus, gameResult).asRight
78+
UpperGameState(moveResult.boardPlus, gameResult).asRight
8079
}
8180
else {
82-
GameState(moveResult.boardPlus, Some(Done(moveResult.boardPlus.getScore))).asRight
81+
UpperGameState(moveResult.boardPlus, Some(GameResult.Done(moveResult.boardPlus.getScore))).asRight
8382
}
8483
nextState
8584
}

src/main/scala/com/us/dsb/explore/algs/coloredlines/manual/ui/GameUI.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.us.dsb.explore.algs.coloredlines.manual.ui
22

33
import cats.syntax.option._
44
import cats.syntax.either._
5-
import com.us.dsb.explore.algs.coloredlines.manual.game.GameState
5+
import com.us.dsb.explore.algs.coloredlines.manual.game.UpperGameState
66
import com.us.dsb.explore.algs.coloredlines.manual.game.board.{ColumnIndex, Index, RowIndex}
77
import com.us.dsb.explore.algs.coloredlines.manual.game.board.CellAddress
88
import enumeratum.{Enum, EnumEntry}
@@ -124,7 +124,7 @@ private[manual] object GameUI {
124124
case None => // game not done yet (after valid _or_ invalid mark try)
125125
newState.asRight
126126
case Some(gameResult) =>
127-
import GameState.GameResult._
127+
import UpperGameState.GameResult._
128128
val resultText =
129129
gameResult match {
130130
case result: Done => s"Done: $result"
@@ -167,7 +167,7 @@ private[manual] object GameUI {
167167

168168
def runGame(io: SegregatedTextIO): GameUIResult = {
169169
val initialState =
170-
GameUIState(gameState = GameState.initial(),
170+
GameUIState(gameState = UpperGameState.initial(),
171171
cursorAddress = CellAddress.fromRaw(1, 1))
172172
getAndDoUiCommands(io, initialState)
173173
}

src/main/scala/com/us/dsb/explore/algs/coloredlines/manual/ui/GameUIState.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.us.dsb.explore.algs.coloredlines.manual.game._
55
import com.us.dsb.explore.algs.coloredlines.manual.game.board.{ColumnIndex, Index, RowIndex, columnIndices, rowIndices}
66

77
// ?? somewhere expand to allow for history (maybe via Semigroup or whatever has .compose?)
8-
private[this] case class GameUIState(gameState: GameState,
8+
private[this] case class GameUIState(gameState: UpperGameState,
99
cursorAddress: CellAddress) {
1010

1111
// ?? clean up that floorMod; I just want plain mathematical mod:

src/test/scala/com/us/dsb/explore/algs/coloredlines/manual/game/GameStateTest.scala renamed to src/test/scala/com/us/dsb/explore/algs/coloredlines/manual/game/UpperGameStateTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.scalatest.funspec.AnyFunSpec
44
import cats.syntax.option._
55
import com.us.dsb.explore.algs.coloredlines.manual.game.board.{ColumnIndex, Index, RowIndex}
66

7-
class XxGameStateTest extends AnyFunSpec {
7+
class UpperGameStateTest extends AnyFunSpec {
88

99
describe("XxGameState$?. tryMoveAt") {
1010
// import Player._

0 commit comments

Comments
 (0)