ai options
This commit is contained in:
1 parent
e2c9b4daaa
commit
ea1a8f78f8
4 files changed
+28
-18
No files matched your search
@@ -64,6 +64,10 @@ AI_STRENGTH = { # not used
|
||||
}
|
||||
|
||||
AI_OPTION_VALUES = {
|
||||
"kyu_rank": [(k, f"{k}[strength:kyu]") for k in range(15, 0, -1)]
|
||||
+ [(k, f"{1-k}[strength:dan]") for k in range(0, -3, -1)]
|
||||
"kyu_rank": [(k, f"{k}[strength:kyu]") for k in range(15, 0, -1)] + [(k, f"{1-k}[strength:dan]") for k in range(0, -3, -1)],
|
||||
"strength": [0.25,0.5,1,2,4],
|
||||
"opening_moves": range(0,51),
|
||||
"pick_override": [0,0.5,0.6,0.7,0.8,0.9,0.95,1],
|
||||
"lower_bound": [(v,f"{v:.2%}") for v in [0,0.0001,0.0005,0.001,0.005,0.01,0.05] ],
|
||||
"weaken_fac": [-2,-1,0.5,1,1.25,1.5,2,4]
|
||||
}
|
||||
@@ -158,7 +158,7 @@ class QuickConfigGui(MDBoxLayout):
|
||||
Clock.schedule_once(self.build_and_set_properties, 0)
|
||||
|
||||
def collect_properties(self, widget) -> Dict:
|
||||
if isinstance(widget, (LabelledTextInput, LabelledSpinner, LabelledCheckBox)) and getattr(
|
||||
if isinstance(widget, (LabelledTextInput, LabelledSpinner, LabelledCheckBox,LabelledSelectionSlider)) and getattr(
|
||||
widget, "input_property", None
|
||||
):
|
||||
try:
|
||||
@@ -318,10 +318,14 @@ class ConfigAIPopup(QuickConfigGui):
|
||||
self.options_grid.clear_widgets()
|
||||
self.help_label.text = i18n._(strategy.replace("ai:", "aihelp:"))
|
||||
for k, v in sorted(mode_settings.items(), key=lambda kv: kv[0]):
|
||||
self.options_grid.add_widget(DescriptionLabel(text=k))
|
||||
self.options_grid.add_widget(DescriptionLabel(text=k,size_hint_x=0.25))
|
||||
if k in AI_OPTION_VALUES:
|
||||
values = [(v, re.sub(r"\[(.*?)\]", lambda m: i18n._(m[1]), l)) for v, l in AI_OPTION_VALUES[k]]
|
||||
widget = LabelledSelectionSlider(values=values, input_property=f"ai/{strategy}/{k}")
|
||||
values = AI_OPTION_VALUES[k]
|
||||
if isinstance(values[0],Tuple): # with descriptions, possibly language-specific
|
||||
fixed_values = [(v, re.sub(r"\[(.*?)\]", lambda m: i18n._(m[1]), l)) for v, l in values]
|
||||
else: # just numbers
|
||||
fixed_values = [(v, str(v)) for v in values]
|
||||
widget = LabelledSelectionSlider(values=fixed_values, input_property=f"ai/{strategy}/{k}")
|
||||
widget.set_value(v)
|
||||
self.options_grid.add_widget(wrap_anchor(widget))
|
||||
else:
|
||||
@@ -329,7 +333,7 @@ class ConfigAIPopup(QuickConfigGui):
|
||||
wrap_anchor(LabelledFloatInput(text=str(v), input_property=f"ai/{strategy}/{k}"))
|
||||
)
|
||||
for _ in range((self.max_options - len(mode_settings)) * 2):
|
||||
self.options_grid.add_widget(Label())
|
||||
self.options_grid.add_widget(Label(size_hint_x=None))
|
||||
|
||||
|
||||
class ConfigPopup(QuickConfigGui):
|
||||
|
||||
@@ -2,13 +2,12 @@ from kivy.lang import Builder
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.properties import (
|
||||
NumericProperty,
|
||||
AliasProperty,
|
||||
ListProperty,
|
||||
BooleanProperty,
|
||||
)
|
||||
from kivymd.uix.label import MDLabel
|
||||
from kivymd.uix.selectioncontrol import Thumb
|
||||
from katrain.gui.style import LIGHTER_BACKGROUND_COLOR
|
||||
|
||||
|
||||
|
||||
class SelectionSlider(Widget):
|
||||
@@ -23,7 +22,7 @@ class SelectionSlider(Widget):
|
||||
padding = NumericProperty("16sp")
|
||||
|
||||
track_color = ListProperty([1, 1, 1, 0.3])
|
||||
thumb_color = LIGHTER_BACKGROUND_COLOR
|
||||
thumb_color = ListProperty([0.5, 0.5, 0.5, 1])
|
||||
|
||||
def __init__(self,**kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@@ -77,6 +76,7 @@ class SelectionSlider(Widget):
|
||||
|
||||
|
||||
KV = """
|
||||
#:import i18n katrain.core.lang.i18n
|
||||
<SelectionSlider>:
|
||||
id: slider
|
||||
canvas:
|
||||
@@ -116,17 +116,17 @@ KV = """
|
||||
md_bg_color: [1, 1, 1, 1] if root.active else [0, 0, 0, 0]
|
||||
elevation: 4 if root.active else 0
|
||||
size:
|
||||
(dp(28), dp(28) if root.active else (dp(20), dp(20)))
|
||||
(max(dp(28), label.texture_size[0]+4) , dp(28))
|
||||
pos:
|
||||
(slider.px_pos - dp(9), slider.center_y - hint_box.height / 2 + dp(30))
|
||||
|
||||
MDLabel:
|
||||
Label:
|
||||
id: label
|
||||
text: slider.values[slider.index][1]
|
||||
font_style: "Caption"
|
||||
font_size: dp(12)
|
||||
lang_change_tracking: i18n._('') # for font
|
||||
halign: "center"
|
||||
color: root.thumb_color if root.active else [0, 0, 0, 0]
|
||||
|
||||
|
||||
"""
|
||||
|
||||
Builder.load_string(KV)
|
||||
+5
-3
@@ -13,6 +13,8 @@
|
||||
|
||||
#:set LIGHTGREY [0.7,0.7,0.7,1]
|
||||
#:import BACKGROUND_COLOR katrain.gui.style.BACKGROUND_COLOR
|
||||
#:import LIGHTER_BACKGROUND_COLOR katrain.gui.style.LIGHTER_BACKGROUND_COLOR
|
||||
#:import LIGHTGREY katrain.gui.style.LIGHTGREY
|
||||
#:import TEXT_COLOR katrain.gui.style.TEXT_COLOR
|
||||
|
||||
|
||||
@@ -371,14 +373,14 @@
|
||||
textbox: textbox
|
||||
SelectionSlider:
|
||||
id: slider
|
||||
size_hint: 3,1
|
||||
size_hint: 2,1
|
||||
values: root.values
|
||||
on_select: textbox.text = str(slider.value)
|
||||
track_color: LIGHTGREY
|
||||
thumb_color: LIGHTER_BACKGROUND_COLOR
|
||||
LabelledFloatInput:
|
||||
id: textbox
|
||||
|
||||
|
||||
|
||||
<ConfigAIPopup>:
|
||||
options_grid: options_grid
|
||||
help_label: help_label
|
||||
|
||||
Reference in new issue
Block a user