Tuesday, April 16, 2024
HomeSample Page

Sample Page Title


enter image description here
Playing the primary transfer in any of the blue spots will allow you to acquire 8 squares with additional optimum play, regardless of the pc does. On the opposite hand, taking part in in any of the purple spots will solely allow you to win 6 squares with additional optimum play.

Since there have been precisely 32 empty areas, I attempted to push the power of my pc and enumerate the very best transfer ranging from all $2^{32}$ states. For every state, the code finds the utmost variety of squares you will get greater than your opponent.

In a couple of minutes, the code discovered that the very best result’s -9. That is, no matter you do, you can not win the sport. Here is the code:

const lengthy lengthy lim=1ll<<32;
char finest[lim];
//finest[i] is the utmost variety of additional squares you may win greater than your opponent ranging from state i
//A state is represented by a 32-bit bitmask. Edge i (outlined beneath) has been already performed iff bit i is 1

int primary()
{
  //Number the empty positions from 0 to 31 from high to backside, breaking ties from left to proper
  //Every edge borders at most 2 containers, and due to the state of the board, there exist at most 2 different edges whose existence is critical to fill these containers
  //Essentially, Adding edge i ends in a field for you if match[i][0] and match[i][1] have been already crammed; and one other field for you if match[i][2] and match[i][3] have been already crammed
  //if match[][] is 32 it signifies that present edge is on the boundary of the field and there is just one neighbouring field
  int match[32][4]={
    { 5, 0,32,32},{ 6, 1,32,32},{ 7, 2,32,32},{ 4, 3,32,32},
    { 3, 4, 8, 4},{ 0, 5,10, 5},{ 1, 6,11, 6},{ 2, 7,12, 7},
    { 4, 8, 9, 8},{ 8, 9,13, 9},{ 5,10,14,17},{ 6,11,15,11},
    { 7,12,15,18},{ 9,13,16,20},{10,17,32,32},{11,15,12,18},
    {19,16,13,20},{10,14,21,22},{23,18,12,15},{16,19,23,19},
    {25,20,13,16},{17,22,32,32},{24,22,17,21},{18,23,19,23},
    {22,24,26,30},{20,25,28,25},{29,26,24,30},{28,27,31,27},
    {25,28,27,28},{26,29,32,32},{24,26,32,32},{27,31,32,32}
  };

  for(lengthy lengthy i=lim-2;i>=0;i--)
  {
    finest[i]=-25;
    for(int j=0;j<32;j++)
    {
      //If jth edge has already been performed, you can not play it at this transfer
      lengthy lengthy cur=(1ll)<<j;
      if((i&cur)!=0)proceed;

      //Check what number of containers are crammed by the present transfer
      lengthy lengthy masks=i^cur;
      int cnt=0;
      if((masks&(1ll<<match[j][0]))!=0 and (masks&(1ll<<match[j][1]))!=0)cnt++;
      if((masks&(1ll<<match[j][2]))!=0 and (masks&(1ll<<match[j][3]))!=0)cnt++;

      //If no containers have been crammed in present transfer, you move to opponent and they're going to do their finest transfer
      //If at the very least one field was crammed, it's important to make one other transfer
      char thismove;
      if(cnt==0)thismove=-best[mask];
      else thismove=cnt+finest[mask];

      //Does taking part in this edge do higher than any beforehand seen edges?
      if(thismove>finest[i])finest[i]=thismove;
    }
  }

  //Now allow us to contemplate the strikes from the empty board
  //Playing edge j, the very best you are able to do is -best[1ll<<j] since no field will likely be crammed instantly and the opponent will do their finest
  for(int j=0;j<32;j++)
  {
    lengthy lengthy masks=(1ll)<<j;
    char thismove=-best[mask];
    printf("%d %dn",j,(int)thismove);
  }
  printf("Best : %dn",(int)finest[0]);
  return 0;
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments