Skip to content

Commit 8212e03

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

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ private[game] class Board(private val cellStates: Vector[Cell]) {
5656
// ?? Q: How to use Tuple3 in data and then convert to or use as 3-element
5757
// List and call .forall?
5858
// ?? any way auto-generate this simply? or factor out repeated cell pairs?
59-
private type CellRawIndices = Tuple2[Int, Int]
60-
private val linesData: List[Tuple3[CellRawIndices, CellRawIndices, CellRawIndices]] =
59+
private type CellRawIndices = (Int, Int)
60+
private val linesData: List[(CellRawIndices, CellRawIndices, CellRawIndices)] =
6161
List(
6262
((1, 1), (1, 2), (1, 3)),
6363
((2, 1), (2, 2), (2, 3)),
@@ -98,7 +98,6 @@ private[game] class Board(private val cellStates: Vector[Cell]) {
9898
def renderMultiline: String = {
9999
val cellWidth = " X ".length
100100
val cellSeparator = "|"
101-
// ?? use new Order or leave using indices declarations?
102101
val wholeWidth =
103102
columnIndices.length * cellWidth +
104103
(columnIndices.length - 1) * cellSeparator.length
@@ -115,7 +114,6 @@ private[game] class Board(private val cellStates: Vector[Cell]) {
115114
}
116115

117116
def renderCompactMultiline: String = {
118-
// ?? use new Order or leave using indices declarations?
119117
rowIndices.map { row =>
120118
columnIndices.map { column =>
121119
getMarkAt(row, column) match {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ case class GameState(board: Board,
3232

3333
// ?? later refine from Either[String, ...] to "fancier" error type
3434
// ?? maybe add result of move (win/draw/other) with new state (so caller
35-
// doesn't have to check state's gameResult;
35+
// doesn't have to check state's gameResult; also, think about where I'd add
36+
// game history
3637

3738
def tryMoveAt(row: RowIndex,
3839
column: ColumnIndex
@@ -53,7 +54,7 @@ case class GameState(board: Board,
5354
GameState(markedBoard, newGameResult, currentPlayer.opponent).asRight
5455
case Some(nameThis) =>
5556
(s"Can't place mark at row $row, column $column;" +
56-
s" is already marked (${nameThis})").asLeft
57+
s" is already marked ($nameThis)").asLeft
5758
}
5859
}
5960

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ import io.estatico.newtype.macros.newtype
88
package object game {
99

1010
type Order = 3
11-
val Order = valueOf[Order]
11+
val Order: Order = valueOf[Order]
1212

1313
/** TTT row or column index integer; 1-based; top row, left column row are #1. */
1414
type Index = Int Refined Closed[1, Order]
1515
object Index extends RefinedTypeOps.Numeric[Index, Int]
1616

17-
// ?? revisit use--in both table and UI selection model; separate?
18-
19-
import scala.language.implicitConversions // suppress warning from @newtype
20-
// ???? what exactly does "private" on a newtype affect?
17+
import scala.language.implicitConversions // suppress warning from @newtype
18+
// ?? what exactly does "private" on a newtype affect?
2119
@newtype case class RowIndex(value: Index)
2220
@newtype case class ColumnIndex(value: Index)
2321

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import enumeratum.{Enum, EnumEntry}
88
import scala.annotation.tailrec
99
import scala.util.chaining.scalaUtilChainingOps
1010

11-
// ?? any substantial benefit to moving internal methods to class? we could
12-
// avoid some state passing, but only by mutating top-level state member
13-
1411
/** TTT UI controller. */
1512
object GameUI {
1613

@@ -73,10 +70,10 @@ object GameUI {
7370
): GameUIState = {
7471
import UICommand._
7572
moveCommand match {
76-
case Up => uiState.withRowAdustedBy(-1)
77-
case Down => uiState.withRowAdustedBy(1)
78-
case Left => uiState.withColumnAdustedBy(-1)
79-
case Right => uiState.withColumnAdustedBy(1)
73+
case Up => uiState.withRowAdjustedBy(-1)
74+
case Down => uiState.withRowAdjustedBy(1)
75+
case Left => uiState.withColumnAdjustedBy(-1)
76+
case Right => uiState.withColumnAdjustedBy(1)
8077
}
8178
}
8279

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private case class GameUIState(gameState: GameState,
88
selectedColumn: ColumnIndex) {
99

1010
// ?? clean up that floorMod; I just want plain mathematical mod:
11-
private def adjustAndwrapToRange(unincremented: Index, delta: Int): Index = {
11+
private def adjustAndWrapToRange(unincremented: Index, delta: Int): Index = {
1212
// ?? maybe enable auto-wrapping and -unwrapping around math
1313
val indexOrigin = Index.MinValue.value
1414
val rangeSize = Index.MaxValue.value - Index.MinValue.value + 1
@@ -24,11 +24,11 @@ private case class GameUIState(gameState: GameState,
2424
// our cursor-based row/column specification; what would GUI use, just
2525
// 9 table-level IDs tied to GUI cells/buttons?);
2626

27-
private[ui] def withRowAdustedBy(delta: Int): GameUIState =
28-
copy(selectedRow = RowIndex(adjustAndwrapToRange(selectedRow.value, delta)))
27+
private[ui] def withRowAdjustedBy(delta: Int): GameUIState =
28+
copy(selectedRow = RowIndex(adjustAndWrapToRange(selectedRow.value, delta)))
2929

30-
private[ui] def withColumnAdustedBy(delta: Int): GameUIState =
31-
copy(selectedColumn = ColumnIndex(adjustAndwrapToRange(selectedColumn.value, delta)))
30+
private[ui] def withColumnAdjustedBy(delta: Int): GameUIState =
31+
copy(selectedColumn = ColumnIndex(adjustAndWrapToRange(selectedColumn.value, delta)))
3232

3333
private def renderTableMultilineWithSelection: String = {
3434
val cellWidth = " X ".length

0 commit comments

Comments
 (0)