trying to import state to help me determine the

number of mines
This commit is contained in:
Chris Mekelburg 2024-12-10 21:36:09 -05:00
parent 947f9647ba
commit 5980c6bb22
5 changed files with 35 additions and 15 deletions

View File

@ -2,31 +2,49 @@ from man import Man
from snack import Snack
from mine import Mine
from random import shuffle
from minecounter import mine_counter
MAX_MINES = 50
LEVELS = [
[5, 10],
[10, 20],
[15, 30],
[100, 40]
]
class Board:
display = False
snack=False
mine=False
def __init__(self,width, height,num_snacks,num_mines):
def __init__(self,width, height,num_snacks):
self.width = width
self.height = height
self.num_snacks = num_snacks
self.num_mines = num_mines
#self.num_mines = num_mines
def mine_counter(self,game):
current_score_dict = game.state
current_score = current_score_dict['Score']
for limit, n in LEVELS:
if current_score < limit:
return n
return MAX_MINES
def get_agents(self,num_snacks,num_mines):
def get_agents(self,num_snacks):
num_mines = int(self.mine_counter)
print(num_mines)
all_positions = self.get_all_positions()
shuffle(all_positions)
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)]]
mines = [Mine(p) for p in all_positions[(num_snacks + 2):(num_snacks + num_mines +2)]]
agents = man + snacks + mines + [self]
return agents
def play_turn(self,game):
game.log(game.turn_number)
game.log(self.num_mines)
while self.game_needs_snacks(game):
self.add_snack(game)
while self.game_needs_mines(game):

View File

@ -3,16 +3,18 @@
MAX_MINES = 50
LEVELS = [
[5, 10],
[50, 20],
[75, 30],
[10, 20],
[15, 30],
[100, 40]
]
def num_mines(score):
def mine_counter(state):
current_score = state['Score']
for limit, n in LEVELS:
if score < limit:
if current_score < limit:
return n
return MAX_MINES
'''
if score < 5:
num_mines = 10

View File

@ -1,18 +1,18 @@
from retro.game import Game
from board import Board
from minecounter import num_mines
width = 25
height = 25
state= {"Score":0}
score =state["Score"]
score = state["Score"]
num_snacks = 10
num_mines = num_mines(score)
board = Board(width,height,num_snacks,num_mines)
board = Board(width,height,num_snacks)
game = Game(
board.get_agents(num_snacks, num_mines),
board.get_agents(num_snacks),
state,
board_size = (width, height),debug=True
)
game.play()
game.play()
#print(board.num_mines)