Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Knight and Bishop

By khatribiru · Limits 2s, 512 MB

We all know about the chess game. Chess game is played on 8x8 board. Now, Alice and Bob come to play chess. They go to the chess grandmaster Magnus Carlsen to request him to organize their chess matches. So Magnus Carlsen organizes the match between them. But he sets up the new rules of the chess for the both players. There are only two types of pieces: Knight and Bishop. Each player is provided exactly one chess piece, either Bishop or Knight. (Both player can have same pieces.).

  • Alice is the first player and Bob is the second player. They move their pieces alternatively.
  • If anyone of them can capture the piece of the opposite player, then s/he will be the winner of the match.
  • Both of them will play optimally.

You have to determine the winner of the match. If no one can win, then the game will be drawn.

Those who are not familiar with chess knights, note that in a single move, a chess knight can attack at most 8 positions within the board. A Bishop can move and attack diagonally at any position within the board as it is shown in the pictures below.


Input starts with an integer T (1 <= T <= 100000) denoting number of test cases. Following T lines describe the piece and position of the chess piece of Alice and Bob in two separated word where each word length is 3. First character of each word denotes the types of piece (‘B’ for Bishop or ‘K’ for Knight), second character denotes the column number (from ‘a’ to ‘h’) from left to right and third character denotes the row number (from 1 to 8) from bottom to top.


For each test case, output a line like ‘Case X: Y’ where X denotes the number of case and Y denotes the name of the winner or the word “Draw”. If Alice wins the game, print “Alice” without quote. If Bob wins the game, print “Bob” without quote. If none of them can manage to win the game, then just print “Draw” without quote.


Ba1 Bb2
Ka1 Bb1
Case 1: Alice
Case 2: Draw


Login to submit