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:
parent
729e1085ee
commit
947f9647ba
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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)
|
||||
|
|
|
@ -17,7 +17,8 @@ direction_vectors = {
|
|||
class Man:
|
||||
character = "&" #try google asci full table?,
|
||||
color = "blue"
|
||||
#name = "man"
|
||||
snack=False
|
||||
mine=False
|
||||
|
||||
def __init__(self,position):
|
||||
self.position = position
|
||||
|
@ -50,7 +51,6 @@ class Man:
|
|||
if obstacle.snack:
|
||||
game.state['Score'] += 1
|
||||
game.remove_agent(agents[0])
|
||||
self.generate_new_snack()
|
||||
else:
|
||||
game.state['Score'] -= 10
|
||||
game.remove_agent(agents[0])
|
||||
|
@ -61,28 +61,16 @@ class Man:
|
|||
else:
|
||||
self.position = future_position
|
||||
|
||||
'''Indicates what happens when the game is over.'''
|
||||
|
||||
def die(self,game):
|
||||
'''Indicates what happens when the game is over.'''
|
||||
game.state["message"] = "Game Over"
|
||||
self.color = "black"
|
||||
game.end()
|
||||
|
||||
def get_all_positions(self):
|
||||
positions=[]
|
||||
for i in range(width):
|
||||
for j in range(height):
|
||||
positions.append((i,j))
|
||||
return positions
|
||||
|
||||
'''issue here, is_empty is not generating a coordinate positon,
|
||||
but I am not sure why it is not'''
|
||||
def generate_new_snack(self):
|
||||
all_positions=self.get_all_positions()
|
||||
shuffle(all_positions)
|
||||
index =0
|
||||
while Game.is_empty(all_positions[index]) == False:
|
||||
index = index + 1
|
||||
Snack(all_positions[index])
|
||||
|
||||
|
||||
'''
|
||||
def __init__(self, position):
|
||||
self.position = position
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
|
||||
MAX_MINES = 50
|
||||
LEVELS = [
|
||||
[5, 10],
|
||||
[50, 20],
|
||||
[75, 30],
|
||||
[100, 40]
|
||||
]
|
||||
|
||||
def num_mines(score):
|
||||
for limit, n in LEVELS:
|
||||
if score < limit:
|
||||
return n
|
||||
return MAX_MINES
|
||||
'''
|
||||
if score < 5:
|
||||
num_mines = 10
|
||||
if 10 <= score <50:
|
||||
num_mines = 20
|
||||
if 50 <= score <75:
|
||||
num_mines = 30
|
||||
if 75 <= score <100:
|
||||
num_mines = 40
|
||||
#else:
|
||||
#num_mines = 50
|
||||
return num_mines
|
||||
'''
|
|
@ -2,6 +2,7 @@ class Mine:
|
|||
character = "*"
|
||||
color = "green"
|
||||
snack=False
|
||||
mine=True
|
||||
|
||||
|
||||
def __init__(self,position):
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
|
||||
MAX_MINES = 50
|
||||
LEVELS = [
|
||||
[5, 10],
|
||||
[50, 20],
|
||||
[75, 30],
|
||||
[100, 40]
|
||||
]
|
||||
|
||||
def num_mines(score):
|
||||
for limit, n in LEVELS:
|
||||
if score < limit:
|
||||
return n
|
||||
return MAX_MINES
|
||||
'''
|
||||
if score < 5:
|
||||
num_mines = 10
|
||||
if 10 <= score <50:
|
||||
num_mines = 20
|
||||
if 50 <= score <75:
|
||||
num_mines = 30
|
||||
if 75 <= score <100:
|
||||
num_mines = 40
|
||||
#else:
|
||||
#num_mines = 50
|
||||
return num_mines
|
||||
'''
|
|
@ -1,7 +1,6 @@
|
|||
from retro.game import Game
|
||||
from board import Board
|
||||
|
||||
from score import num_mines
|
||||
from minecounter import num_mines
|
||||
|
||||
width = 25
|
||||
height = 25
|
||||
|
@ -14,6 +13,6 @@ board = Board(width,height,num_snacks,num_mines)
|
|||
game = Game(
|
||||
board.get_agents(num_snacks, num_mines),
|
||||
state,
|
||||
board_size = (width, height)
|
||||
board_size = (width, height),debug=True
|
||||
)
|
||||
game.play()
|
|
@ -1,6 +1,19 @@
|
|||
|
||||
|
||||
MAX_MINES = 50
|
||||
LEVELS = [
|
||||
[5, 10],
|
||||
[50, 20],
|
||||
[75, 30],
|
||||
[100, 40]
|
||||
]
|
||||
|
||||
def num_mines(score):
|
||||
for limit, n in LEVELS:
|
||||
if score < limit:
|
||||
return n
|
||||
return MAX_MINES
|
||||
'''
|
||||
if score < 5:
|
||||
num_mines = 10
|
||||
if 10 <= score <50:
|
||||
|
@ -12,4 +25,4 @@ def num_mines(score):
|
|||
#else:
|
||||
#num_mines = 50
|
||||
return num_mines
|
||||
|
||||
'''
|
|
@ -2,6 +2,7 @@ class Snack:
|
|||
character = "o"
|
||||
color = "red"
|
||||
snack=True
|
||||
mine=False
|
||||
|
||||
|
||||
def __init__(self,position):
|
||||
|
|
|
@ -1,7 +1,83 @@
|
|||
# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
|
||||
package = []
|
||||
|
||||
[[package]]
|
||||
name = "ansicon"
|
||||
version = "1.89.0"
|
||||
description = "Python wrapper for loading Jason Hood's ANSICON"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "ansicon-1.89.0-py2.py3-none-any.whl", hash = "sha256:f1def52d17f65c2c9682cf8370c03f541f410c1752d6a14029f97318e4b9dfec"},
|
||||
{file = "ansicon-1.89.0.tar.gz", hash = "sha256:e4d039def5768a47e4afec8e89e83ec3ae5a26bf00ad851f914d1240b444d2b1"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blessed"
|
||||
version = "1.20.0"
|
||||
description = "Easy, practical library for making terminal apps, by providing an elegant, well-documented interface to Colors, Keyboard input, and screen Positioning capabilities."
|
||||
optional = false
|
||||
python-versions = ">=2.7"
|
||||
files = [
|
||||
{file = "blessed-1.20.0-py2.py3-none-any.whl", hash = "sha256:0c542922586a265e699188e52d5f5ac5ec0dd517e5a1041d90d2bbf23f906058"},
|
||||
{file = "blessed-1.20.0.tar.gz", hash = "sha256:2cdd67f8746e048f00df47a2880f4d6acbcdb399031b604e34ba8f71d5787680"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
jinxed = {version = ">=1.1.0", markers = "platform_system == \"Windows\""}
|
||||
six = ">=1.9.0"
|
||||
wcwidth = ">=0.1.4"
|
||||
|
||||
[[package]]
|
||||
name = "jinxed"
|
||||
version = "1.3.0"
|
||||
description = "Jinxed Terminal Library"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "jinxed-1.3.0-py2.py3-none-any.whl", hash = "sha256:b993189f39dc2d7504d802152671535b06d380b26d78070559551cbf92df4fc5"},
|
||||
{file = "jinxed-1.3.0.tar.gz", hash = "sha256:1593124b18a41b7a3da3b078471442e51dbad3d77b4d4f2b0c26ab6f7d660dbf"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
ansicon = {version = "*", markers = "platform_system == \"Windows\""}
|
||||
|
||||
[[package]]
|
||||
name = "retro-games"
|
||||
version = "1.1.0"
|
||||
description = "A simple framework for Terminal-based games"
|
||||
optional = false
|
||||
python-versions = "<4.0,>=3.10"
|
||||
files = [
|
||||
{file = "retro_games-1.1.0-py3-none-any.whl", hash = "sha256:c621117e4dd528b1e4870d897d00c4365566ab3ba965177e3996ed3c889dd9f8"},
|
||||
{file = "retro_games-1.1.0.tar.gz", hash = "sha256:2167b574f42fe1e739b7c9ec75e98a9b76df42e2166376b85559291b3dc58f82"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
blessed = ">=1.20.0,<2.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "six"
|
||||
version = "1.17.0"
|
||||
description = "Python 2 and 3 compatibility utilities"
|
||||
optional = false
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7"
|
||||
files = [
|
||||
{file = "six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274"},
|
||||
{file = "six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wcwidth"
|
||||
version = "0.2.13"
|
||||
description = "Measures the displayed width of unicode strings in a terminal"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "wcwidth-0.2.13-py2.py3-none-any.whl", hash = "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859"},
|
||||
{file = "wcwidth-0.2.13.tar.gz", hash = "sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5"},
|
||||
]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "53f2eabc9c26446fbcc00d348c47878e118afc2054778c3c803a0a8028af27d9"
|
||||
content-hash = "2bcb10c06051310c2d2ce4f7b65ed30705765ffe70121fe098b07e32ef9307bc"
|
||||
|
|
|
@ -7,6 +7,7 @@ readme = "README.md"
|
|||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
retro-games = "^1.1.0"
|
||||
|
||||
|
||||
[build-system]
|
||||
|
|
Loading…
Reference in New Issue