i'm currently working on my final project in school so i'm making a game with pygame.
The game includes a board with bases, colonies and defenses, all are sprite objets.
In the project we were requested to add 2 machine learning algorithems so one of them is minimax.
as you probably know, to use minimax you need to copy.deepcopy
the board a couple of times and calculate each board's huristic value and find the best boards when max and the worst ones when min.
The problem I am facing is the simple fact that copy.deepcopy
probably can't operate on an object that has sprite's attributes.
This is the error message that shows up:
TypeError:无法腌制pygame.Surface对象
它将我的地址指向代码的这一行:
b = copy.deepcopy(板)
我真的不知道在这种情况下该怎么办,因为我有大约1700行代码+完成的图形,并且将所有对象更改为非sprite对象实在太多了,所以我无法返回并更换电路板。 所以我非常需要您的帮助,必须弄清楚这一点才能继续
这是游戏开始时董事会中单行的示例;只是为了帮助您了解我在说什么:
[无,“ <”殖民地精灵(分为2组)“>”,无,无,无,无,无,无,无,无,无,无,无,无,无,无,无,无,“ <“殖民地雪碧(分为2组)”>“,无]
最后一段中与sprite相关的代码是殖民地类的示例:
class Colony(pg.sprite.Sprite):
def __init__(self, x, y, clan, type):
self.clan = clan
if self.clan == 1:
name = "joogadars"
else:
name = "klagars"
self.type = type
if type == 1:
type_name = "doorks"
else:
type_name = "gorgs"
self.lvl = 1
self.attackable = True
self.rates = array_from_txt_colonies("Colonies Data.txt", self.type, 'Rates')
self.prices = array_from_txt_colonies("Colonies Data.txt", self.type, 'Prices')
self.hps = array_from_txt_colonies("Colonies Data.txt", self.type, 'Hps')
self.hp = self.hps[self.lvl - 1]
self.rate = self.rates[self.lvl - 1]
self.position = (x, y)
full_name = type_name + '/' + name + '/' + name + " " + type_name + " colony lvl " + str(self.lvl) + " use.png"
pg.sprite.Sprite.__init__(self)
img = 'C:/Users/ariel/Desktop/Ariel/12th/Python/final proj/graphics/islands/colonies/' + full_name
self.image = pg.image.load(img)
self.rect = self.image.get_rect(center=self.position)