Epic Systems Interview Question for Software Engineers


Country: United States
Interview Type: In-Person




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

#include<bits/stdc++.h>
#define pp pair<char,char> 
#define ppi pair<int,int> 
#define ff first
#define ss second
#define mp make_pair
#define move mv
using namespace std;

string move;

pair<pp,pp> parsed_move(string move)
{
	return mp( mp(move[0]-'a',move[1]-'0') , mp(move[3]-'a',move[4]-'0') );		
}

class piece
{
	
	public :
	
	string rep;

			
	virtual string ret_rep()
	{
		return rep;
	}
	
	virtual bool is_valid(ppi frm,ppi to)
	{
		
	}
	
	void add_color(string c)
	{
		rep=c+rep;
	}
	
};

class empty:public piece
{
	public :
	
	empty()
	{
		rep="00";	
	}	
	
	string ret_rep()
	{
		return rep;
	}

};

class pawn:public piece
{	
	public :
	
	pawn()
	{
		rep="p";
	}
	
	string ret_rep()
	{
		return rep;
	}	
	
	bool is_valid(ppi frm,ppi to)
	{
	}
	
};

class king:public piece
{	
	int moved;	
	
	public :
	
	king()
	{
		rep="K";
		moved=0;
	}
	
	bool is_valid(ppi frm,ppi to)
	{
		
	}
	
	string ret_rep()
	{
		return rep;
	}
	
	
};

class queen:public piece
{	
	
	public :
		
	queen()
	{
		rep="Q";
	}
		
	bool is_valid(ppi frm,ppi to)
	{
		
	}

	string ret_rep()
	{
		return rep;
	}	
};


class rook:public piece
{
	
	public :		
	
	rook()
	{
		rep="R";
	}
	
	bool is_valid(ppi frm,ppi to)
	{
		
	}
	
	string ret_rep()
	{
		return rep;
	}

};

class knight:public piece
{
	public :
		
	knight()
	{
		rep="k";
	}
	
	bool is_valid(ppi frm,ppi to)
	{
		
	}
	
	string ret_rep()
	{
		return rep;
	}

};

class bishop:public piece
{
	public :
		
	bishop()
	{
		rep="B";
	}
	
	string ret_rep()
	{
		return rep;
	}
	
	
	bool is_valid(ppi frm,ppi to)
	{
		
	}
	
};


class chess_board
{
	
	public :
	
	
	vector<vector<piece*> > brd;
	string white,black;
	int moves;
	vector<string> move_details;
	
	chess_board()
	{
	}
	
	chess_board(string a,string b)
	{
		brd.resize(8,vector<piece*> (8));
		white=a,black=b;
		moves=0;
		
		initialize_board();
	}
	
	void initialize_board();
	
	void add_piece(int r,int c,piece *obj)
	{
		brd[r][c]=obj;
	}
		
	void move_p1()
	{
		cout<<"Your move Mr."<<white<<"\n";
		cin>>move;
		
		if( isvalid_move(1,move) )
		{
			commit_to_board(1,move);
			moves++;
		}
		else
			move_p1();
		
	}	
	
	void move_p2()
	{
		cout<<"Your move Mr."<<black<<"\n";
		
		cin>>move;
		
		if( isvalid_move(2,move) )
		{
			moves++;
			commit_to_board(2,move);
		}
		else
			move_p1();
		
	}
	
	void castling(int flag,string move)
	{
		
	}
	
	bool isvalid_move(int flag,string mv)
	{
		
	}
	
	void commit_to_board(int flag,string move)
	{
		move_details.push_back(move);
		if(move=="0-0" || move=="0-0-0") //castling
			castling(flag,move);
		else
		{
			pair<ppi,ppi> fnl=parsed_move(move);
			brd[fnl.ss.ff][fnl.ss.ss]=brd[fnl.ff.ff][fnl.ff.ss];
			brd[fnl.ff.ff][fnl.ff.ss]=new empty();
		}
		
	}
	
	void print_board()
	{
		cout<<"  ";
		for(int i=0;i<8;i++)
			cout<<char('a'+i)<<"  ";
		
		for(int i=0;i<8;i++)
		{
			cout<<"\n"<<i<<" ";
			for(int j=0;j<8;j++)
			{
				cout<<brd[i][j]->ret_rep()<<" ";		
			}
			
			cout<<" "<<i<<" ";
		}
		
		cout<<"\n  ";
		for(int i=0;i<8;i++)
			cout<<char('a'+i)<<"  ";
		
	}
	
	
};


void chess_board :: initialize_board()
{
	for(int j=0;j<8;j++)
		for(int i=0;i<8;i++)
			brd[i][j]=new empty();

	for(int i=0;i<8;i++)	
		brd[1][i]=new pawn(),
		brd[6][i]=new pawn();
		
	//4 rooks	
	brd[0][0]=new rook() , brd[0][7]=new rook();
	brd[7][0]=new rook() , brd[7][7]=new rook();
	
	//4 knights
	brd[0][1]=new knight() , brd[0][6]=new knight();
	brd[7][1]=new knight() , brd[7][6]=new knight();
	
	//4 bishops
	brd[0][2]=new bishop() , brd[0][5]=new bishop();
	brd[7][2]=new bishop() , brd[7][5]=new bishop();
	
	brd[0][3]=new king() , brd[7][3]=new king();
	brd[0][4]=new queen() , brd[7][4]=new queen();
	
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<8;j++)
			brd[i][j]->add_color("W") , brd[i+6][j]->add_color("B");
	}
} 

int main()
{

	string a="dhruv",b="pankaj";
	chess_board match(a,b);
	match.print_board();

}

Here , I have made a class for the board and a base class for pieces .
The board consists of 64 pointers to the class pieces .
Classes like king,queen,rook,knight,pawn etc inherit from the pieces .
Made an extra class empty which indicates empty box and it also inherits from the class pieces .

Using polymorphism or virtual functions , piece* can point to different sort of pieces on the board .

- dhsharma27 May 22, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

#include<iostream>
using namespace std;

int main(){
return 0;
}

- Anonymous June 29, 2015 | Flag Reply


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