AttributeError为9人Morris游戏运行Github代码时出错

2024-06-17 10:49:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在GitHub上使用下面的NineMenMorris代码,但是当我运行它时,我得到了下面的错误

错误出现在获得一个Morris(连续3个)后,算法要求选择一个对手人物来吃

https://github.com/boris-ns/NineMensMorris

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-47e27bb9316e> in <module>
      6     player2 = Human('B', game)
      7     game.set_players(player1, player2)
----> 8     game.place_figures_phase1()

<ipython-input-3-8aed7b0be5a0> in place_figures_phase1(self)
    287                 white_position = self._player1.place_figure()
    288                 self.place_figure_on_table(self._player1.mark, white_position)
--> 289                 self._while_closed_morris(white_position)
    290             else:              # Black on the move
    291                 black_position = self._player2.place_figure()

<ipython-input-3-8aed7b0be5a0> in _while_closed_morris(self, pozicija)
    261         if self.check_if_closed_morris(self._player1.mark, pozicija):
    262             self.draw_table()
--> 263             position_eat = self._player1.eat_opponents_figure()
    264             if position_eat == -1:
    265                 return

<ipython-input-1-1cfba64f88fc> in eat_opponents_figure(self)
     81                 continue
     82 
---> 83             if self.game_instance.eat_figure(self.mark, position):
     84                 return position
     85 

<ipython-input-3-8aed7b0be5a0> in eat_figure(self, mark, position)
    206             return False
    207 
--> 208         if mark == self._player1.oznaka:
    209             if self.check_if_closed_morris(self._player2.oznaka, position):
    210                 return False

AttributeError: 'Human' object has no attribute 'oznaka'

Tags: inselfgameinputifipythonpositionplace
1条回答
网友
1楼 · 发布于 2024-06-17 10:49:50

谢谢你的建议

@KetZoomer解决了这个问题

try replacing self._player1.ozanka, with self._player1.mark. look like the code was translated recently and he might have missed replacing that

很少有其他错误包括

  • self._player1.broj_figuraself._player1.num_of_figures
  • 位置

相关问题 更多 >