This commit is contained in:
Sander Land committed 2020-04-26 19:42:01 +02:00
1 parent edd4eea5b5
commit ba0a1548ee
12 files changed
+127 -76

No files matched your search

+13 -4
View File
@@ -1,6 +1,9 @@
from kivy.graphics.context_instructions import Color
from kivy.graphics.vertex_instructions import Line, SmoothLine
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from gui.popups import ConfigAIPopup
class Controls(BoxLayout):
@@ -31,7 +34,7 @@ class Controls(BoxLayout):
return self.player_mode_groups[player].value
def ai_mode(self, player):
return self.ai_mode_groups[player].text.lower()
return self.ai_mode_groups[player].text
def on_size(self, *args):
self.update_evaluation()
@@ -60,13 +63,19 @@ class Controls(BoxLayout):
self.score.text = current_node.format_score()
self.win_rate.text = current_node.format_win_rate()
if move and next_player_is_human_or_both_robots: # don't immediately hide this when an ai moves comes in
self.score_change.label = f"Score change"
points_lost = current_node.points_lost
self.score_change.text = f"{move.player}{-current_node.points_lost:+.1f}" if points_lost else "..."
self.score_change.label = f"Points lost for {move.player}" if points_lost and points_lost > 0 else f"Points gained for {move.player}"
self.score_change.text = f"{abs(points_lost):.1f}" if points_lost else "..."
elif not current_player_is_ai_playing_human:
self.score_change.label = f"Score change"
self.score_change.label = f"Points lost"
self.score_change.text = ""
self.graph.update_value(current_node)
self.info.text = info
def configure_ais(self):
config_popup = Popup(title="Edit AI Settings", size_hint=(0.9, 0.9))
popup_contents = ConfigAIPopup(self.katrain, config_popup, {self.ai_mode("B"), self.ai_mode("W")})
config_popup.add_widget(popup_contents)
config_popup.open()
+37 -13
View File
@@ -23,6 +23,19 @@ class QuickConfigGui(BoxLayout):
if initial_values:
self.set_properties(self, initial_values)
@staticmethod
def type_to_widget_class(value):
if isinstance(value, float):
return LabelledFloatInput
elif isinstance(value, bool):
return LabelledCheckBox
elif isinstance(value, int):
return LabelledIntInput
if isinstance(value, dict):
return LabelledObjectInputArea
else:
return LabelledTextInput
def collect_properties(self, widget):
if isinstance(widget, (LabelledTextInput, LabelledSpinner, LabelledCheckBox)):
try:
@@ -69,19 +82,6 @@ class NewGamePopup(QuickConfigGui):
class ConfigPopup(QuickConfigGui):
@staticmethod
def type_to_widget_class(value):
if isinstance(value, float):
return LabelledFloatInput
elif isinstance(value, bool):
return LabelledCheckBox
elif isinstance(value, int):
return LabelledIntInput
if isinstance(value, dict):
return LabelledObjectInputArea
else:
return LabelledTextInput
def __init__(self, katrain, popup, config, ignore_cats):
self.config = config
self.ignore_cats = ignore_cats
@@ -157,3 +157,27 @@ class ConfigPopup(QuickConfigGui):
self.katrain.debug_level = self.config["debug"]["level"]
self.katrain.update_state(redraw_board=True)
class ConfigAIPopup(QuickConfigGui):
def __init__(self, katrain, popup, ai_modes, **kwargs):
self.settings = self.katrain.ai_settings
super().__init__(katrain, popup, self.settings, **kwargs)
self.ai_modes = ai_modes
Clock.schedule_once(self._build, 0)
def _build(self):
for mode in self.ai_modes:
mode_settings = self.settings[mode]
column = GridLayout(rows=2 + len(mode_settings), columns=2, size_hint=(0.5, 1))
column.add_widget(ScaledLightLabel(text=f"Settings for AI {mode}", bold=True))
for k, v in mode_settings.items():
column.add_widget(ScaledLightLabel(text=f"{k}"))
column.add_widget(ConfigPopup.type_to_widget_class(v)(text=str(v), input_property=f"{mode}/{k}"))
column.add_widget(Label(text=f"Settings for AI {mode}", bold=True))
self.add_widget(column)
def on_submit(self):
self.popup.dismiss()