MarGolf와 Langton의 Anthill 만나기


9
This is Markov.
Markov's golf ball rolls around randomly.
Markov's ball will hole however he strikes it.
Markov is smart.
Be like Markov.

그리고 이것은 :
여기에 이미지 설명을 입력하십시오 Langton의 뒤뜰에있는 개미집입니다.
개미집은 Markov의 골프 공인 MarGolf를 담을 수있을만큼 큽니다. 그러나 개미 언덕은 주변 지형에 따라 움직이며 방향을 바꿉니다.

작업

10x20 필드를 입력하십시오.

  • * 마르 골프
  • O 랜턴의 개미집
  • , Anthill은 시계 방향으로 90도 회전
  • . Anthill은 시계 반대 방향으로 90도 회전
  • 0 랭턴의 개미집에서 MarGolf

필드는 다음과 같습니다.

,...,.,,..,...,.,,..
..,.,,,..,...,..,.,.
.,,*.,....,.,,,.,,,.
,.,,.,...,,.,.,,,,,.
.,..,....,,.....,,.,
,.,.,...,..,.,,,,..,
....,,,,,,,,,.......
........,,.,...,...,
,,,,,,,,,,,,....,O.,
,.,.,.,.....,,.,,,,,

게임 규칙 :
입력 필드의 구성을 틱 0이라고합니다. 프로그램은 다음 틱의 구성을 평가하고 인쇄해야합니다. 여기에서 MarGolf와 Langton의 Anthill이 다른 셀로 이동합니다. 현재 셀의 항목이 현재 대상 셀의 항목이됩니다. 다음 틱에서 MarGolf와 anthill이 동일한 셀로 이동하면 게임이 종료됩니다.

운동 규칙 :

  • MarGolf 가 무작위로 움직입니다. MarGolf 주변의 3x3 영역에있는 9 개의 셀이 모두 선택 될 가능성이 동일합니다. 이것은 필드 가장자리에있는 6 개의 셀과 모서리에있는 4 개의 셀 중에서 선택됩니다.
  • Langton의 Anthill 은 위, 아래, 왼쪽 또는 오른쪽 (NSEW 또는 이와 동등한 것)의 이동 방향을 기억해야합니다. 각 눈금마다 한 셀의 방향으로 이동하며 셀의 원래 내용은 위에서 지정한대로 시계 방향 또는 시계 반대 방향으로 방향을 변경합니다. 눈금 0의 초기 방향은 임의적이며 각 방향은 초기 일 가능성이 동일합니다.

노트

  • 프로그램은 게임이 끝날 때까지 각 진드기의 구성을 인쇄해야합니다.
  • 틱 번호는 각 틱의 필드 구성보다 우선합니다.
  • 입력이 항상 유효하다고 가정 할 수 있습니다.
  • 가장 짧은 프로그램은 바이트 수입니다.

업데이트 : 달리지 않는 경우 개미 집이 이동하기 전에 방향을 반대로 바꾸는 것을 잊어 버렸습니다. 상기시켜 주신 user81655에게 감사드립니다.


"여기에 <삽입 이름 입력> meme"이 (가) 유래 된 장소를 지적 할 수있는 사람이 있습니까?
자랑스러운 하스 켈러

@proudhaskeller Be Like Bill 페이스 북 페이지에는 Wikipedia에 관한 기사가 있습니다. en.wikipedia.org/wiki/Be_like_Bill
busukxuan


2
@Doorknob 도전을 올바르게 이해하면 그 아래에 타일이 없습니다. 그중 하나를 이동하면 이동하는 타일과 교체되고 해당 타일 O다음 단계 의 방향을 결정합니다 .
Martin Ender

1
@MartinButtner 예, 대부분 맞습니다. 한 구석 사례에 대해 "스왑"이라는 용어를 사용하지 않았지만 그 용어는 그렇지 않습니다.
busukxuan

답변:


3

자바 10, 611 609 607 593 591 바이트

