2010-02-16 12 views
5

में मैं पुनरावृत्ति अल्फा-बीटा prunning, का उपयोग कर टिक टैक पैर की अंगुली खेलने के लिए कोशिश कर रहा हूँ मैं एक चाल के लिए एक दूसरे की सीमा है, लेकिन यह does not को अच्छी तरह से काम किसी कारण से।टिक टैक पैर की अंगुली अल्फा का उपयोग कर बीटा prunning जावा

मैं नियमित रूप से अल्फा बीटा कोड तो बजाय अल्फा या बीटा लौटने संशोधित, यह एक राज्य रिटर्न

हर बार जब मैं मैं उनकी गहराई को अद्यतन बच्चों बनाने (जो अगली चाल के साथ बोर्ड है)।

लेकिन फिर से किसी कारण से मैं हार रहा हूं और मुझे लगता है कि मेरा अल्फा बीटा बनाने के लिए सबसे अच्छा कदम नहीं देखता है।

बाहरी पाश:

while (watch.get_ElapsedMilliseconds() < 900 && d <= board.length * board[0].length - 1) 
     { 
      s = maxiMin(beginSt, d, watch); 
      if (s.getNextMove().getIsWin() == true) 
      { 
       break; 
      } 
      d++; 
     } 
     return new location(s.getNextMove().getRow(), s.getNextMove().getCol()); 

अल्फा बीटा:

public State maxiMin(State s, int depth, Stopwatch timer) 
    { 
     if (s.getDepth() == 7) 
     { 
      Console.WriteLine(); 
     } 
     if (timer.get_ElapsedMilliseconds() > 850 || s.getDepth() == depth || goalTest(s.getBoard()) != 0) 
     { 
      s.evaluationFunc(line_length, PlayerShape); 
      s.setAlpha(s.getEvaluation()); 
      s.setBeta(s.getEvaluation()); 
      return s; 
     } 
     LinkedList<State> children = createChildren(s, true); 
     // No winner, the board is full 
     if (children.get_Count() == 0) 
     { 
      s.evaluationFunc(line_length, PlayerShape); 
      s.setAlpha(s.getEvaluation()); 
      s.setBeta(s.getEvaluation()); 
      return s; 
     } 
     while (children.get_Count() > 0) 
     { 
      State firstChild = children.get_First().get_Value(); 
      children.RemoveFirst(); 
      State tmp = miniMax(firstChild, depth, timer); 
      int value = tmp.getBeta(); 
      if (value > s.getAlpha()) 
      { 
       s.setAlpha(value); 
       s.setNextMove(tmp); 
      } 
      if (s.getAlpha() >= s.getBeta()) 
      { 
       return s; 
      } 
     } 
     return s; 
    } 

    public State miniMax(State s, int depth, Stopwatch timer) 
    { 
     if (s.getDepth() == 7) 
     { 
      Console.WriteLine(); 
     } 
     if (timer.get_ElapsedMilliseconds() > 850 || s.getDepth() == depth || goalTest(s.getBoard()) != 0) 
     { 
      s.evaluationFunc(line_length, PlayerShape); 
      s.setAlpha(s.getEvaluation()); 
      s.setBeta(s.getEvaluation()); 
      return s; 
     } 
     LinkedList<State> children = createChildren(s, false); 
     // No winner, the board is full 
     if (children.get_Count() == 0) 
     { 
      s.evaluationFunc(line_length, PlayerShape); 
      s.setAlpha(s.getEvaluation()); 
      s.setBeta(s.getEvaluation()); 
      return s; 
     } 
     while (children.get_Count() > 0) 
     { 
      State firstChild = children.get_First().get_Value(); 
      children.RemoveFirst(); 
      State tmp = maxiMin(firstChild, depth, timer); 
      int value = tmp.getAlpha(); 
      if (value < s.getBeta()) 
      { 
       s.setBeta(value); 
       s.setNextMove(tmp); 
      } 
      if (s.getAlpha() >= s.getBeta()) 
      { 
       return s; 
      } 
     } 
     return s; 
    } 

बहुत appriciate होगा अगर किसी को भी मुझे बता सकते हैं अगर कुछ गलत है

यहाँ मेरी कोड है। मैं शायद संदेह कि के साथ क्या करना यह कुछ मैं लौट रहा हूँ "एस" नियमित रूप से अल्फा बीटा जो मूल्यांकन रिटर्न लेकिन मैं त्रुटि खोजने के लिए प्रबंधन फ्लॉप के बजाय।

अग्रिम धन्यवाद,

लीना

+1

मुझे लगता है कि आपको मिनीमैक्स (http://en.wikipedia.org/wiki/Minimax) से शुरू करना चाहिए, तब जब आप अल्फा बीटा में उस काम को जोड़ते हैं। इससे डीबग करना बहुत आसान हो जाएगा। Minimax अनिवार्य रूप से छंटनी के बिना अल्फा बीटा है। Minimax कुछ सेकंड के भीतर आसानी से टिक टैक पैर की अंगुली हल करेगा। – theycallhimtom

उत्तर

5

सबसे पहले टिक टीएसी को पैर की अंगुली एक बहुत ही सरल खेल है, और मेरा मानना ​​है कि यह एक बहुत सरल कोड के साथ व्याख्या करने योग्य है, मुख्य रूप से है क्योंकि हम जानते वहाँ हमेशा एक टाई है विकल्प और राज्यों की कुल संख्या 3^9 से कम है (सममित और कई असंभव राज्यों सहित)।

आपके कोड के लिए मुझे विश्वास है कि आपकी समस्याओं में से एक यह है कि आप रिकर्सिव कॉल में अपनी गहराई में वृद्धि नहीं कर रहे हैं।

आपके कोड में खराब शैली के कई मुद्दे भी हैं, आपने मिनीमैक्स और मैक्सीमिन को दो कार्यों में विभाजित किया है, हालांकि वे मूल रूप से वही हैं। आप प्रत्येक से एक या इटरेटर (या यहां तक ​​कि एक int iterator) के उपयोग के विरोध में इसके तत्वों को हटाकर संग्रह पर पुन: प्रयास करते हैं।

संबंधित मुद्दे