Getting started with IronPython – Part 4: MiniMax algorithm

13 ביולי 2009

4 תגובות

My blog has moved. You can view this post at the following address:

הוסף תגובה
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


    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

    >>> 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']

    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