mirror of
https://github.com/Xevion/fusion-fission-choices.git
synced 2025-12-05 23:15:06 -06:00
simplify to lambdas
This commit is contained in:
@@ -8,6 +8,14 @@
|
||||
|
||||
As of now, I have only implemented the fusion part, since it's drastically easier. The fission module for this will come later, if I decide I need it, but since the fission recipes come in JEI automatically... I'll be okay.
|
||||
|
||||
## To-do
|
||||
|
||||
* Implement Fission
|
||||
|
||||
* Better configuration options
|
||||
|
||||
* Automatic scoring system
|
||||
|
||||
## Configuration Options
|
||||
|
||||
The `elements` portion refers to the scores of each element, each being the atomic number of the element.
|
||||
|
||||
16
fusion.py
16
fusion.py
@@ -1,14 +1,15 @@
|
||||
import os, sys, json, re, mendeleev as mdv
|
||||
|
||||
# Configuration reading
|
||||
path = os.path.join(sys.path[0], 'config.json')
|
||||
config = json.load(open(path, 'r'))
|
||||
|
||||
def score(element):
|
||||
return config['elements'][str(element)]
|
||||
|
||||
def scoreSum(item):
|
||||
return (score(item[0]) + score(item[1])), item
|
||||
# Lambdas
|
||||
score = lambda element : config['elements'][str(element)]
|
||||
scoreSum = lambda item : ((score(item[0]) + score(item[1])), item)
|
||||
hasNegatives = lambda item : score(item[0]) < 0 or score(item[1]) < 0
|
||||
|
||||
# Formatting for a single element report line
|
||||
def formatting(e1, e2):
|
||||
e1, e2 = mdv.element(e1), mdv.element(e2)
|
||||
return '\t[{} {}] + [{} {}]'.format(e1.symbol if not config['fullPrint'] else e1.name,
|
||||
@@ -16,9 +17,6 @@ def formatting(e1, e2):
|
||||
e2.symbol if not config['fullPrint'] else e2.name,
|
||||
e2.atomic_number)
|
||||
|
||||
def hasNegatives(item):
|
||||
return score(item[0]) < 0 or score(item[1]) < 0
|
||||
|
||||
# get the element based on two letters or a digit and attempt to map it to a number
|
||||
def getElement(element):
|
||||
if re.match(r'\d+', element):
|
||||
@@ -58,8 +56,8 @@ def main():
|
||||
selection = [getElement(e) for e in selection.split()]
|
||||
print('\n\n'.join(
|
||||
sorted(['{}\n{}'.format(*bestSelection(E)) for E in selection],
|
||||
key=lambda string : len([line for line in string.split('\n') if
|
||||
# hacky solution for reverseOrder config option
|
||||
key=lambda string : len([line for line in string.split('\n') if
|
||||
'\t{No elements matched the configuration specified}' not in line]),
|
||||
reverse=not config['reverseOrder'])
|
||||
))
|
||||
Reference in New Issue
Block a user