MarGolf ตรงตาม Anthill ของ Langton


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.

และนี่
ป้อนคำอธิบายรูปภาพที่นี่ คือมดในสนามหลังบ้านของแลงตัน
เขากวางใหญ่พอที่จะถือ MarGolf ลูกกอล์ฟของมาร์คอฟ อย่างไรก็ตามเสาอากาศจะเคลื่อนที่และเปลี่ยนทิศทางขึ้นอยู่กับภูมิประเทศโดยรอบ

งาน

ใช้อินพุตของฟิลด์ 10x20:

  • * MarGolf
  • O Lanton Anthill
  • , Anthill หมุน 90 องศาตามเข็มนาฬิกา
  • . Anthill หมุน 90 องศาทวนเข็มนาฬิกา
  • 0 MarGolf ใน Anthill ของ Langton

ฟิลด์มีลักษณะดังนี้:

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

กฎของเกม:
การกำหนดค่าของฟิลด์อินพุตเรียกว่าขีด จำกัด โปรแกรมของคุณต้องประเมินและพิมพ์การกำหนดค่าของเห็บถัดไปซึ่งทั้ง MarGolf และ Langton's Anthill จะย้ายไปที่เซลล์อื่น รายการในเซลล์ปัจจุบันจะกลายเป็นรายการที่อยู่ในเซลล์เป้าหมาย หากทั้ง MarGolf และ anthill ย้ายไปที่เซลล์เดียวกันในเห็บต่อไปเกมจะจบลง

กฎการเคลื่อนไหว:

  • MarGolfเคลื่อนไหวแบบสุ่ม เซลล์ทั้งเก้าในพื้นที่ 3x3 รอบ MarGolf มีโอกาสเท่ากันในการเลือก สิ่งนี้จะกลายเป็นตัวเลือกระหว่าง 6 เซลล์ที่ขอบสนามและ 4 เซลล์ที่มุมหนึ่ง
  • Anthill ของ Langtonจำเป็นต้องจดจำทิศทางการเคลื่อนไหวของมันไม่ว่าจะขึ้น, ลง, ซ้ายหรือขวา (NSEW หรืออะไรก็ตามที่เทียบเท่า) มันเลื่อนเซลล์หนึ่งไปในทิศทางของแต่ละเห็บและเนื้อหาต้นฉบับของเซลล์จะเปลี่ยนทิศทางตามเข็มนาฬิกาหรือทวนเข็มนาฬิกาตามที่ระบุข้างต้น ทิศทางเริ่มต้นที่ขีด 0 เป็นแบบสุ่มแต่ละทิศทางมีโอกาสเท่ากันในการเริ่มต้น

หมายเหตุ

  • โปรแกรมจำเป็นต้องพิมพ์การกำหนดค่าของแต่ละเห็บจนกว่าเกมจะจบลง
  • หมายเลขติ๊กนำหน้าการกำหนดค่าฟิลด์ของแต่ละติ๊ก
  • คุณอาจสันนิษฐานว่าอินพุตนั้นถูกต้องเสมอ
  • โปรแกรมที่สั้นที่สุดคือจำนวนไบต์ที่ชนะ

อัปเดต:ลืมที่จะพูดถึง anthill ย้อนทิศทางก่อนที่จะย้ายถ้ามิฉะนั้นมันจะออกไปจากสนาม เพิ่มเครดิตให้กับ user81655 เพื่อเตือนความจำ


ทุกคนสามารถชี้ที่ "เป็นเหมือน <ชื่อแทรกที่นี่> มส์เกิดขึ้นได้ไหม?
ภูมิใจ haskeller

@proudhaskeller ฉันเดาจากหน้า Facebook ของ Be Like Bill มีบทความเกี่ยวกับ Wikipedia ที่คุณอาจต้องการอ่าน en.wikipedia.org/wiki/Be_like_Bill
busukxuan


2
@Doorknob ถ้าฉันเข้าใจความท้าทายอย่างถูกต้องจะไม่มีไทล์อยู่ข้างใต้ เมื่อคุณย้ายหนึ่งในนั้นจะสลับกับไทล์ที่พวกเขาย้ายไปและไทล์นั้นกำหนดOทิศทาง s สำหรับขั้นตอนถัดไป
Martin Ender

1
@MartinButtner ใช่ว่าถูกต้องที่สุด ฉันหลีกเลี่ยงคำว่า "swap" สำหรับกรณีหนึ่งมุม แต่คำนั้นเป็นความจริง
busukxuan

คำตอบ:


3

Java 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);}

-4 ไบต์ขอบคุณที่@ceilingcat

ถือว่าสลับสุดท้ายของ*และ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.