Skip to content

Commit 527478a

Browse files
author
Daniel Barclay
committed
ManualTicTacToe: Misc. little: fixed misspellings, edited comments, etc.
1 parent 8212e03 commit 527478a

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/main/scala/com/us/dsb/explore/algs/ttt/manual/game/Board.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private[game] class Board(private val cellStates: Vector[Cell]) {
5555

5656
// ?? Q: How to use Tuple3 in data and then convert to or use as 3-element
5757
// List and call .forall?
58-
// ?? any way auto-generate this simply? or factor out repeated cell pairs?
58+
// ?? any way auto-generate this _simply_? or factor out repeated cell pairs?
5959
private type CellRawIndices = (Int, Int)
6060
private val linesData: List[(CellRawIndices, CellRawIndices, CellRawIndices)] =
6161
List(

src/main/scala/com/us/dsb/explore/algs/ttt/manual/game/GameState.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ object GameState {
1919
GameState(Board.initial, None, startingPlayer)
2020
def initial: GameState = initial(Player.X)
2121
}
22+
import GameState._
2223

2324
/**
2425
* TTT game state _and_ controller--should functions be separated or together?
2526
*
2627
* @param gameResult `None` means no win or draw yet
2728
*/
2829
case class GameState(board: Board,
29-
gameResult: Option[GameState.GameResult],
30+
gameResult: Option[GameResult],
3031
currentPlayer: Player
3132
) {
3233

@@ -43,10 +44,10 @@ case class GameState(board: Board,
4344
val markedBoard = board.withCellMarkedForPlayer(row, column, currentPlayer)
4445
val newGameResult =
4546
if (markedBoard.hasThreeInARow) {
46-
GameState.GameResult.Win(currentPlayer).some
47+
GameResult.Win(currentPlayer).some
4748
}
4849
else if (markedBoard.hasNoMovesLeft) {
49-
GameState.GameResult.Draw.some
50+
GameResult.Draw.some
5051
}
5152
else {
5253
gameResult

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scala.util.chaining.scalaUtilChainingOps
1111
/** TTT UI controller. */
1212
object GameUI {
1313

14-
// ??? enhance; maybe just put clean strings in; maybe build on GameResult (plus quit case)
14+
// ?? enhance; maybe just put clean strings in; maybe build on GameResult (plus quit case)
1515
case class GameUIResult(text: String)
1616

1717

@@ -35,8 +35,6 @@ object GameUI {
3535
// (Could put strings in enumerators and use Enum.withName to factor down
3636
// parse function, but then layers wouldn't be separated.)
3737

38-
// ?? revisit String (but may be fine since dealing with input _strings_
39-
// from _user_
4038
// ?? revisit Either--use something fancier (MonadError)?
4139
private def parseCommand(rawCmd: String): Either[String, UICommand] = {
4240
import UICommand._
@@ -88,7 +86,7 @@ object GameUI {
8886
uiState.copy(gameState = newGameState)
8987
case Left(errorMsg) =>
9088
// ??? probably change return value to carry state plus any message
91-
// (or possibly Either, with caller displaying)
89+
// (or possibly Either, with caller displaying)
9290
io.printError(errorMsg)
9391
uiState // no change
9492
}
@@ -124,7 +122,7 @@ object GameUI {
124122
case None => // game not done yet (after valid _or_ invalid mark try)
125123
newState.asRight
126124
case Some(gameResult) =>
127-
import GameState.GameResult._ // ??? unnest? leave?
125+
import GameState.GameResult._
128126
val resultText =
129127
gameResult match {
130128
case Draw => "Game ended in draw"
@@ -159,7 +157,7 @@ object GameUI {
159157
}
160158
}
161159

162-
// ???? soon, probably create class GameUI to hold NameThisIO (to avoid passing
160+
// ??? soon, probably create class GameUI to hold NameThisIO (to avoid passing
163161
// all around); but think about currently pure methods vs. using IO member)
164162

165163
// ??? add more GameUI tests:

0 commit comments

Comments
 (0)