Skip to content

Instantly share code, notes, and snippets.

@byron-perez
Created February 8, 2018 22:01
Show Gist options
  • Save byron-perez/94c98a88fe5a193065509b5ba4a2eb87 to your computer and use it in GitHub Desktop.
Save byron-perez/94c98a88fe5a193065509b5ba4a2eb87 to your computer and use it in GitHub Desktop.
ways to give a check
#include <bits/stdc++.h>
using namespace std;
vector<int> findBlackKing(vector < vector<char> > board)
{
int board_len = board.size();
vector<int> king_pos;
for(int x = 0; x < board_len; x++)
{
for(int y = 0; y < board_len; y++)
{
if(board[x][y] == 'k')
{
king_pos.push_back(x);
king_pos.push_back(y);
}
}
}
return king_pos;
}
int waysToGiveACheck(vector < vector<char> > board) {
//getting the size of the board (dimensions)
int n = board.size();
//position of a valid pawn to be promoted
vector<int> valid_pawn_pos;
//position of the king
vector<int> black_king_pos;
//number of ways to give a check
int ways_to_give_a_check = 0;
//find position of valid pawn
for(int i = 0; i < n; i++)
{
if(board[1][i] == 'P')
{
if(board[0][i] == '#')
{
valid_pawn_pos.push_back(1);
valid_pawn_pos.push_back(i);
}
}
}
//find position of black king
black_king_pos = findBlackKing(board);
/*find all ways to give a check situation*/
if(board[valid_pawn_pos[0]])
cout << "(" << valid_pawn_pos[0] << " " << valid_pawn_pos[1] << ")" << endl;
cout << "(" << black_king_pos[0] << " " << black_king_pos[1] << ")" << endl;
cout << endl;
return 0;
}
int main() {
int t;
cin >> t;
for(int a0 = 0; a0 < t; a0++){
vector< vector<char> > board(8,vector<char>(8));
for(int board_i = 0;board_i < 8;board_i++){
for(int board_j = 0;board_j < 8;board_j++){
cin >> board[board_i][board_j];
}
}
int result = waysToGiveACheck(board);
cout << result << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment