MCPcopy
hub / github.com/careercup/ctci / playRandom

Method playRandom

java/Chapter 8/Question8_8/Automator.java:58–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56 }
57
58 public boolean playRandom() {
59 Board board = Game.getInstance().getBoard();
60 shuffle();
61 lastPlayer = lastPlayer == players[0] ? players[1] : players[0];
62 String color = lastPlayer.getColor().toString();
63 for (int i = 0; i < remainingMoves.size(); i++) {
64 Location loc = remainingMoves.get(i);
65 boolean success = lastPlayer.playPiece(loc.getRow(), loc.getColumn());
66
67 if (success) {
68 System.out.println("Success: " + color + " move at (" + loc.getRow() + ", " + loc.getColumn() + ")");
69 board.printBoard();
70 printScores();
71 return true;
72 }
73 }
74 System.out.println("Game over. No moves found for " + color);
75 return false;
76 }
77
78 public boolean isOver() {
79 if (players[0].getScore() == 0 || players[1].getScore() == 0) {

Callers 1

mainMethod · 0.95

Calls 12

getInstanceMethod · 0.95
shuffleMethod · 0.95
getRowMethod · 0.95
getColumnMethod · 0.95
printBoardMethod · 0.95
printScoresMethod · 0.95
getBoardMethod · 0.80
playPieceMethod · 0.80
toStringMethod · 0.45
getColorMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected