Commit 2d40bc7e authored by Oskar Skog's avatar Oskar Skog

Attempting to remove no flag count option

parent 4ee8ea8c
0.5.7
- No option to disable flagcount.
- enginecfg: 'hiscores' is now required.
- anonymine_engine.py: The hiscores_dummy class has been removed.
0.5.6
- cursescfg has changed: Added a key cfg['curses-input']['quit']
......
......@@ -494,10 +494,7 @@ class curses_game():
chunks.append('Choose your starting point.')
if engine.game_status == 'play-game':
if engine.field.flags_left is not None:
chunks.append("Flags left: {0}".format(
engine.field.flags_left
))
chunks.append("Flags left: {0}".format(engine.field.flags_left))
msg = ' '.join(chunks)
if len(msg) + 4 <= self.width:
......@@ -1099,8 +1096,7 @@ def arg_input(default):
game parameters, `user_input` will be True.
`default` is a dictionary that MUST contain these keys:
'width', 'height', 'mines', 'gametype', 'flagcount', 'guessless'
and 'insult'.
'width', 'height', 'mines', 'gametype', 'guessless' and 'insult'.
Their types are specified in the doc-string for `play_game`.
`params` is a dictionary that contains either all of the keys that
......@@ -1228,23 +1224,6 @@ without guessing and supports three different game types:
)
)
# Bools.
flagcount = parser.add_mutually_exclusive_group()
flagcount.add_argument(
'-f', '--flagcount', dest='flagcount', action='store_true',
help=(
"Show how many flags are left." + default_s[
default['flagcount']
]
)
)
flagcount.add_argument(
'-F', '--no-flagcount', dest='noflagcount', action='store_true',
help=(
"Don't Show how many flags are left." + default_s[
not default['flagcount']
]
)
)
guessless = parser.add_mutually_exclusive_group()
guessless.add_argument(
'-g', '--guessless', dest='guessless', action='store_true',
......@@ -1260,7 +1239,7 @@ without guessing and supports three different game types:
help=(
"Play with the risk of having to guess. " +
"Large fields will be initialized much faster." + default_s[
not default['flagcount']
not default['guessless']
]
)
)
......@@ -1321,13 +1300,7 @@ without guessing and supports three different game types:
user_input_required = False
assert args.gametype in ('moore', 'hex', 'neumann')
params['gametype'] = args.gametype
# flagcount, guessless, insult
if args.flagcount:
user_input_required = False
params['flagcount'] = True
if args.noflagcount:
user_input_required = False
params['flagcount'] = False
# guessless, insult
if args.guessless:
user_input_required = False
params['guessless'] = True
......@@ -1363,8 +1336,7 @@ def user_input(default, cursescfg_path):
displayed by this function.
`default` is a dictionary that MUST contain these keys:
'width', 'height', 'mines', 'gametype', 'flagcount', 'guessless'
and 'insult'.
'width', 'height', 'mines', 'gametype', 'guessless' and 'insult'.
Their types are specified in the doc-string for `play_game`.
`user_input` will return dictionary containing the same keys.
......@@ -1392,11 +1364,6 @@ def user_input(default, cursescfg_path):
'gametype',
default['gametype']
)
parameters['flagcount'] = ask(
'Do you want to know how many flags you have left?',
'yesno',
booldefault[default['flagcount']]
)
parameters['guessless'] = ask(
'100% solvable field (no guessing required)',
'yesno',
......@@ -1526,7 +1493,6 @@ def play_game(parameters):
'height' Integer >= 4
'mines' Integer >= 1 or float in ]0.0, 1.0[
'gametype' 'moore', 'hex' or 'neumann'
'flagcount' A boolean (Show flag count)
'guessless' A boolean (no guessing required)
'insult' A boolean (!polite mode)
'enginecfg' The path to the configuration file for the
......@@ -1594,7 +1560,6 @@ def main():
'height': 20,
'mines': .2,
'gametype': 'moore',
'flagcount': True,
'guessless': True,
'insult': True,
}
......
......@@ -68,22 +68,6 @@ class security_alert(Exception):
pass
class hiscores_dummy():
'''
If the 'hiscores' field does not exist due to an old egninecfg
lacking 'hiscores' or perhaps an internal error, this class can
be used to create replacement objects for `hiscores`.
NOTICE: The `__init__` method takes `self` as the only argument.
'''
def __init__(self):
pass
def add_entry(self, inputfunction):
pass
def display(self):
return 'Higscores unavailable', (), []
class hiscores():
'''
Manage highscores.
......@@ -136,13 +120,13 @@ class hiscores():
The syntax that will be used for paramstrings should be
documented somewhere and somehow.
"{mines}@{width}x{height}-{gametype}" + nfc*"+nocount" + ng*"+losable"
"{mines}@{width}x{height}-{gametype}" + ng*"+losable"
<mines>"@"<width>"x"<height>"-"<gametype>["+nocount"]["+losable"]
<mines>"@"<width>"x"<height>"-"<gametype>["+losable"]
And for a lost game, "lost/" is prepended to the paramstring, ie:
"lost/"<mines>"@"<width>"x"<height>"-"<gametype>["+nocount"]["+losable"]
"lost/"<mines>"@"<width>"x"<height>"-"<gametype>["+losable"]
Unicode
......@@ -273,15 +257,12 @@ class hiscores():
Returns the sorted and tail truncated sublist.
self_reference.hiscores does not contain the sublist.
'''
filter_f = (lambda entry:
entry[0].replace('+nocount', '')
== self_reference.paramstring)
self_reference._load()
sublist = list(filter(
lambda entry: entry[0] == self_reference.paramstring,
self_reference.hiscores
))
self.hiscores = list(filter(
lambda entry: entry[0] != self_reference.paramstring,
self_reference.hiscores
))
sublist = list(filter(filter_f, self_reference.hiscores))
self.hiscores = list(filter(filter_f, self_reference.hiscores))
# Add entry.
sublist.append(new_entry)
self._sort(sublist, self.paramstring.startswith('lost/'))
......@@ -593,7 +574,6 @@ class game_engine():
height= # int >= 4
mines= # int; Only integers are allowed here.
gametype= # str; 'moore', 'hex' or 'neumann'
flagcount= # bool; Count how many flags are left?
guessless= # bool; Must be possible to solve without
# guessing?
......@@ -609,7 +589,6 @@ class game_engine():
'height': 10,
'mines': 10,
'gametype': 'moore',
'flagcount': True,
'guessless': True,
}
for key in default:
......@@ -627,19 +606,18 @@ class game_engine():
self.dimensions = (parameters['width'], parameters['height'])
self.gametype = parameters['gametype']
self.n_mines = parameters['mines']
self.flagcount = parameters['flagcount']
self.guessless = parameters['guessless']
if self.gametype == 'hex':
self.field = fields.hexagonal_field(
parameters['width'],
parameters['height'],
parameters['flagcount']
True # Flagcount
)
else:
self.field = fields.generic_field(
[parameters['width'], parameters['height']],
self.gametype == 'moore',
parameters['flagcount']
True # Flagcount
)
self.game_status = 'pre-game' # play-game game-won game-lost
......@@ -909,8 +887,6 @@ class game_engine():
self.dimensions[1],
self.gametype
)
if not self.flagcount:
paramstring += '+nocount'
if not self.guessless:
paramstring += '+losable'
mines_left = 0
......@@ -919,24 +895,11 @@ class game_engine():
for cell in self.field.all_cells():
if self.field.get(cell) == 'X':
mines_left += 1
# Some cheating may still be possible if flagcount is disabled.
if mines_left == 0:
mines_left = self.n_mines * 42
# Somehow missed more than 20% of all mines??
if self.field.flags_left is not None:
fail = float(mines_left - self.field.flags_left)/self.n_mines
if fail > .20:
mines_left = self.n_mines * 42
# Allow old configuration files.
if 'hiscores' in self.cfg:
hs = hiscores(
self.cfg['hiscores'],
paramstring,
delta_time,
mines_left
)
else:
hs = hiscores_dummy()
fail = float(mines_left - self.field.flags_left)/self.n_mines
if fail > .20:
mines_left = self.n_mines * 42
hs = hiscores(self.cfg['hiscores'], paramstring, delta_time, mines_left)
# NOTICE: This used to return game_won, delta_time
# Do this last, so the player won't unfairly get a terrible time.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment