Getting started with IronPython – Part 4: MiniMax algorithm

13 ביולי 2009

4 תגובות

My blog has moved. You can view this post at the following address: http://blog.drorhelper.com/2009/07/getting-started-with-ironpython-part-4.html

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים

4 תגובות

  1. Michael Foord13 ביולי 2009 ב 23:07

    Instead "for i in range(len(something))" look into the builtin enumerate function.

    Could getAvailableMoves be built as single list comprehension? Perhaps:

    [pot.seeds for pot in playerPots if pot.seeds > 0]

    להגיב
  2. dhelper14 ביולי 2009 ב 21:35

    It seems like a good idea, but how can I collect the index of the pot so I can return it in the end?

    להגיב
  3. Danilo Cabello19 ביולי 2009 ב 4:09

    Hi,

    Just commenting about the Michael Ford idea, I saw your try, but he was saying to use enumerate, see a sample:

    >>> lst = ['a','b','c']
    >>> for item in lst:
    print item

    a
    b
    c
    >>> for index,value in enumerate(lst):
    print index, value

    0 a
    1 b
    2 c
    >>> [index for index, value in enumerate(lst) if value == 'a']
    [0]

    In python we forget the idea of iterating len(something) we always iterate for piece in pieces, is hard to get used but is nice.

    I think in your example the code looks like:
    [index for index, pot in enumerate(playerPots) if pot.seeds > 0]

    להגיב
  4. dhelper19 ביולי 2009 ב 22:38

    Thanks – It' hard to unlearn a few C* habits. Very elegant solution

    להגיב