generated from mwc/project_game
regenerates mines and snacks
may still try to add more difficulty and update any docstrings and old commented code
This commit is contained in:
@@ -2,16 +2,19 @@ from man import Man
|
||||
from snack import Snack
|
||||
from mine import Mine
|
||||
from random import shuffle
|
||||
from retro import game
|
||||
|
||||
|
||||
class Board:
|
||||
|
||||
display = False
|
||||
snack=False
|
||||
mine=False
|
||||
|
||||
def __init__(self,width, height,num_snacks,num_mines):
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.num_snacks = num_snacks
|
||||
self.num_mines = num_mines
|
||||
|
||||
|
||||
def get_agents(self,num_snacks,num_mines):
|
||||
all_positions = self.get_all_positions()
|
||||
@@ -19,8 +22,51 @@ class Board:
|
||||
man= [Man(all_positions[0])]
|
||||
snacks = [Snack(p) for p in all_positions[1:(num_snacks+1)]]
|
||||
mines = [Mine(p) for p in all_positions[(num_snacks + 2):(num_snacks + num_mines +2)]]
|
||||
agents = man + snacks + mines
|
||||
agents = man + snacks + mines + [self]
|
||||
return agents
|
||||
|
||||
def play_turn(self,game):
|
||||
game.log(game.turn_number)
|
||||
while self.game_needs_snacks(game):
|
||||
self.add_snack(game)
|
||||
while self.game_needs_mines(game):
|
||||
self.add_mine(game)
|
||||
|
||||
def add_mine(self,game):
|
||||
all_positions=self.get_all_positions()
|
||||
shuffle(all_positions)
|
||||
index =0
|
||||
while not game.is_empty(all_positions[index]):
|
||||
index = index + 1
|
||||
mine = Mine(all_positions[index])
|
||||
game.add_agent(mine)
|
||||
|
||||
def count_mines(self,game):
|
||||
mines= [a for a in game.agents if a.mine]
|
||||
return len(mines)
|
||||
|
||||
def game_needs_mines(self,game):
|
||||
return self.count_mines(game) < self.num_mines
|
||||
|
||||
|
||||
def add_snack(self,game):
|
||||
all_positions=self.get_all_positions()
|
||||
shuffle(all_positions)
|
||||
index =0
|
||||
while not game.is_empty(all_positions[index]):
|
||||
index = index + 1
|
||||
snack = Snack(all_positions[index])
|
||||
game.add_agent(snack)
|
||||
|
||||
def count_snacks(self,game):
|
||||
snacks= [a for a in game.agents if a.snack]
|
||||
return len(snacks)
|
||||
|
||||
def game_needs_snacks(self,game):
|
||||
return self.count_snacks(game) < self.num_snacks
|
||||
|
||||
|
||||
|
||||
'''
|
||||
def get_agents(self,num_snacks,num_mines):
|
||||
man = self.get_man(num_snacks,num_mines)
|
||||
|
||||
Reference in New Issue
Block a user