/* * @topic W120161 Java <a href="http://www.c-jump.com/bcc/c123c/c123sample/Java/Week11/tic_tac_toe_class_violet.html" target="_blank">Tic-Tac-Toe Game</a> * @brief class StrategyRandom extends Strategy */ package tictactoeapp; public class StrategyRandom extends Strategy { // constructors public StrategyRandom( Board board ) { super( board ); } // operations @Override public void nextMove( int piece ) { // Find and use unallocated square on the board // Squares are in range zero to board.size()-1 for(;;) { int idx = (int)(Math.random()*board.size()); if ( board.getSquareValue(idx) == Board.PIECE_EMPTY ) { board.update(idx, piece); return; } } } }//class StrategyRandom