Compare commits

..

2 Commits

Author SHA1 Message Date
Maximilian Moser
dedf852090 Make AI smarter 2024-03-04 23:27:49 +01:00
Maximilian Moser
5d4b3c55c6 Add support for multiple AI-controlled players 2024-03-04 23:15:24 +01:00
2 changed files with 7 additions and 3 deletions

View File

@@ -23,4 +23,4 @@ Other key bindings are:
## Playing against AI
If you want to play against the AI instead of other players, supply the corresponding CLI flag: `pipenv run ./maxman.py --ai`
If you want to play against the AI instead of other players, supply the corresponding CLI flag: `pipenv run ./maxman.py --ai <number of AI players>`

View File

@@ -115,11 +115,14 @@ class AI:
return
target = self.target
if random.random() * 100 < 10:
if (target and target.size > self.man.size) or random.random() * 100 < 10:
target = None
if target is None:
if targets := [e for e in self.enemies or [] if e.size < self.man.size]:
targets = [
e for e in self.enemies or [] if e.alive and e.size < self.man.size
]
if targets:
target = random.choice(targets)
if target is None:
@@ -235,6 +238,7 @@ while running:
for p in players:
for op in players:
if p != op and p.can_eat(op):
op.alive = False
players.remove(op)
if p.can_eat(food):