Tabnine Logo
Board
Code IndexAdd Tabnine to your IDE (free)

How to use
Board
in
com.acme.tictactoe.model

Best Java code snippets using com.acme.tictactoe.model.Board (Showing top 7 results out of 315)

origin: ericmaxwell2003/ticTacToe

/**
 *  Restart or start a new game, will clear the board and win status
 */
public void restart() {
  clearCells();
  winner = null;
  currentTurn = Player.X;
  state = GameState.IN_PROGRESS;
}
origin: ericmaxwell2003/ticTacToe

private boolean isValid(int row, int col ) {
  if( state == GameState.FINISHED ) {
    return false;
  } else if( isOutOfBounds(row) || isOutOfBounds(col) ) {
    return false;
  } else if( isCellValueAlreadySet(row, col) ) {
    return false;
  } else {
    return true;
  }
}
origin: ericmaxwell2003/ticTacToe

public Board() {
  restart();
}
origin: ericmaxwell2003/ticTacToe

/**
 * Mark the current row for the player who's current turn it is.
 * Will perform no-op if the arguments are out of range or if that position is already played.
 * Will also perform a no-op if the game is already over.
 *
 * @param row 0..2
 * @param col 0..2
 *
 */
public void mark( int row, int col ) {
  if(isValid(row, col)) {
    cells[row][col].setValue(currentTurn);
    if(isWinningMoveByPlayer(currentTurn, row, col)) {
      state = GameState.FINISHED;
      winner = currentTurn;
    } else {
      // flip the current turn and continue
      flipCurrentTurn();
    }
  }
}
origin: ericmaxwell2003/ticTacToe

/**
 * This test will simulate and verify x is the winner.
 *
 *    X | X | X
 *    O |   |
 *      | O |
 */
@Test
public void test3inRowAcrossTopForX() {
  board.mark(0,0); // x
  assertNull(board.getWinner());
  board.mark(1,0); // o
  assertNull(board.getWinner());
  board.mark(0,1); // x
  assertNull(board.getWinner());
  board.mark(2,1); // o
  assertNull(board.getWinner());
  board.mark(0,2); // x
  assertEquals(Player.X, board.getWinner());
}
origin: ericmaxwell2003/ticTacToe

@Before
public void setup() {
  board = new Board();
}
origin: ericmaxwell2003/ticTacToe

/**
 * This test will simulate and verify o is the winner.
 *
 *    O | X | X
 *      | O |
 *      | X | O
 */
@Test
public void test3inRowDiagonalFromTopLeftToBottomForO() {
  board.mark(0,1); // x
  assertNull(board.getWinner());
  board.mark(0,0); // o
  assertNull(board.getWinner());
  board.mark(2,1); // x
  assertNull(board.getWinner());
  board.mark(1,1); // o
  assertNull(board.getWinner());
  board.mark(0,2); // x
  assertNull(board.getWinner());
  board.mark(2,2); // o
  assertEquals(Player.O, board.getWinner());
}
com.acme.tictactoe.modelBoard

Most used methods

  • <init>
  • clearCells
  • flipCurrentTurn
  • getWinner
  • isCellValueAlreadySet
  • isOutOfBounds
  • isValid
  • isWinningMoveByPlayer
    Algorithm adapted from http://www.ntu.edu.sg/home/ehchua/programming/java/JavaGame_TicTacToe.html
  • mark
    Mark the current row for the player who's current turn it is. Will perform no-op if the arguments ar
  • restart
    Restart or start a new game, will clear the board and win status

Popular in Java

  • Parsing JSON documents to java classes using gson
  • onRequestPermissionsResult (Fragment)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • compareTo (BigDecimal)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • Collectors (java.util.stream)
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now