diff options
Diffstat (limited to 'src/main/scala/me/robbyzambito/othello/game/Game.scala')
-rw-r--r-- | src/main/scala/me/robbyzambito/othello/game/Game.scala | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/src/main/scala/me/robbyzambito/othello/game/Game.scala b/src/main/scala/me/robbyzambito/othello/game/Game.scala index ea8c382..4c0e7a2 100644 --- a/src/main/scala/me/robbyzambito/othello/game/Game.scala +++ b/src/main/scala/me/robbyzambito/othello/game/Game.scala @@ -1,8 +1,6 @@ package me.robbyzambito.othello.game import scala.annotation.tailrec -import scala.io.StdIn -import scala.util.Try /** * Represents the state of the game. @@ -66,23 +64,8 @@ case class Game(board: Board, def takeTurn: Game = { println(s"${this}\n") - def getPos: (Int, Int) = { - val rowCount = Iterator.continually( - Try(StdIn.readLine(s"Enter the row to move for ${currentPlayer}: ").toInt) - ).dropWhile(_.isFailure).next().get - val colCount = Iterator.continually( - Try(StdIn.readLine(s"Enter the col to move for ${currentPlayer}: ").toInt) - ).dropWhile(_.isFailure).next().get + val move = currentPlayer.nextMove(board) - (rowCount, colCount) - } - - val possibleMoves = currentPlayer.possibleMoves(board) - val pos = Iterator.continually(getPos) - .dropWhile(!possibleMoves.map(m => (m.rowCount, m.colCount)).contains(_)) - .next() - - val move = possibleMoves.find(m => m.rowCount == pos._1 && m.colCount == pos._2).get this.copy(board = move(board, currentPlayer), turnCount = turnCount + 1) } @@ -93,5 +76,7 @@ case class Game(board: Board, } object Game { - def apply(): Game = new Game(Board.init(), List(Player(Position.WHITE), Player(Position.BLACK))) + def apply(players: List[Player]): Game = new Game(Board.init(), players) + + def apply(): Game = Game( List(UserPlayer(Position.WHITE), AIPlayer(Position.BLACK)) ) }
\ No newline at end of file |