m->{int x=0,y=0,X=0,Y=0,r=10,c,d=4,e;for(d*=Math.random();r-->0;)for(c=20;c-->0;){if(m[r][c]<43){x=r;y=c;}if(m[r][c]>48){X=r;Y=c;}}for(;;d=m[r][c]<45?d<2?d+2:d<3?1:0:d>1?d-2:d>0?2:3){p(m);for(e=4;e==4;e*=Math.random())e=9;m[r=x][c=y]=m[x+=e/3<1?x>0?-1:1:e/3>1?x<9?1:-1:0][y+=e%3<1?y>0?-1:1:e%3>1?y<19?1:-1:0];if(m[x][y]>48){m[x][y]=48;m[r][c]=0;p(m);e/=0;}m[x][y]=42;m[r=X][c=Y]=m[X+=d<1?X<9?1:-1:d==1?X>0?-1:1:0][Y+=d==2?Y<19?1:-1:d>2?Y>0?-1:1:0];if(m[X][Y]<43){m[r][c]=48;m[X][Y]=0;p(m);e/=0;}m[X][Y]=79;}}void p(char[][]m){var p="";for(var a:m)p+=p.valueOf(a)+"\n";System.out.println(p);}

@ceilingcat 덕분에 -4 바이트 .

의 최종 스왑을 가정 *하고 O셀 비어 것이다 *에서 오는됩니다.

설명:

온라인으로 사용해보십시오.

m->{                        // Method with character-matrix parameter and no return-type
  int x=0,y=0,              //  [x,y] coordinates of MarGolf
      X=0,Y=0,              //  [X,Y] coordinates of Langton's Anthill
      r=10,c,               //  Temp [x,y] coordinates
      d=4,                  //  Direction Langton's Anthill
      e;                    //  Direction MarGolf
  for(d*=Math.random();     //  Set the direction Langton's Anthill randomly [0,3]
      r-->0;)               //  Loop over the rows:
    for(c=20;c-->0;){       //   Inner loop over the columns:
      if(m[r][c]<43){       //    If '*' is found:
        x=r;y=c;}           //     Set MarGolf's [x,y] coordinates
      if(m[r][c]>48){       //    If 'O' is found:
        X=r;Y=c;}}          //     Set Langton's Anthill's [X,Y] coordinates
  for(;                     //  Loop indefinitely:
       ;                    //    After every iteration:
        d=                  //     Change the direction of Langton's Anthill:
          m[r][c]<45?       //      If the swapped cell contained a comma:
           d<2?d+2:d<3?1:0  //       Change the direction clockwise
          :                 //      Else (the swapped cell contained a dot):
           d>1?d-2:d>0?2:3){//       Change the direction counterclockwise
  p(m);                     //  Pretty-print the matrix
  for(e=4;e==4;e*=Math.random())e=9;
                            //  Change direction MarGolf randomly [0-9] (excluding 4)
  m[r=x][c=y]               //  Save the current MarGolf coordinates
   =m[x+=e/3<1?x>0?-1:1:e/3>1?x<9?1:-1:0]
     [y+=e%3<1?y>0?-1:1:e%3>1?y<19?1:-1:0];
                            //  And change that cell to the content in direction `e`
                            //  0 to 9 (excl. 4) is NW,N,NE,W,n/a,E,SW,S,SE respectively
                            //  If `e` would go out of bounds, it moves opposite instead
  if(m[x][y]>48){           //  If MarGolf reached Langton's Anthill:
    m[x][y]=48;             //   Set that cell to '0'
    m[r][c]=0;              //   And empty the swapped cell
    p(m);                   //   Print the final status of the matrix
    e/=0;}                  //   And stop the loop with an error to exit the program
  m[x][y]=42;               //  Change the cell in the new coordinate to '*'
  m[r=X][c=Y]               //  Save the current Langton's Anthill coordinates
   =m[X+=d<1?X<9?1:-1:d==1?X>0?-1:1:0]
      [Y+=d==2?Y<19?1:-1:d>2?Y>0?-1:1:0];
                            //  And change that cell to the content in direction `d`
                            //  0 to 3 is E,W,S,N respectively
                            //  If `d` would be out of bounds, it moves opposite instead
  if(m[X][Y]<43){           //  If MarGolf reached Langton's Anthill:
    m[r][c]=48;             //   Set that cell to '0'
    m[X][Y]=0;              //   And empty the swapped cell
    p(m);                   //   Print the final status of the matrix
    e/=0;}                  //   And stop the loop with an error to exit the method
  m[X][Y]=79;}}             //  Change the cell in the new coordinate to 'O'

void p(char[][]m){          // Separated method to print the given matrix
  var p="";                 //  String to print, starting empty
  for(var a:m){             //  Loop over the rows:
    p+=p.valueOf(a)         //   Convert the character-array to a String line and append,
                     +"\n"; //   including a trailing newline
  System.out.println(p);}   //  Print the String with trailing newline as separator
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.