Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3433098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:31:55+00:00 2026-05-18T07:31:55+00:00

I’m implementing a board with only 2 types of pieces, and was looking for

  • 0

I’m implementing a board with only 2 types of pieces, and was looking for a function to map from that board to a Long Integer (64 bits). I was thinking this should not be so hard, since a long integer contains more available information than an 8 by 8 array (call it grid[x][y]) with only 3 possible elements in each spot including the empty element. I tried the following:
(1) Zobrist hashing with Longs rather than ints (Just to test – I didn’t actually expect that to work perfectly)
(2) Translated the grid into a 64 character string of a base 3 number, and then took that number and parsed it into a long. I think this should work, but it took a very very long time.
Is there some simpler solution to (2) involving bit operations of shifting or something like that?
Edit: Please don’t give me actual code, as this is for a class project, and that would probably be considered unethical in our department (or at least not in Java).
Edit2: Basically, there are only 10 whites and 10 blacks on the board at any given time, of which no two pieces of the same color can be neighbors, either in the horizontal, vertical, or diagonal direction. Also, there are 12 spaces for each color where only that color may place pieces.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:31:56+00:00Added an answer on May 18, 2026 at 7:31 am

    If each tile in the game can be 1 of any 3 states at any point in the game, then the minimum amount of storage required for a “perfect hash” when hashing every possible state of the game board, at any given moment will
    = power(3,8*8) individual hashes
    = log2(3^64) bits
    = approx. 101.4 bits, so you will need at least 102 bits to store this info

    At this point, you may as well just say there are 4 states for each tile, which will bring you to needing 128 bits.

    Once you do this, its rather easy to make a fast hashing algorithm for the board.

    E.g. (writtin as c++, may need to alter code if the platform doesn’t support 128 bit numbers)

    uint_128 CreateGameBoardHash(int (&game_board)[8][8])
    {
        uint_128  board_hash = 0;
        for(int i = 0; i < 8; ++i)
        {
            for(int j = 0; j < 8; ++j)
            {
                board_hash |= game_board[i][j] << ((i * 8 + j) *2);
            }
        }
        return board_hash;
    }
    

    This method will only waste 26 bits (little more than 3 bytes) over the optimal solution of 102 bits, but you will save a LOT of processing time that would be otherwise spent doing base 3 math.


    Edit Here’s a version that doesn’t require 128 bits and should work on any 16-bit (or better) processor

    struct GameBoardHash
    {
        uint16 row[8];
    };

    GameBoardHash CreateGameBoardHash(int (&game_board)[8][8])
    {
    GameBoardHash board_hash;
    for(int i = 0; i < 8; ++i)
    {
    board_hash.row[i] = 0;
    for(int j = 0; j < 8; ++j)
    {
    board_hash.row[i] |= game_board[j] << (j*2);
    }
    }
    return board_hash;
    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.