private void executeMove(int x, int y) { var piece = new Piece(PieceType.PIECEX); if (!BoardUtils.turnControl(xTurn, PieceType.PIECEX)) { piece = new Piece(PieceType.PIECEO); } squares[x, y].placePiece(piece); checkAllRows(); checkAllColumns(); checkAllDiagonals(); checkForDraw(); }
// return false if illegal (I.e. not your turn, not valid destination). // return true if successful, then update board state. public bool move(int x, int y, PieceType player) { if (getState() != GameState.ONGOING) { return(false); } if (!BoardUtils.turnControl(xTurn, player)) { return(false); } if (!BoardUtils.inRange(new int[] { x, y })) { return(false); } if (squares[x, y].isOccupied()) { return(false); } executeMove(x, y); xTurn = !xTurn; return(true); }