@@ -17,36 +17,36 @@ object GameLogicSupport {
1717
1818 // (was "private[this]" before test calls:)
1919 @ tailrec
20- private [game] def pickRandomEmptyCell (board : BoardPlus )(implicit rng : Random ): Option [CellAddress ] = {
21- if (board .isFull)
20+ private [game] def pickRandomEmptyCell (boardPlus : BoardPlus )(implicit rng : Random ): Option [CellAddress ] = {
21+ if (boardPlus .isFull)
2222 None
2323 else {
2424 val row = rowIndices(rng.nextInt(BoardOrder ))
2525 val col = columnIndices(rng.nextInt(BoardOrder ))
26- if (board .getBallStateAt(CellAddress (row, col)).isEmpty)
26+ if (boardPlus .getBallStateAt(CellAddress (row, col)).isEmpty)
2727 Some (CellAddress (row, col))
2828 else
29- pickRandomEmptyCell(board ) // loop: try again
29+ pickRandomEmptyCell(boardPlus ) // loop: try again
3030 }
3131 }
3232
3333 /**
3434 * @param board
3535 * expected to be empty //???? maybe refactor something?
3636 */
37- private [game] def placeInitialBalls (board : BoardPlus )(implicit rng : Random ): MoveResult = {
37+ private [game] def placeInitialBalls (boardPlus : BoardPlus )(implicit rng : Random ): MoveResult = {
3838 val postPlacementsResult =
3939 // ???? parameterize:
40- (1 to 5 ).foldLeft(MoveResult (board , false )) {
40+ (1 to 5 ).foldLeft(MoveResult (boardPlus , false )) {
4141 case (resultSoFar, _) =>
4242 val address =
43- pickRandomEmptyCell(resultSoFar.board ).getOrElse(scala.sys.error(" Unexpectedly full board" ))
44- val postPlacementBoard = resultSoFar.board .withBallAt(address, pickRandomBallKind())
43+ pickRandomEmptyCell(resultSoFar.boardPlus ).getOrElse(scala.sys.error(" Unexpectedly full board" ))
44+ val postPlacementBoard = resultSoFar.boardPlus .withBallAt(address, pickRandomBallKind())
4545 val placementHandlingResult = LineDetector .handleBallArrival(postPlacementBoard, address)
46- MoveResult (placementHandlingResult.board , placementHandlingResult.anyRemovals)
46+ MoveResult (placementHandlingResult.boardPlus , placementHandlingResult.anyRemovals)
4747 }
4848 // ???? parameterize
49- postPlacementsResult.copy(board = postPlacementsResult.board .withOnDeckBalls(List .fill(3 )(pickRandomBallKind())))
49+ postPlacementsResult.copy(boardPlus = postPlacementsResult.boardPlus .withOnDeckBalls(List .fill(3 )(pickRandomBallKind())))
5050 }
5151
5252 private [game] sealed trait Action
@@ -59,12 +59,12 @@ object GameLogicSupport {
5959 }
6060 import Action ._
6161
62- def interpretTapLocationToTapAction (board : BoardPlus ,
62+ def interpretTapLocationToTapAction (boardPlus : BoardPlus ,
6363 address : CellAddress ): Action =
64- tapAndStateToTapAction(onABall = board .hasABallAt(address),
65- isSelectedAt = board .isSelectedAt(address),
66- hasABallSelected = board .hasABallSelected,
67- hasAnyCellSelected = board .hasAnyCellSelected)
64+ tapAndStateToTapAction(onABall = boardPlus .hasABallAt(address),
65+ isSelectedAt = boardPlus .isSelectedAt(address),
66+ hasABallSelected = boardPlus .hasABallSelected,
67+ hasAnyCellSelected = boardPlus .hasAnyCellSelected)
6868
6969 private def tapAndStateToTapAction (onABall : Boolean ,
7070 isSelectedAt : Boolean ,
@@ -110,46 +110,46 @@ object GameLogicSupport {
110110 action
111111 }
112112
113- private [this ] def placeNextBalls (board : BoardPlus )(implicit rng : Random ): MoveResult = {
113+ private [this ] def placeNextBalls (boardPlus : BoardPlus )(implicit rng : Random ): MoveResult = {
114114 val postPlacementResult =
115115 // ???? for 1 to 3, consume on-deck ball from list, and then place (better for internal state view);;
116116 // can replenish incrementally or later; later might show up better in internal state view
117- board .getOnDeckBalls
118- .foldLeft(MoveResult (board , false )) {
117+ boardPlus .getOnDeckBalls
118+ .foldLeft(MoveResult (boardPlus , false )) {
119119 case (curMoveResult, onDeckBall) =>
120- pickRandomEmptyCell(curMoveResult.board ) match {
120+ pickRandomEmptyCell(curMoveResult.boardPlus ) match {
121121 case None => // board full; break out early (game will become over)
122122 curMoveResult
123123 case Some (address) =>
124- val postDeueueBoard =
125- curMoveResult.board .withOnDeckBalls(curMoveResult.board .getOnDeckBalls.tail)
126- val postPlacementBoard = postDeueueBoard .withBallAt(address, onDeckBall)
124+ val postDeueueBoardPlus =
125+ curMoveResult.boardPlus .withOnDeckBalls(curMoveResult.boardPlus .getOnDeckBalls.tail)
126+ val postPlacementBoard = postDeueueBoardPlus .withBallAt(address, onDeckBall)
127127 LineDetector .handleBallArrival(postPlacementBoard, address)
128128 }
129129 }
130130 // ???? parameterize?
131131 // ????? check re duplicate on-deck code (look for other "fill(3)"
132- postPlacementResult.copy(board = postPlacementResult.board .withOnDeckBalls(List .fill(3 )(pickRandomBallKind())))
132+ postPlacementResult.copy(boardPlus = postPlacementResult.boardPlus .withOnDeckBalls(List .fill(3 )(pickRandomBallKind())))
133133 }
134134
135135 // ???? rename? isn't _user_ move result; is ball move/placement/arrival result
136- case class MoveResult (board : BoardPlus ,
136+ case class MoveResult (boardPlus : BoardPlus ,
137137 // ??? clarify re placing next three balls (re interpreting differently in different contexts
138138 anyRemovals : Boolean )
139139 {
140140 println(s " ??? ${this }" )
141141 // ??? print("")
142142 }
143143
144- private [game] def doPass (board : BoardPlus )(implicit rng : Random ): MoveResult =
145- placeNextBalls(board )
144+ private [game] def doPass (boardPlus : BoardPlus )(implicit rng : Random ): MoveResult =
145+ placeNextBalls(boardPlus )
146146
147147
148148 // ???: likely move core algorithm out; possibly move outer code into BoardPlus/BoardState:
149149 /**
150150 * @param toTapCell - must be empty */
151151 // (was "private[this]" before test calls:)
152- private [game] def pathExists (board : BoardPlus ,
152+ private [game] def pathExists (boardPlus : BoardPlus ,
153153 fromBallCell : CellAddress ,
154154 toTapCell : CellAddress ): Boolean = {
155155 // ???? CLEAN ALL THIS:
@@ -160,7 +160,7 @@ object GameLogicSupport {
160160 val blockedAt : Array [Array [Boolean ]] =
161161 rowIndices.map { row =>
162162 columnIndices.map { column =>
163- board .hasABallAt(CellAddress (row, column))
163+ boardPlus .hasABallAt(CellAddress (row, column))
164164 }.toArray
165165 }.toArray
166166 val cellsToExpandFrom = mutable.Queue [CellAddress ](fromBallCell)
@@ -202,22 +202,22 @@ object GameLogicSupport {
202202 }
203203
204204
205- private [game] def doTryMoveBall (board : BoardPlus , // ???? change to game state to carry and update score?
205+ private [game] def doTryMoveBall (boardPlus : BoardPlus , // ???? change to game state to carry and update score?
206206 from : CellAddress ,
207207 to : CellAddress
208208 )(implicit rng : Random ): MoveResult = {
209- val canMoveBall = pathExists(board , from, to)
209+ val canMoveBall = pathExists(boardPlus , from, to)
210210 canMoveBall match {
211211 case false => // can't move--ignore (keep selection state)
212- MoveResult (board , false )
212+ MoveResult (boardPlus , false )
213213 case true =>
214- val deselectedBoard = board .withNoSelection
215- val moveBallColor = deselectedBoard .getBallStateAt(from).get // ????
216- val postMoveBoard = deselectedBoard .withNoBallAt(from).withBallAt(to, moveBallColor)
214+ val deselectedBoardPlus = boardPlus .withNoSelection
215+ val moveBallColor = deselectedBoardPlus .getBallStateAt(from).get // ????
216+ val postMoveBoard = deselectedBoardPlus .withNoBallAt(from).withBallAt(to, moveBallColor)
217217
218218 val postHandlingResult = LineDetector .handleBallArrival(postMoveBoard, to)
219219 if (! postHandlingResult.anyRemovals )
220- placeNextBalls(postHandlingResult.board )
220+ placeNextBalls(postHandlingResult.boardPlus )
221221 else
222222 postHandlingResult
223223 }
0 commit comments