Codota Logo
Board
Code IndexAdd Codota 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)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
SimpleDateFormat s =
  • Codota IconString pattern;new SimpleDateFormat(pattern)
  • Codota IconString template;Locale locale;new SimpleDateFormat(template, locale)
  • Codota Iconnew SimpleDateFormat()
  • Smart code suggestions by Codota
}
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

  • Start an intent from android
  • setRequestProperty (URLConnection)
  • setContentView (Activity)
  • findViewById (Activity)
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Notification (javax.management)
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now