mirror of
https://github.com/Xevion/fusion-fission-choices.git
synced 2025-12-11 00:07:23 -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.
|
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
|
## Configuration Options
|
||||||
|
|
||||||
The `elements` portion refers to the scores of each element, each being the atomic number of the element.
|
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
|
import os, sys, json, re, mendeleev as mdv
|
||||||
|
|
||||||
|
# Configuration reading
|
||||||
path = os.path.join(sys.path[0], 'config.json')
|
path = os.path.join(sys.path[0], 'config.json')
|
||||||
config = json.load(open(path, 'r'))
|
config = json.load(open(path, 'r'))
|
||||||
|
|
||||||
def score(element):
|
# Lambdas
|
||||||
return config['elements'][str(element)]
|
score = lambda element : config['elements'][str(element)]
|
||||||
|
scoreSum = lambda item : ((score(item[0]) + score(item[1])), item)
|
||||||
def scoreSum(item):
|
hasNegatives = lambda item : score(item[0]) < 0 or score(item[1]) < 0
|
||||||
return (score(item[0]) + score(item[1])), item
|
|
||||||
|
|
||||||
|
# Formatting for a single element report line
|
||||||
def formatting(e1, e2):
|
def formatting(e1, e2):
|
||||||
e1, e2 = mdv.element(e1), mdv.element(e2)
|
e1, e2 = mdv.element(e1), mdv.element(e2)
|
||||||
return '\t[{} {}] + [{} {}]'.format(e1.symbol if not config['fullPrint'] else e1.name,
|
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.symbol if not config['fullPrint'] else e2.name,
|
||||||
e2.atomic_number)
|
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
|
# get the element based on two letters or a digit and attempt to map it to a number
|
||||||
def getElement(element):
|
def getElement(element):
|
||||||
if re.match(r'\d+', element):
|
if re.match(r'\d+', element):
|
||||||
@@ -58,8 +56,8 @@ def main():
|
|||||||
selection = [getElement(e) for e in selection.split()]
|
selection = [getElement(e) for e in selection.split()]
|
||||||
print('\n\n'.join(
|
print('\n\n'.join(
|
||||||
sorted(['{}\n{}'.format(*bestSelection(E)) for E in selection],
|
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
|
# 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]),
|
'\t{No elements matched the configuration specified}' not in line]),
|
||||||
reverse=not config['reverseOrder'])
|
reverse=not config['reverseOrder'])
|
||||||
))
|
))
|
||||||
Reference in New Issue
Block a user