A Chessboard Game

Two players are playing a game on a  chessboard. The rules of the game are as follows:

  • The game starts with a single coin located at some  coordinates. The coordinates of the upper left cell are , and of the lower right cell are .

  • In each move, a player must move the coin from cell  to one of the following locations:

    Note: The coin must remain inside the confines of the board.

  • Beginning with player 1, the players alternate turns. The first player who is unable to make a move loses the game.

Given the initial coordinates of the players' coins, assuming optimal play, determine which player will win the game

Example:

Input:  x = 5, y = 2
Output: Second

Approach

C++

#include <bits/stdc++.h>
using namespace std;

string chessboardGame(int xint y)
{
    x = x % 4;
    y = y % 4;
    if ((y == 0) || (y == 3) || (x == 0) || (x == 3))
        return "First";
    return "Second";
}

int main()
{
    int x = 5;
    int y = 2;

    cout << chessboardGame(xy<< "\n";

    return 0;
}


No comments:

Post a Comment