Yahoo Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
3
of 3 vote

i wud like to answer the above question with design steps

1.problem statement
2.use cases
analysis & design
3.identifying objects
4.identifying interactions among objects
5.identifying attributes of objects
6.refining with hierarchy
at the end of sixth step, we shall get good class diagram,
after we can proceed for implementation with functional modeling

- spiderman December 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

1. problem statement

Chess is a board game of two players. Player could be human or computer. There are two sides of pieces in chess game. One is black and another one is white. A player chooses one of them and plays with that side.

Each side of pieces contains total 16 including 1 king, 1 queen, 2 bishops, 2 knights, 2 rooks and 8 pawns.

First board is initialized according to its standard initial position of pieces.
Each player gets his turn and makes valid move of his side piece and gives turn to opponent.

Checkmate of either side king is considered the end of game. In time limit game, either timeout or checkmate is considered as the end of game. Time limit game requires to maintain time watch of the two players.

- spiderman December 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

2. use cases

I. chess board is initialized to its standard position
II. a player chooses his side.
III. White side is given the first turn and after given turn to the side time-watch starts for the side.
IV. A player during his turn makes a move.
V. Validity of the move is checked
VI. Opponent king checkmate checked
VII. A piece is moved on the board accordingly.
VIII. Turn is given to opponent side.
IX. The game is ended if timeout happens of checkmate found.

- spiderman December 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

3. identifying objects

After looking at use-cases, objects could be the following
tangibles/externals:
chess-board, player, piece,

internal:
game, time-watch

- spiderman December 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

4. identifying the interactions among objects

game->(initializes)->chess-board
game->(arranges/moves)->piece
game->(starts/stops)->time-watch
player->(requests move)->game

- spiderman December 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

4. identifying the interactions among objects

chess-board->(consists of)->piece
game->(consiss)->players
game->(discards piece from)->chess-board

- spiderman December 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

5. identifying attributes

chess-board: matrix of positions, a position may contain piece
piece: side: white or black
king: type, queen: type, ....
game: players, chess-board, turn, time-watch
time-watch: timer
player: name, side

- spiderman December 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

6. refining with hierarchy

Player is inherited by "Human Player" and "Computer Player"
Piece is inherited by "King", "Queen", "Bishop", "Knight", "Rook", "Pawn"

- spiderman December 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

5. refining with hierarchy

Player is inherited by "Human Player" and "Computer Player"
Piece is inherited by "King", "Queen", "Bishop", "Knight", "Rook", "Pawn"

- spiderman December 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package lld.chess;

public class Game {

Player p1;
Player p2;
Player currentPlayer;

Board board;
GameAssistant gameAssistant;

public void registerPlayer(String name, PieceColor pieceColor) throws ChessException {
// If player has already taken color then throw message;
}

public void pickPlayer(String name){

}

public void createGameBoard(){
board = new Board();
board.initialize();
gameAssistant = new GameAssistant(board);
}

public void movePiece(int sX, int sY, int ex, int ey) throws ChessException{
if(!gameAssistant.isValidTurn(currentPlayer)) throw new ChessException("Invalid turn");
if(gameAssistant.isValidPick(currentPlayer, sX, sY)) throw new ChessException("Wrong piece picked");
// if(gameAssistant.isValidMove()) throw exception
// Piece p = gameAssistant.move()
// if p is of type KING then display currentPlayerWon
// else display other players turn.
}

private void displayTurn(){

}
private void displayWon(Player p){

}
}


package lld.chess;

/**
* Public interface. It will interact with user.
*/
public class GameAssistant {

Player playerLastPlayed;

Board board;

GameAssistant(Board board){

}

Piece move(int sX, int sY, int eX, int eY){
Piece p = board.getPiece(eX, eY);
board.movePlayer(sX, sY, eX, eY);
board.removePiece(eX, eY);
return p;

}

public boolean isValidTurn(Player player){
return false;
}

public boolean isValidPick(Player player, int i, int j){
return false;
}

public boolean isValidMove(int sX, int sY, int eX, int eY){
Piece p = board.getPiece(sX,sY);
if(p.validSteps(sX, sY, eX, eY) && board.isValidMove(sX, sY, eX, eY))
return true;

return false;

}
}

- Anonymous May 16, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

www(dot)nd(dot)edu/~cseprog/proj04_212/Chess_Hopkins_Oehmen_Lictenwalter/Final%20Project%20-%20Chess%20Game/cse212final.pdf mb it will help you

- uugan August 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Come and get your candy..

- Thekkumootil April 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More