We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Game Theory
  4. A Chessboard Game
  5. Discussions

A Chessboard Game

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 68 Discussions, By:

recency

Please Login in order to post a comment

  • seoworld404
    3 weeks ago+ 0 comments

    It seems like you're interested in a chessboard game. Chess is a classic two-player strategy board game played on an 8x8 grid. Each player commands an army of 16 pieces: one king, one queen, two rooks, two knights, two bishops, and eight pawns. The objective is to checkmate your opponent's king, which means putting their king in a position where it cannot escape capture. For more details click on the link: http://www.hafsapc.com/

    0|
    Permalink
  • britvolli135
    1 month ago+ 1 comment

    Hello everyone, could you please recommend some python literature for beginners? Like onprivatewriting.net/

    0|
    Permalink
  • h9712561
    4 months ago+ 2 comments

    c++ solution without magic

    string chessboardGame(int x, int y) {
        vector<vector<bool>> cache(15, vector<bool>(15, false));
    
        auto fillCache = [&cache](int x, int y) {
            static vector<vector<int>> steps = {
                {-2, 1},
                {-2, -1},
                {1, -2},
                {-1, -2},
            };
            
            for (auto step : steps) {
                if (x+step[0] < 0 || x + step[0] > 14 ||
                    y + step[1] > 14 || y+step[1] < 0) {
                        continue;
                    }
    
                // if next player will lose in next step - we will win
                if (!cache[x + step[0]][y+step[1]]) {
                    cache[x][y] = true;
                }
            }
        };
    
        for (int i = 0; i < 15; i++) {
            for (int j = 0; j < 15 && i-j >= 0; j++) {
                fillCache(i-j, j);
            }
        }
        
        for (int i = 0; i < 15; i++) {
            for (int j = 0; j < 15; j++) {
                if (14 + (i - j) > 14)
                    continue;
                fillCache(14 + (i - j), j);
            }
        }
        
        return cache[x-1][y-1] ? "First" : "Second";
    }
    
    0|
    Permalink
  • wyu318
    9 months ago+ 0 comments

    python 3

    def chessboardGame(x, y):
        return 'Second' if 0<x%4<3 and 0<y%4<3 else 'First'
    
    -4|
    Permalink
  • thecodingsoluti2
    10 months ago+ 0 comments

    Here is A Chessboard Game problem solution in Python Java C++ and c programming - https://programs.programmingoneonone.com/2021/07/hackerrank-a-chessboard-game-problem-solution.html

    -3|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy