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 snack import Snack
from mine import Mine from mine import Mine
from random import shuffle from random import shuffle
from minecounter import mine_counter
MAX_MINES = 50
LEVELS = [
[5, 10],
[10, 20],
[15, 30],
[100, 40]
]
class Board: class Board:
display = False display = False
snack=False snack=False
mine=False mine=False
def __init__(self,width, height,num_snacks,num_mines): def __init__(self,width, height,num_snacks):
self.width = width self.width = width
self.height = height self.height = height
self.num_snacks = num_snacks 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() all_positions = self.get_all_positions()
shuffle(all_positions) shuffle(all_positions)
man= [Man(all_positions[0])] man= [Man(all_positions[0])]
snacks = [Snack(p) for p in all_positions[1:(num_snacks+1)]] 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] agents = man + snacks + mines + [self]
return agents return agents
def play_turn(self,game): def play_turn(self,game):
game.log(game.turn_number) game.log(self.num_mines)
while self.game_needs_snacks(game): while self.game_needs_snacks(game):
self.add_snack(game) self.add_snack(game)
while self.game_needs_mines(game): while self.game_needs_mines(game):

View File

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

View File

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