रॉक, पेपर, कैंची, छिपकली, स्पॉक टूर्नामेंट


13

4 मई के बाद स्टार ट्रेक के संदर्भ को शामिल करते हुए एक चुनौती दी जा सकती है, लेकिन यहाँ जाता है।

आप, ल्यूक, अनाकिन, पलपेटीन, योदा और हान सोलो रॉक, पेपर, कैंची, छिपकली, स्पॉक के एक पागल टूर्नामेंट में शामिल हैं।

यहां पकड़ यह है कि आपको केवल चालों के एक निश्चित क्रम का उपयोग करने की अनुमति है। यदि आपका आदेश "आर" है, तो आपको रॉक का उपयोग करना होगा, जब तक कि आप सभी के खिलाफ हार या जीत नहीं लेते। यदि आपका ऑर्डर RRV है, तो आपको 2 Rocks का उपयोग एक Spock द्वारा करना होगा और तब तक दोहराते रहना चाहिए जब तक आप जीत या हार नहीं जाते।

ल्यूक, अनाकिन, पलपेटाइन, योडा और हान सोलो ने अपने संबंधित आदेश प्रस्तुत किए हैं और आप एक विशेषज्ञ हैकर के रूप में उनके प्रत्येक आदेश पर अपना हाथ मिला रहे हैं!

इस ज्ञान के साथ, आपको टूर्नामेंट के लिए अपना ऑर्डर डिजाइन करना है। चूंकि हर कोई जीतना चाहता है, आप एक ऐसा ऑर्डर बनाना चाहते हैं कि आप सभी को हराकर टूर्नामेंट जीतें। लेकिन यह सभी परिस्थितियों में संभव नहीं हो सकता है।

सुनिश्चित करें कि एक संभावित जीत क्रम है, इसे प्रिंट करें। यदि आपके पास जीतने का कोई संभावित तरीका नहीं है, तो प्रिंट आउट -1 (या 0 या गलत या "असंभव"

इनपुट : 5 आदेशों की एक सूची

आउटपुट : एक एकल आदेश या -1

नमूना इनपुट 1

R
P
S
L
V

नमूना आउटपुट 1

-1

व्याख्या १

कोई फर्क नहीं पड़ता कि आप अपनी पहली चाल में खेलते हैं, कम से कम एक व्यक्ति होगा जो आपको मारता है, इसलिए आपके लिए जीतना संभव नहीं है।

नमूना इनपुट 2

RPS
RPP
R
SRR
L

नमूना आउटपुट 2

RPSP

व्याख्या २

एक बार जब आप अपनी पहली चाल में रॉक खेलते हैं, तो आप "L" और "SRR" को समाप्त करते हैं और बाकी के खिलाफ टाई करते हैं। ऐसा इसलिए है क्योंकि छिपकली और कैंची रॉक से हार जाते हैं। जब आप आगे पेपर खेलते हैं, तो आप "आर" को हरा देंगे और शेष 2 के खिलाफ टाई करेंगे। ऐसा इसलिए है क्योंकि रॉक पेपर को खो देता है। जब आप आगे कैंची चलाते हैं, तो आप "RPP" के खिलाफ जीतेंगे क्योंकि कैंची बीट पेपर है।

अंत में, आप अपने पेपर के साथ "आरपीएस" को हरा देंगे क्योंकि पेपर बीट रॉक है।

यहां नोटिफिकेशन की सूची दी गई है (आप किसी भी 5 लीटर का उपयोग कर सकते हैं, लेकिन कृपया अपने उत्तर में निर्दिष्ट करें):

R : Rock
P : Paper
S : Scissor
L : Lizard
V : Spock

यहां सभी संभावित परिणामों की एक सूची दी गई है:

winner('S', 'P') -> 'S'
winner('S', 'R') -> 'R'
winner('S', 'V') -> 'V'
winner('S', 'L') -> 'S'
winner('S', 'S') -> Tie
winner('P', 'R') -> 'P'
winner('P', 'V') -> 'P'
winner('P', 'L') -> 'L'
winner('P', 'S') -> 'S'
winner('P', 'P') -> Tie
winner('R', 'V') -> 'V'
winner('R', 'L') -> 'R'
winner('R', 'S') -> 'R'
winner('R', 'P') -> 'P'
winner('R', 'R') -> Tie
winner('L', 'R') -> 'R'
winner('L', 'V') -> 'L'
winner('L', 'S') -> 'S'
winner('L', 'P') -> 'L'
winner('L', 'L') -> Tie
winner('V', 'R') -> 'V'
winner('V', 'L') -> 'L'
winner('V', 'S') -> 'V'
winner('V', 'P') -> 'P'
winner('V', 'V') -> Tie

यह , इसलिए सबसे कम बाइट जीतते हैं।

पुनश्च: मुझे पता है अगर आप और अधिक परीक्षण मामलों की जरूरत है।


4
कृपया "स्टार ट्रेक " को अपने परिचय में "स्टार वार्स " में बदल दें;)
मूवीटिका

