0

私は人工知能に非常に慣れておらず、主に理論的なコンピューター サイエンス/AI の経験があります。小さなプロジェクトとして、数年前の Google AI チャレンジの簡易版にミニマックス アルゴリズムを実装しようとしています。残念ながら、多くの試みと疑似コードの読み取りの後、私はまだそれをうまく実装できていません。

プラネット ウォーズは、自分の惑星を持つ 2 人のプレイヤー間のゲームです。毎ターン、プレイヤーは自分の惑星のどれから船の半分を中立または敵の惑星に送るかを決めることができます。このように、相手の惑星を乗っ取ることが可能です。対戦相手の惑星がなくなったら勝ちです。

まだ私はこれを書いています:

max_depth = 4

def minmax(pw, depth):
    max_player(pw, depth)
    return [max_source,max_dest]

def min_player(pw, depth):
    if depth > max_depth:
    return evaluate_state(pw)
    min_score = 10000

for my_planet in pw.my_planets(pw):
    for not_my_planet in pw.not_my_planets(pw):
        sim = simulate_move(pw)
        simulated_pw.SimulateAttack(my_planet, not_my_planet)
        score = max(sim, depth +1)
        if score < min_score:
            score = min_score
return min_score

def max_player(pw, depth):
    if depth > max_depth:
        return evaluate_state(pw)
    max_score = -10000
    global max_source
    global max_dest
for my_planet in pw.my_planets(pw):
    for not_my_planet in pw.not_my_planets(pw):
        sim = simulate_move(pw)
        sim.SimulateAttack(my_planet, not_my_planet)
        score = min(sim, depth +1)
        if score > max_score:
            score = max_score
            max_source = my_planet
            max_dest = not_my_planet
return max_score

def do_turn(pw):
    source = None
    destination = None

# (1) Implement an algorithm to determine the source planet to send your ships from  
source = minmax(pw, 4)[0]

# (2) Implement an algorithm to determine the destination planet to send your ships to
destination = minmax(pw, 4)[1]

# (3) Attack/Defend
# If the source and destination variables contain actual planets, then
# send half of the ships from source to destination.
if source is not None and destination is not None:
    pw.issue_order(source, destination)

しかし、別のボットと対戦しようとすると、ターミナルはこれを返します:

Johannas-MacBook-Pro:PlanetWars johannakorte$ python play.py -1 MinMax2.py     -2 BullyBot.py -s

Game[1]: Something went wrong, engine output dump:

-------------------------

Engine entering main game loop. Mode serial

Game state turn 0

Player 1 said: Traceback (most recent call last):

Player 1 said:   File "src/python/MinMax2.py", line 74, in <module>

Player 1 said:     main()

Player 1 said:   File "src/python/MinMax2.py", line 69, in main

Player 1 said:     do_turn(pw)

Player 1 said:   File "src/python/MinMax2.py", line 52, in do_turn

Player 1 said:     source = minmax(pw, 4)[0]

Player 1 said:   File "src/python/MinMax2.py", line 14, in minmax

Player 1 said:     max_player(pw, depth)

Player 1 said:   File "src/python/MinMax2.py", line 36, in max_player

Player 1 said:     for my_planet in pw.my_planets(pw):

Player 1 said: TypeError: my_planets() takes exactly 1 argument (2 given)

Player 1 timeout: you missed a turn! Consider to make your bot faster, or    increase the maxTurnTime.

Game state turn 1

Game state turn 2

Couldn't write to stdin of player 1

私のボットは、速度が不十分であるか、決定を下していないために、ターンを逃しているようです。

ご意見やフィードバックをいただければ幸いです。ありがとう!

4

1 に答える 1

2

次の行が原因で、コードがクラッシュします: for my_planet in pw.my_planets(pw):.

それを置き換えるとfor my_planet in pw.my_planets():、少なくとも1つのエラーがなくなります。これは、pw がクラスであるためです。つまり、そのクラスのすべての関数は自動的にself最初のパラメーターとして取ります。この最初のパラメーターは指定しないでください。

簡単な例で説明するには:

class MyClass(object):
    def __init__(self): pass
    def show42(self):
        return 42
class1 = MyClass()

# This will work:
print(class1.show42())
# 42

# ... but this will crash
print(class1.show42(class1))
# It will crash with: TypeError: show42() takes exactly 1 argument (2 given)
于 2016-03-21T20:17:29.730 に答える