1
यह काफी कठिन समस्या है। खैर, या मैं इस तरह की प्रोग्रामिंग में बुरा हूं।
क्रैबमैन

@ क्रैबमैन यह एक कठिन समस्या है गोल्फ के लिए। विशेष रूप से व्यावहारिक भाषाओं में।
कोइशोर रॉय

1
कई काम करता है, लेकिन सिद्धांत अनंत जीतने की रणनीति में हैं, इसलिए ध्यान रखें कि
कोश्योर रॉय

1
संबंधित , और एक KOTH (cc: @Arnauld)
DLosc

जवाबों:


2

जेली , 29 बाइट्स

_%5ḟ0ḢḂ¬
ṁ€ZLḤƊçþ`Ạ€Tị;‘%5Ɗ$€

एक मोनडिक लिंक जो पूर्णांकों की सूचियों की एक सूची को स्वीकार करता है (जिनमें से प्रत्येक एक प्रतिद्वंद्वी की रणनीति है) जो पूर्णांकों की सूचियों की सूची तैयार करता है - जिनमें से प्रत्येक एक जीतने की रणनीति है (इसलिए यदि कोई संभव नहीं है तो एक खाली सूची)।
( केवल एक एकल रणनीति सूची या 0यदि असंभव हो तो जोड़ें)

इसे ऑनलाइन आज़माएं! (हमेशा सूची दिखाने के लिए पाद प्रारूप)

Rock  Paper  Scissors  Spock  Lizard
0     1      2         3      4

या एक पत्र मैप किए गए संस्करण का प्रयास करें (जहां रणनीतियों को लिया गया है और RPSVLअंकन का उपयोग करके अपनी खुद की लाइनों पर दिखाया गया है)।

कैसे?

संख्याओं को इस तरह चुना जाता है कि कोई भी एक अन्य मोडुलो फाइव जीत की तुलना में एक विषम संख्या होती है (यानी उन्हें फेंके गए शिलालेख के किनारे पर घूमने के लिए गिना जाता है)।

कोड हर रणनीति के खिलाफ प्रत्येक रणनीति (खुद सहित) के लिए दो बार सबसे लंबी रणनीति के रूप में फेंकता है ताकि किसी भी हारे हुए लोगों को खोजने के लिए सुनिश्चित किया जा सके जो हार नहीं रहे हैं। रणनीतियों की परिणामी सूची में एक एकल रणनीति शामिल होगी यदि एकमुश्त विजेता हो; विजेता नहीं होने पर कोई रणनीति नहीं; या कई रणनीति अगर वहाँ ड्राइंग खिलाड़ी हैं। इसके बाद इनमें से प्रत्येक रणनीति के लिए चालों का एक विजयी सेट जोड़ा जाता है।

_%5ḟ0ḢḂ¬ - Link 1, does B survive?: list A, list B (A & B of equal lengths)
                              e.g. RPSR vs RPVL ->  [0,1,2,0], [0,1,3,4]
_        - subtract (vectorises)                    [0,0,-1,-4]
 %5      - modulo five (vectorises)                 [0,0,4,1]   ...if all zeros:
   ḟ0    - filter discard zeros (ties)              [4,1]                       []
     Ḣ   - head (zero if an empty list)             4                           0
      Ḃ  - modulo two                               0                           0
       ¬ - logical NOT                              1                           1

ṁ€ZLḤƊçþ`Ạ€Tị;‘%5Ɗ$€ - Main Link: list of lists of integers
ṁ€                   - mould each list like:
     Ɗ               -   last three links as a monad
  Z                  -     transpose
   L                 -     length
    Ḥ                -     double  (i.e. 2 * throws in longest strategy)
        `            - use left as both arguments of:
       þ             -   table using:
      ç              -     last Link (1) as a dyad
         Ạ€          - all for each (1 if survives against all others, else 0)
           T         - truthy indices
            ị        - index into the input strategies
                  $€ - last two links as a monad for each:
             ;       -   concatenate with:
                 Ɗ   -     last three links as a monad:
              ‘      -       increment (vectorises)
               %5    -       modulo five (vectorises)

मैं जेली के लिए पूरी तरह से नया हूँ, लेकिन ऐसा लगता है कि आप को बदल कर एक बाइट प्राप्त कर सकते हैं ZLḤद्वारा
रॉबिन राइडर

@RobinRyder काम नहीं करेगा - यह केवल उदाहरण डेटा के साथ काम कर रहा है क्योंकि इसमें पर्याप्त प्रतिद्वंद्वी और कुछ पर्याप्त थ्रो हैं - यह एक ऐसा उदाहरण है जो काम नहीं करेगा । हमें सबसे लंबी प्रतिद्वंद्वी रणनीति के रूप में दो बार विश्लेषण करने की आवश्यकता है। (आपका कोड वास्तव में के बराबर है इस )
जोनाथन एलन

... वास्तव Ɗमें आपके कोड की कार्रवाई के कारण यह वह भी नहीं कर रहा है जो आपने सोचा हो सकता है - यह प्रत्येक की तरह ढल रहा है जैसे कि यह अपनी लंबाई है फिर उन परिणामों के संचयी रकम प्राप्त कर रहा है, इसलिए गलत मानों की भी तुलना करेगा। उदाहरण के लिए इसे आज़माएँ - यह [[1,2,3,4,5],[6,7],[8]]पूरी सूची (3) की लंबाई से प्रत्येक को ढालता है, [[1,2,3],[6,7,6],[8,8,8]]फिर पाने के लिए संचय करता है [[1,1+2,1+2+3],[6,6+7,6+7+8],[8,8+8,8+8+8]]= पाने के लिए [[1,3,6],[6,13,19],[8,16,24]]
जोनाथन एलन

आह हाँ, मुझे पता था कि मैं कुछ गलत समझ रहा था!
रॉबिन राइडर

7

जावास्क्रिप्ट (ईएस 6),  122 115  112 बाइट्स

अंकों के तारों के एक सरणी के रूप में इनपुट लेता है:

  • 0 = कैंची (एस)
  • 1 = पेपर (P)
  • 2 = रॉक (आर)
  • 3 = छिपकली (एल)
  • 4 = स्पॉक (वी)

समाधान नहीं होने पर या तो एक ही प्रारूप में एक स्ट्रिंग या ।false

f=(a,m='',x=0,o,b=a.filter(a=>(y=a[m.length%a.length])-x?o|=y-x&1^x<y:1))=>b+b?x<4&&f(a,m,x+1)||!o&&f(b,m+x):m+x

इसे ऑनलाइन आज़माएं!

कैसे?

यह एक चौड़ाई-पहली खोज है: हम पहले दिए गए कदम पर सभी को देखने की कोशिश करते हैं कि क्या हम खेल जीत सकते हैं। यदि हम अभी जीत नहीं सकते हैं, तो हम प्रत्येक गैर-खोने वाले कदम में एक और कदम जोड़ने की कोशिश करते हैं।

चाल पहचानकर्ताओं को इस तरह से चुना गया था कि एक चाल खिलाफ एक चाल जीतती है अगर और केवल अगर विषम है।A ( B - A ) mod 5B(BA)mod5

साथ को छोड़ दिया और पर शीर्ष पर:AB

(S)(P)(R)(L)(V)01234(S) 01234(P) 14123(R) 23412(L) 32341(V) 41234

वहाँ से, हम जांच करना है कि का एक और तरीका यह मान सकते हैं के खिलाफ जीत के लिए :ABAB

((A - B) and 1) xor (B < A)

कहाँ andऔर xorबिटवाइज़ ऑपरेटर हैं।

टिप्पणी की गई

f = (                        // f is a recursive function taking:
  a,                         //   a[] = input
  m = '',                    //   m   = string representing the list of moves
  x = 0,                     //   x   = next move to try (0 to 4)
  o,                         //   o   = flag set if we lose, initially undefined
  b =                        //   b[] = array of remaining opponents after the move x
    a.filter(s =>            //     for each entry s in a[]:
    ( y =                    //       define y as ...
      s[m.length % s.length] //         ... the next move of the current opponent
    ) - x                    //       subtract x from y
    ?                        //       if the difference is not equal to 0:
      o |=                   //         update o using the formula described above:
        y - x & 1 ^ x < y    //           set it to 1 if we lose; opponents are removed
                             //           while o = 0, and kept as soon as o = 1
    :                        //       else (this is a draw):
      1                      //         keep this opponent, but leave o unchanged
  )                          //     end of filter()
) =>                         //
  b + b ?                    // if b[] is not empty:
    x < 4 &&                 //   if x is less than 4:
      f(a, m, x + 1)         //     do a recursive call with x + 1 (going breadth-first)
    ||                       //   if this fails:
      !o &&                  //     if o is not set:
        f(b, m + x)          //       keep this move and do a recursive call with b[]
  :                          // else (success):
    m + x                    //   return m + x

आपका कोड परीक्षण के मामले में विफल रहता है: test(['P','P','S','P','P']) उत्तर "एसआर" या "एसवी" होना चाहिए।
किशोर रॉय

@KoishoreRoy अब तय किया गया।
अरनौलद

1
यह वास्तव में एक शानदार दृष्टिकोण है। मैंने इसे एक ग्राफ के रूप में विचार करने के बारे में सोचा भी नहीं था। मैं अपने अनगुल्ड मूल दृष्टिकोण (बिना स्पोक या छिपकली के) में शब्दकोशों और रिवर्स लुक-अप का उपयोग कर रहा था
कोइशोर रॉय

3

आर , 213 190 बाइट्स

-23 बाइट्स ग्यूसेप के लिए धन्यवाद।

function(L){m=matrix(rep(0:2,1:3),5,5)
m[1,4]=m[2,5]=1
v=combn(rep(1:5,n),n<-sum(lengths(L)))
v[,which(apply(v,2,function(z)all(sapply(L,function(x,y,r=m[cbind(x,y)])r[r>0][1]<2,z)))>0)[1]]}

इसे ऑनलाइन आज़माएं!

यदि कोई समाधान मौजूद है, तो वह एक आउटपुट करता है। यदि कोई समाधान नहीं है, तो यह एक पंक्ति को आउटपुट करता है NA। यदि यह आउटपुट प्रारूप स्वीकार्य नहीं है, तो मैं इसे कुछ बाइट्स की कीमत पर बदल सकता हूं।

मूव्स को 1 = R, 2 = S, 3 = P, 4 = L, 5 = V के रूप में कोडित किया जाता है, ताकि परिणाम का मैट्रिक्स हो

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    2    2    1    1
[2,]    1    0    2    2    1
[3,]    1    1    0    2    2
[4,]    2    1    1    0    2
[5,]    2    2    1    1    0

(0 = कोई विजेता नहीं; 1 = खिलाड़ी 1 जीत; 2 = खिलाड़ी 2 जीत)

यदि मौजूद है तो समाधान की लंबाई पर एक ऊपरी बाध्य है, n=sum(lengths(L))जहां Lविरोधियों की चाल की सूची है। कोड लंबाई की सभी संभावित रणनीतियों n(मैट्रिक्स में संग्रहीत v) बनाता है, उन सभी को आज़माता है, और सभी जीतने वाली रणनीतियों को प्रदर्शित करता है।

ध्यान दें कि यह मान nTIO पर कोड को बहुत धीमा करता है, इसलिए मैंने TIO में हार्डकोड किया है n=4जो परीक्षण के मामलों के लिए पर्याप्त है।

पहले परीक्षण मामले के लिए, आउटपुट है

     1 4 2 4

समाधान के लिए इसी RLSL।

दूसरे परीक्षण मामले के लिए, आउटपुट है

 NA NA NA NA

जिसका अर्थ है कि कोई समाधान नहीं है।

पिछले संस्करण की व्याख्या (अद्यतन जब मैं कर सकता हूँ):

function(L){
  m = matrix(rep(0:2,1:3),5,5);
  m[1,4]=m[2,5]=1                      # create matrix of outcomes
  v=as.matrix(expand.grid(replicate(   # all possible strategies of length n
    n<-sum(lengths(L))                 # where n is the upper bound on solution length
    ,1:5,F)))             
  v[which(    
    apply(v,1,                         # for each strategy
          function(z)                  # check whether it wins
            all(                       # against all opponents
              sapply(L,function(x,y){  # function to simulate one game
                r=m[cbind(x,y)];       # vector of pair-wise outcomes
                r[r>0][1]<2            # keep the first non-draw outcome, and verify that it is a win
              }
              ,z)))
    >0),]                              # keep only winning strategies
}

whichNAS जो होते हैं, जब दो खिलाड़ियों को हमेशा के लिए आकर्षित से छुटकारा पाने के लिए आवश्यक है।

मुझे यकीन नहीं है कि यह सबसे कुशल रणनीति है। यहां तक ​​कि अगर यह है, मुझे यकीन है कि कोड के लिए mकाफी थोड़ा गोल्फ हो सकता है।


lengths()हमेशा वापस आने के लिए सचेत क्यों किया जाता है 4?
Giuseppe

1
वैसे भी, जब मैं आपकी प्रतिक्रिया की प्रतीक्षा कर रहा हूं, मैंने इसे 197 तक नीचे कर दिया , ज्यादातर पर ध्यान केंद्रित करके v...
Giuseppe

@Giuseppe मैंने टीआईओ पर lengthsबल देने का उपनाम दिया है n=4, क्योंकि अन्यथा सभी ( ) रणनीतियों पर जाने के लिए बहुत लंबा समय लगता है । एन = 115nn=11
रॉबिन राइडर

आह, समझ में आता है, पता होना चाहिए था। 187 बाइट्स
ग्यूसेप

@Giuseppe धन्यवाद, प्रभावशाली गोल्फ! मैंने आउटपुट को अधिक पठनीय बनाने के लिए 3 बाइट्स जोड़े (अन्यथा हम एक ही समाधान के साथ कई बार मुद्रित होते हैं)।
रॉबिन राइडर

0

एमएसीएस लिस्प, 730 बाइट्स

(require 'cl-extra)
(require 'seq)
(defun N (g) (length (nth 1 g)))
(defun M (g) (mapcar (lambda (o) (nth (% (N g) (length o)) o)) (car g)))
(defun B (x y) (or (eq (% (1+ x) 5) y) (eq (% (+ y 2) 5) x)))
(defun S (g) (seq-filter (lambda (m) (not (seq-some (lambda (v) (B v m)) (M g)))) '(0 1 2 3 4)))
(defun F (g) (cond ((null (car g)) (reverse (nth 1 g))) ((null (S g)) nil) ((>= (nth 3 g) (seq-reduce (lambda (x y) (calc-eval "lcm($,$$)" 'raw x y)) (mapcar 'length (car g)) 1)) nil) (t (cl-some (lambda (m) (F   (let ((r (seq-filter 'identity (mapcar* (lambda (v o) (and (not (B m v)) o)) (M g) (car g))))) (list r (cons m (nth 1 g)) (1+ (N g)) (if (eq (car g) r) (1+ (nth 3 g)) 0))))) (S g)))))
(defun Z (s) (F (list s () 0 0)))

मुझे Emacs Lisp का एक ऑनलाइन दुभाषिया नहीं मिला :( यदि आपके पास Emacs स्थापित हैं, तो आप कोड को एक .elफ़ाइल में कॉपी कर सकते हैं , नीचे कुछ परीक्षण लाइनें कॉपी कर सकते हैं

;; 0 = rock, 1 = lizard; 2 = spock;
;; 3 = scissors; 4 = paper
(print (Z '((0) (1) (2) (3) (4))))
; output: nil
(print (Z '((0) (4) (3) (1))))
; output: nil
(print (Z '((0 4 3) (0 4 4) (0) (3 0 0) (1))))
; output: (0 4 3 0 1)
(print (Z '((4) (4) (3) (4) (4))))
; output: (3 0)
(print (Z '((4 3 2 1 0) (2 1 0 4 3))))
; output: (1)
(print (Z '((2) (2) (3) (0) (2) (3) (0) (0))))
; output: (2 1)
(print (Z '((2) (2 0) (3) (0) (2 1) (3) (0) (0))))
; output: nil

और इसे चलाओ $ emacs --script filename.el

यह काम किस प्रकार करता है

मेरा कार्यक्रम कभी-कभी यह पता लगाने के साथ गहराई से खोज करता है कि उस शाखा को जीतना और उसे समाप्त करना असंभव है।

आप कोड के unshortened संस्करण में पूर्ण विवरण देख सकते हैं:

(require 'seq)
(require 'cl-extra)

;; This program does depth first search with sometimes figuring out
;; that it's impossible to win and terminating the branch it's on.
;;

;; A move is a number from 0 to 4. 
;; https://d3qdvvkm3r2z1i.cloudfront.net/media/catalog/product/cache/1/image/1800x/6b9ffbf72458f4fd2d3cb995d92e8889/r/o/rockpaperscissorslizardspock_newthumb.png
;; this is a nice visualization of what beats what.
;; Rock = 0, lizard = 1, spock = 2, scissors = 3, paper = 4.

(defun beats (x y) "Calculates whether move x beats move y"
  (or (eq (% (1+ x) 5) y)
      (eq (% (+ y 2) 5) x)))

;; A gamestate is a list with the following elements:
(defun get-orders (gamestate)
  "A list of orders of players who haven't lost yet. Each order is a list of moves.
For example, ((2) (2 0) (3) (0) (2 1) (3) (0) (0)) is a valid orders list.
This function gets orders from the gamestate."
  (car gamestate))

;; At index 1 of the gamestate lies a list of all moves we have made so far in reverse order
;; (because lists are singly linked, we can't push back quickly)
(defun get-num-moves-done (gamestate)
  "Returns the number of moves the player has done so far"
  (length (nth 1 gamestate)))

(defun get-rounds-since-last-elim (gamestate)
  "The last element of a gamestate is the number of rounds passed since an opponent
was eliminated. We use this to determine if it's possible to win from current
gamestate (more about it later)."
  (nth 2 gamestate))

;; next go some utility functions
;; you can skip their descriptions, they are not very interesting
;; I suggest you skip until the next ;; comment

(defun get-next-move (order num-rounds-done)
  "Arguments: an order (e.g. (1 0 1)); how many rounds have passed total.
Returns the move this opponent will make next"
  (nth (% num-rounds-done (length order)) order))

(defun moves-of-opponents-this-round (gamestate)
  "Returns a list of moves the opponents will make next"
  (mapcar (lambda (order) (get-next-move order (get-num-moves-done gamestate)))
          (get-orders gamestate)))

(defun is-non-losing (move opponents-moves)
  "Calculates if we lose right away by playing move against opponents-moves"
  (not (seq-some (lambda (opponent-move) (beats opponent-move move))
                 opponents-moves)))

(defun non-losing-moves (gamestate)
  "Returns a list of moves which we can play without losing right away."
  (seq-filter
   (lambda (move) (is-non-losing move (moves-of-opponents-this-round gamestate)))
   '(0 1 2 3 4)))

(defun advance-gamestate (gamestate move)
  "If this move in this gamestate is non-losing, returns the next game state"
  (let ((new-orders (seq-filter
                    'identity (mapcar* (lambda (opp-move order)
                                         (and (not (beats move opp-move)) order))
                                       (moves-of-opponents-this-round gamestate)
                                       (get-orders gamestate)))))
  (list new-orders
        (cons move (nth 1 gamestate))
        (if (eq (get-orders gamestate) new-orders) (1+ (get-rounds-since-last-elim gamestate)) 0))))

;; How do we prevent our depth first search from continuing without halting?
;; Suppose 3 players (except us) are still in the game and they have orders of lengths a, b, c
;; In this situation, if least_common_multiple(a, b, c) rounds pass without an elimination
;; we will be in the same situation (because they will be playing the same moves they played
;; lcm(a, b, c) rounds ago)
;; Therefore, if it's possible to win from this gamestate,
;; then it's possible to win from that earlier game state,
;; hence we can stop exploring this branch

(defun get-cycle-len (gamestate)
  "Returns a number of rounds which is enough for the situation to become the same
if the game goes this long without an elimination."
  (seq-reduce (lambda (x y) (calc-eval "lcm($,$$)" 'raw x y))
              (mapcar 'length (get-orders gamestate)) 1))

(defun unwinnable-cycle (gamestate)
  "Using the aforementioned information, returns t if we are in such a
suboptimal course of play."
  (>= (get-rounds-since-last-elim gamestate) (get-cycle-len gamestate)))

(defun find-good-moves (gamestate)
  "Given gamestate, if it's possible to win
returns a list of moves, containing all moves already done + additional moves which lead to win.
Otherwise returns nil"
  (cond ((null (get-orders gamestate)) ; if no opponents left, we won, return the list of moves
         (reverse (nth 1 gamestate)))
        ((null (non-losing-moves gamestate)) ; if no non-losing moves available, this gamestate
         nil) ; doesn't lead to a win, return nil
        ((unwinnable-cycle gamestate) ; either it's impossible to win, or
         nil) ; it's possible to win from an earlier position, return nil
        (t (cl-some (lambda (move) ; otherwise return the first non-losing move which leads
                      (find-good-moves (advance-gamestate gamestate move))) ; to a non-nil result
                    (non-losing-moves gamestate)))))

(defun make-initial-gamestate (orders)
  "Given an orders list, create initial gamestate"
  (list orders () 0))

1
tio.run/##S81NTC7WzcksLvgPBAA क्या आप यहां अपना कोड डाल सकते हैं और इसे चलाने का प्रयास कर सकते हैं?
कोइशोर रॉय

@KoishoreRoy मैंने tio.run की कोशिश की थी और मैं यह नहीं पता लगा सका कि यह क्यों नहीं चलता है। यह कहता है "अनुगामी कचरा निम्नलिखित अभिव्यक्ति" और मुझे नहीं पता कि क्या है और 5 मिनट की गुगली ने मुझे इसे ठीक करने में मदद नहीं की।
क्रैबमैन
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.