This commit is contained in:
Sander Land committed 2020-04-19 17:31:06 +02:00
1 parent 3f8e15f36c
commit 0f8393bb2e
15 files changed
+351 -305

No files matched your search

+3 -4
View File
@@ -1,12 +1,11 @@
This repository includes: This repository includes:
1. binaries for 'KataGo', which is Copyright 2019 David J Wu et al. 1. Binaries for 'KataGo', which is Copyright 2019 David J Wu et al.
For on related licenses for these binaries and libraries see https://github.com/lightvector/KataGo For on related licenses for these binaries and libraries see https://github.com/lightvector/KataGo
2. Icons from www.flaticon.com 2. Icons from www.flaticon.com, used with permission with the following attributions:
- New game/Load game/Config icons: made by Freepik from www.flaticon.com - New game/Load game/Config icons: made by Freepik from www.flaticon.com
- Save icon: made by Pixel perfect from www.flaticon.com - Save icon: made by Pixel perfect from www.flaticon.com
- Next/Previous icon: made by RoundIcons from www.flaticon.com - other next/previous icons are derived work.
Aside from the above, the license for all other content in this repository is as follows: Aside from the above, the license for all other content in this repository is as follows:
+1 -1
View File
@@ -202,7 +202,7 @@ class Game:
# select move # select move
ai_moves = self.current_node.candidate_moves ai_moves = self.current_node.candidate_moves
pos_moves = [ pos_moves = [
[d["move"], d["scoreLead"], d["pointsLost"]] for i, d in enumerate(ai_moves) if i == 0 or int(d["visits"]) >= self.config["balance_play_min_visits"] [d["move"], d["scoreLead"], d["pointsLost"]] for i, d in enumerate(ai_moves) if i == 0 or int(d["visits"]) >= train_settings["balance_play_min_visits"]
] # TODO: lcb based ? ] # TODO: lcb based ?
sel_moves = pos_moves[:1] sel_moves = pos_moves[:1]
# don't play suicidal to balance score - pass when it's best # don't play suicidal to balance score - pass when it's best
+309 -267
View File
@@ -33,13 +33,25 @@
button_color: 0.71, 0.78, 0.81, 1 button_color: 0.71, 0.78, 0.81, 1
icon_margin: 0.15 * self.size[0] icon_margin: 0.15 * self.size[0]
icon: 'missing.png' icon: 'missing.png'
icon_size: min(self.size[0]-2*self.margin[0]-2*self.icon_margin,self.size[1]-2*self.margin[1]-2*self.icon_margin) icon_size: min(self.size[0]-self.margin[0]-self.margin[2]-2*self.icon_margin,self.size[1]-self.margin[1]-self.margin[3]-2*self.icon_margin)
#EffectWidget: effects: [ew.FXAAEffect()] #EffectWidget: effects: [ew.FXAAEffect()]
Image: Image:
size: (root.icon_size or 0,root.icon_size or 0) # square size: (root.icon_size or 0,root.icon_size or 0) # square
pos: [root.pos[i] + (root.size[i] - root.icon_size)/2 for i in [0,1]] if root.icon_size else [0,0] pos: [root.pos[i] + (root.size[i] - root.icon_size)/2 for i in [0,1]] if root.icon_size else [0,0]
source: root.icon source: root.icon
<TransparentIconButton@Button>
background_normal: ''
background_color: (0,0,0,0)
margin: (1,1,1,1)
icon_size: min(self.size[0]-self.margin[0]-self.margin[2],self.size[1]-self.margin[1]-self.margin[3])
icon: 'missing.png'
Image:
size: (root.icon_size or 0,root.icon_size or 0) # square
pos: [root.pos[i] + (root.size[i] - root.icon_size)/2 for i in [0,1]] if root.icon_size else [0,0]
source: root.icon
<DarkLabel@Label>: <DarkLabel@Label>:
color: (0.05,0.05,0.05,1) color: (0.05,0.05,0.05,1)
@@ -99,7 +111,6 @@
active: root.default_active active: root.default_active
on_active: root.dispatch('on_active') on_active: root.dispatch('on_active')
# TODO no need for this anymore
<CensorableLabel> <CensorableLabel>
orientation: 'horizontal' orientation: 'horizontal'
text: '' text: ''
@@ -134,39 +145,308 @@
<WhiteCircleWithText@BaseCircleWithText> <WhiteCircleWithText@BaseCircleWithText>
color: 0.05,0.05,0.05,1 color: 0.05,0.05,0.05,1
outline: True
canvas.before:
Color:
rgba: 0.95,0.95,0.95,1
Ellipse:
pos: self.pos[0] + self.width/2 - min(self.height,self.width) * 0.48, self.pos[1] + self.height/2 - min(self.height,self.width) * 0.48
size: min(self.height,self.width) * 0.96, min(self.height,self.width) * 0.96
canvas.after: canvas.after:
Color: Color:
rgba: 0.05,0.05,0.05,1 rgba: 0.05,0.05,0.05,1
Line: Line:
circle: self.pos[0] + self.width/2, self.pos[1] + self.height/2, min(self.height,self.width)*0.45 circle: self.pos[0] + self.width/2, self.pos[1] + self.height/2, min(self.height,self.width)*0.47
width: 1.1 width: 1.1 if root.outline else 0.0001
<BadukPanWidget>:
size: self.parent.height, self.parent.height
katrain: self.parent.parent
<CensorableScoreLabel> <BadukPanControls>:
orientation: 'horizontal' katrain: self.parent.parent
text: '' black_prisoners: black_prisoners
label: '' white_prisoners: white_prisoners
black: black pass_btn: pass_btn
white: white canvas.before:
BlackCircleWithText: Color:
id: black rgb: 0.85, 0.68, 0.40
size_hint: 0.15,1 Rectangle:
text: '0' pos: root.pos
CheckBoxHintLabel: size: root.size
size_hint: 0.3,1 Label:
text: root.label size_hint: 0.05, 1
font_size: self.height * 0.6 StyledButton:
on_press: value.opacity = 1 if value.opacity==0 else 0 text: 'Pass'
WhiteCircleWithText: id: pass_btn
id: white on_press: root.katrain("play",None)
size_hint: 0.15,1 size_hint: 0.1, 1
text: '0' margin: (0, self.size[1]/5, 0, self.size[1]/5)
DarkLabel: Label:
size_hint: 0.4,1 size_hint: 0.1, 1
text: root.text TransparentIconButton:
font_size: self.height * 0.6 icon: 'img/flaticon/previous999.png'
id: value margin: (3, self.size[1]/3, 3, self.size[1]/3)
bold: True size_hint: 0.1, 1
on_press: root.katrain('undo',999)
TransparentIconButton:
icon: 'img/flaticon/previous5.png'
margin: (3, self.size[1]/3, 3, self.size[1]/3)
size_hint: 0.1, 1
on_press: root.katrain('undo',5)
TransparentIconButton:
icon: 'img/flaticon/previous.png'
margin: (3, self.size[1]/3, 3, self.size[1]/3)
size_hint: 0.1, 1
on_press: root.katrain('undo')
BoxLayout:
size_hint: 0.25, 1
BlackCircleWithText:
id: black_prisoners
size_hint: 0.3,1
text: '0'
WhiteCircleWithText:
id: white_prisoners
size_hint: 0.3,1
text: '0'
outline: False
TransparentIconButton:
icon: 'img/flaticon/next.png'
margin: (3, self.size[1]/3, 3, self.size[1]/3)
size_hint: 0.1, 1
on_press: root.katrain('redo')
TransparentIconButton:
icon: 'img/flaticon/next5.png'
margin: (3, self.size[1]/3, 3, self.size[1]/3)
size_hint: 0.1, 1
on_press: root.katrain('redo',5)
TransparentIconButton:
icon: 'img/flaticon/next999.png'
margin: (3, self.size[1]/3, 3, self.size[1]/3)
size_hint: 0.1, 1
on_press: root.katrain('redo',999)
Label:
size_hint: 0.25, 1
<Controls>
orientation: 'vertical'
play_tab_button: play_tab_button
analyze_tab_button: analyze_tab_button
info: info
win_rate: win_rate
points_lost: points_lost
score: score
hints: hints
ownership: ownership
policy: policy
eval: eval
ai_balance: ai_balance
ai_auto: ai_auto
ai_fast: ai_fast
ai_lock: ai_lock
ai_move: ai_move
auto_undo: auto_undo
katrain: self.parent
BoxLayout:
size_hint: 1,0.05
orientation: 'horizontal'
StyledToggleButton:
text: 'Analyze'
id: analyze_tab_button
margin: (3,0,1,3)
group: 'tabs'
on_press:
analyze_tab.size_hint[0] = 1
analyze_tab.opacity = 1
play_tab.size_hint_x = None
play_tab.width = 0
play_tab.opacity = 0
self.state = 'down'
StyledToggleButton:
text: 'Play'
group: 'tabs'
state: 'down'
id: play_tab_button
margin: (1,0,3,3)
on_press:
play_tab.size_hint[0] = 1
play_tab.opacity = 1
analyze_tab.size_hint_x = None
analyze_tab.width = 0
analyze_tab.opacity = 0
self.state = 'down'
BoxLayout:
size_hint: 1,0.25
orientation: 'horizontal'
BoxLayout: # ----------- analyze -----------
size_hint: 0,1
id: analyze_tab
opacity: 0
orientation: 'vertical'
GridLayout:
cols: 6
rows: 1
size_hint: 1, 0.35
Label:
size_hint: 0.01, 1
BoxLayout:
orientation: 'vertical'
size_hint: 0.1, 0.5
Label:
size_hint: 1, 0.2
BlackCircleWithText:
text: 'B'
WhiteCircleWithText:
text: 'W'
BWCheckBoxHint:
size_hint: 0.2, 0.5
id: eval
text: 'all eval'
default_active: False
on_active: root.katrain.update_state()
BWCheckBoxHint:
size_hint: 0.2, 0.5
id: hints
text: 'top move'
on_active: root.katrain.update_state()
CheckBoxHint:
size_hint: 0.2, 0.5
id: ownership
text: 'show\nowner'
on_active: root.katrain.update_state()
CheckBoxHint:
size_hint: 0.2, 0.5
id: policy
text: 'show\npolicy'
on_active: root.katrain.update_state()
LargeLabel:
text: 'graph?'
size_hint: 1,0.75
CensorableLabel:
id: win_rate
size_hint: 1, 0.15
label: 'Win rate'
text: '...'
CensorableLabel:
id: score
size_hint: 1, 0.15
label: 'Score'
text: '...'
BoxLayout: # ----------- play -----------
orientation: 'vertical'
size_hint: 1,1
opacity: 1
id: play_tab
GridLayout:
cols: 5
rows: 1
size_hint: 1, 0.1
BoxLayout:
orientation: 'vertical'
size_hint: 0.1, 0.5
Label:
size_hint: 1, 0.2
BlackCircleWithText:
text: 'B'
WhiteCircleWithText:
text: 'W'
BWCheckBoxHint:
text: 'ai'
id: ai_auto
default_active: False
size_hint: 0.25, 1
BWCheckBoxHint:
size_hint: 0.2, 0.5
id: auto_undo
text: 'undo'
on_active: root.katrain.update_state()
CheckBoxHint:
size_hint: 0.25, 1
text: 'fast'
id: ai_fast
default_active: True
CheckBoxHint:
size_hint: 0.25, 1
text: 'balance\nscore'
id: ai_balance
default_active: False
GridLayout:
cols: 4
rows: 1
size_hint: 1, 0.1
StyledButton:
id: ai_move
size_hint: 0.5, 0.5
text: ' AI\nMove'
on_press: root.katrain("ai_move")
CheckBoxHint:
size_hint: 0.25, 1
text: 'lock\nAI'
id: ai_lock
on_active: self.checkbox.disabled = analyze_tab_button.disabled = ai_auto.white = ai_auto.black = ai_move.disabled = True
LargeLabel:
text: 'free real estate'
size_hint: 1,0.2
CensorableLabel:
id: points_lost
size_hint: 1, 0.03
label: 'Point loss'
text: '...'
GridLayout:
cols: 2
rows: 1
size_hint: 1, 0.05
TextInput:
id: info
size_hint: 1, 0.2
valign: 'middle'
BoxLayout:
orientation: 'horizontal'
size_hint: 1, None
height: self.width * 0.25
StyledIconButton:
icon: 'img/flaticon/go-game.png'
size_hint: 0.25, 1
on_press: root.katrain("new-game-popup")
StyledIconButton:
icon: 'img/flaticon/open-folder.png'
size_hint: 0.25, 1
on_press: root.katrain("analyze-sgf-popup")
StyledIconButton:
icon: 'img/flaticon/bar.png'
size_hint: 0.25, 1
on_press: root.katrain('output-sgf')
StyledIconButton:
icon: 'img/flaticon/gears.png'
size_hint: 0.25, 1
on_press: root.katrain('config-popup')
<KaTrainGui>:
board_gui: board_gui
controls: controls
board_controls: board_controls
board_aspect_ratio: 1.075
canvas.before:
Color:
rgba: 0.95, 0.95, 0.95, 1
Rectangle:
pos: self.pos
size: root.size
BoxLayout:
orientation: 'vertical'
size_hint: 1 - controls.size_hint[0], 1
BadukPanWidget:
id: board_gui
size_hint: (1,1)
BadukPanControls:
id: board_controls
size_hint: (1,root.board_aspect_ratio-1)
Controls:
id: controls
size_hint: max(0.25,(root.width - root.height/root.board_aspect_ratio)/root.width), 1
<LoadSGFPopup>: <LoadSGFPopup>:
@@ -260,241 +540,3 @@
size_hint: 0.5, 0.1 size_hint: 0.5, 0.1
text: 'Start Game' text: 'Start Game'
on_press: root.new_game() on_press: root.new_game()
<BadukPanWidget>:
size: self.parent.height, self.parent.height
katrain: self.parent.parent
<Controls>
orientation: 'vertical'
play_tab_button: play_tab_button
analyze_tab_button: analyze_tab_button
info: info
win_rate: win_rate
points_lost: points_lost
score: score
hints: hints
ownership: ownership
policy: policy
eval: eval
ai_balance: ai_balance
ai_auto: ai_auto
ai_fast: ai_fast
ai_lock: ai_lock
ai_move: ai_move
auto_undo: auto_undo
pass_btn: pass_btn
katrain: self.parent
BoxLayout:
size_hint: 1,0.05
orientation: 'horizontal'
StyledToggleButton:
text: 'Analyze'
id: analyze_tab_button
margin: (3,0,1,3)
group: 'tabs'
on_press:
analyze_tab.size_hint[0] = 1
analyze_tab.opacity = 1
play_tab.size_hint_x = None
play_tab.width = 0
play_tab.opacity = 0
self.state = 'down'
StyledToggleButton:
text: 'Play'
group: 'tabs'
state: 'down'
id: play_tab_button
margin: (1,0,3,3)
on_press:
play_tab.size_hint[0] = 1
play_tab.opacity = 1
analyze_tab.size_hint_x = None
analyze_tab.width = 0
analyze_tab.opacity = 0
self.state = 'down'
BoxLayout:
size_hint: 1,0.25
orientation: 'horizontal'
BoxLayout: # ----------- analyze -----------
size_hint: 0,1
id: analyze_tab
opacity: 0
orientation: 'vertical'
GridLayout:
cols: 6
rows: 1
size_hint: 1, 0.35
Label:
size_hint: 0.01, 1
BoxLayout:
orientation: 'vertical'
size_hint: 0.1, 0.5
Label:
size_hint: 1, 0.2
BlackCircleWithText:
text: 'B'
WhiteCircleWithText:
text: 'W'
BWCheckBoxHint:
size_hint: 0.2, 0.5
id: eval
text: 'all eval'
default_active: False
on_active: root.parent.update_state()
BWCheckBoxHint:
size_hint: 0.2, 0.5
id: hints
text: 'top move'
on_active: root.parent.update_state()
CheckBoxHint:
size_hint: 0.2, 0.5
id: ownership
text: 'show\nowner'
on_active: root.parent.update_state()
CheckBoxHint:
size_hint: 0.2, 0.5
id: policy
text: 'show\npolicy'
on_active: root.parent.update_state()
LargeLabel:
text: 'graph?'
size_hint: 1,0.75
CensorableLabel:
id: win_rate
size_hint: 1, 0.15
label: 'Win rate'
text: '...'
CensorableScoreLabel:
id: score
size_hint: 1, 0.15
label: 'Score'
text: '...'
BoxLayout: # ----------- play -----------
orientation: 'vertical'
size_hint: 1,1
opacity: 1
id: play_tab
GridLayout:
cols: 5
rows: 1
size_hint: 1, 0.1
BoxLayout:
orientation: 'vertical'
size_hint: 0.1, 0.5
Label:
size_hint: 1, 0.2
BlackCircleWithText:
text: 'B'
WhiteCircleWithText:
text: 'W'
BWCheckBoxHint:
text: 'ai'
id: ai_auto
default_active: False
size_hint: 0.25, 1
BWCheckBoxHint:
size_hint: 0.2, 0.5
id: auto_undo
text: 'undo'
on_active: root.parent.update_state()
CheckBoxHint:
size_hint: 0.25, 1
text: 'fast'
id: ai_fast
default_active: True
CheckBoxHint:
size_hint: 0.25, 1
text: 'balance\nscore'
id: ai_balance
default_active: False
GridLayout:
cols: 4
rows: 1
size_hint: 1, 0.1
StyledButton:
id: ai_move
size_hint: 0.5, 0.5
text: ' AI\nMove'
on_press: root.katrain("ai_move")
CheckBoxHint:
size_hint: 0.25, 1
text: 'lock\nAI'
id: ai_lock
on_active: self.checkbox.disabled = analyze_tab_button.disabled = ai_auto.white = ai_auto.black = ai_move.disabled = True
LargeLabel:
text: 'free real estate'
size_hint: 1,0.2
CensorableLabel:
id: points_lost
size_hint: 1, 0.03
label: 'Point loss'
text: '...'
GridLayout:
cols: 2
rows: 1
size_hint: 1, 0.05
StyledButton:
id: undo
text: 'Undo'
on_press: root.katrain("undo")
default_active: True
StyledButton:
text: 'Pass'
id: pass_btn
on_press: root.katrain("play",None)
TextInput:
id: info
size_hint: 1, 0.2
valign: 'middle'
BoxLayout:
orientation: 'horizontal'
size_hint: 1, None
height: self.width * 0.25
StyledIconButton:
icon: 'img/flaticon/go-game.png'
size_hint: 0.25, 1
on_press: root.katrain("new-game-popup")
StyledIconButton:
icon: 'img/flaticon/open-folder.png'
size_hint: 0.25, 1
on_press: root.katrain("analyze-sgf-popup")
StyledIconButton:
icon: 'img/flaticon/bar.png'
size_hint: 0.25, 1
on_press: root.katrain('output-sgf')
StyledIconButton:
icon: 'img/flaticon/gears.png'
size_hint: 0.25, 1
on_press: root.katrain('config-popup')
<BadukPanControls>:
StyledIconButton:
icon: 'img/flaticon/go-game.png'
size_hint: 0.25, 1
on_press: root.katrain("new-game-popup")
<KaTrainGui>:
board_gui: board_gui
controls: controls
board_aspect_ratio: 1.1
canvas.before:
Color:
rgba: 0.95, 0.95, 0.95, 1
Rectangle:
pos: self.pos
size: root.size
BoxLayout:
orientation: 'vertical'
size_hint: 1 - controls.size_hint[0], 1
BadukPanWidget:
id: board_gui
size_hint: (1,1)
BadukPanControls:
id: board_controls
size_hint: (1,root.board_aspect_ratio-1)
Controls:
id: controls
size_hint: max(0.25,(root.width - root.height/root.board_aspect_ratio)/root.width), 1
-1
View File
@@ -3,7 +3,6 @@ from gui.controls import Controls
from gui.kivyutils import ( from gui.kivyutils import (
BWCheckBoxHint, BWCheckBoxHint,
CensorableLabel, CensorableLabel,
CensorableScoreLabel,
CheckBoxHint, CheckBoxHint,
LabelledFloatInput, LabelledFloatInput,
LabelledIntInput, LabelledIntInput,
+20 -18
View File
@@ -29,8 +29,8 @@ class BadukPanWidget(Widget):
def on_touch_down(self, touch): def on_touch_down(self, touch):
if not self.gridpos_x: if not self.gridpos_x:
return return
xd, xp = self._find_closest(touch.x,self.gridpos_x) xd, xp = self._find_closest(touch.x, self.gridpos_x)
yd, yp = self._find_closest(touch.y,self.gridpos_y) yd, yp = self._find_closest(touch.y, self.gridpos_y)
prev_ghost = self.ghost_stone prev_ghost = self.ghost_stone
if max(yd, xd) < self.grid_size / 2 and (xp, yp) not in [m.coords for m in self.katrain.game.stones]: if max(yd, xd) < self.grid_size / 2 and (xp, yp) not in [m.coords for m in self.katrain.game.stones]:
self.ghost_stone = (xp, yp) self.ghost_stone = (xp, yp)
@@ -49,8 +49,8 @@ class BadukPanWidget(Widget):
if self.ghost_stone: if self.ghost_stone:
katrain("play", self.ghost_stone) katrain("play", self.ghost_stone)
else: else:
xd, xp = self._find_closest(touch.x,self.gridpos_x) xd, xp = self._find_closest(touch.x, self.gridpos_x)
yd, yp = self._find_closest(touch.y,self.gridpos_y) yd, yp = self._find_closest(touch.y, self.gridpos_y)
nodes_here = [node for node in katrain.game.current_node.nodes_from_root if node.single_move and node.single_move.coords == (xp, yp)] nodes_here = [node for node in katrain.game.current_node.nodes_from_root if node.single_move and node.single_move.coords == (xp, yp)]
if nodes_here and max(yd, xd) < self.grid_size / 2: # load old comment if nodes_here and max(yd, xd) < self.grid_size / 2: # load old comment
@@ -101,12 +101,12 @@ class BadukPanWidget(Widget):
self.canvas.before.clear() self.canvas.before.clear()
with self.canvas.before: with self.canvas.before:
# board # board
sz = min(self.width, self.height) board_px_size = min(self.width, self.height)
Color(*self.ui_config["board_color"]) Color(*self.ui_config["board_color"])
board_rectangle = Rectangle(pos=self.pos, size=(sz, sz)) Rectangle(pos=self.pos, size=(self.width, self.height))
# grid lines # grid lines
margin = 1.5 margin = 1.5
self.grid_size = board_rectangle.size[0] / (board_size - 1 + 1.5 * margin) self.grid_size = board_px_size / (board_size - 1 + 1.5 * margin)
self.stone_size = self.grid_size * self.ui_config["stone_size"] self.stone_size = self.grid_size * self.ui_config["stone_size"]
self.gridpos_x = [self.pos[0] + math.floor((margin + i) * self.grid_size + 0.5) for i in range(board_size)] self.gridpos_x = [self.pos[0] + math.floor((margin + i) * self.grid_size + 0.5) for i in range(board_size)]
self.gridpos_y = [self.pos[1] + math.floor((margin + i) * self.grid_size + 0.5) for i in range(board_size)] self.gridpos_y = [self.pos[1] + math.floor((margin + i) * self.grid_size + 0.5) for i in range(board_size)]
@@ -114,8 +114,8 @@ class BadukPanWidget(Widget):
line_color = self.ui_config["line_color"] line_color = self.ui_config["line_color"]
Color(*line_color) Color(*line_color)
for i in range(board_size): for i in range(board_size):
Line(points=[(self.gridpos_x[i], self.gridpos_y[0]), (self.gridpos_x[i], self.gridpos_y[-1])]) Line(points=[(self.gridpos_x[i], self.gridpos_y[0]), (self.gridpos_x[i], self.gridpos_y[-1])])
Line(points=[( self.gridpos_x[0], self.gridpos_y[i]), ( self.gridpos_x[-1], self.gridpos_y[i])]) Line(points=[(self.gridpos_x[0], self.gridpos_y[i]), (self.gridpos_x[-1], self.gridpos_y[i])])
# star points # star points
star_point_pos = 3 if board_size <= 11 else 4 star_point_pos = 3 if board_size <= 11 else 4
@@ -128,7 +128,7 @@ class BadukPanWidget(Widget):
Color(0.25, 0.25, 0.25) Color(0.25, 0.25, 0.25)
coord_offset = self.grid_size * margin / 2 coord_offset = self.grid_size * margin / 2
for i in range(board_size): for i in range(board_size):
draw_text(pos=(self.gridpos_x[i], self.gridpos_y[0] -coord_offset), text=Move.GTP_COORD[i], font_size=self.grid_size / 1.5) draw_text(pos=(self.gridpos_x[i], self.gridpos_y[0] - coord_offset), text=Move.GTP_COORD[i], font_size=self.grid_size / 1.5)
draw_text(pos=(self.gridpos_x[0] - coord_offset, self.gridpos_y[i]), text=str(i + 1), font_size=self.grid_size / 1.5) draw_text(pos=(self.gridpos_x[0] - coord_offset, self.gridpos_y[i]), text=str(i + 1), font_size=self.grid_size / 1.5)
def draw_board_contents(self, *args): def draw_board_contents(self, *args):
@@ -177,14 +177,15 @@ class BadukPanWidget(Widget):
Rectangle(pos=(self.gridpos_x[x] - rsz / 2, self.gridpos_y[y] - rsz / 2), size=(rsz, rsz)) Rectangle(pos=(self.gridpos_x[x] - rsz / 2, self.gridpos_y[y] - rsz / 2), size=(rsz, rsz))
ix = ix + 1 ix = ix + 1
policy = current_node.policy # likewise for policy, although it makes slightly less sense here
policy = current_node.policy or (current_node.parent and current_node.parent.policy)
if katrain.controls.policy.active and policy and not katrain.controls.ownership.active: if katrain.controls.policy.active and policy and not katrain.controls.ownership.active:
n_legal_moves = sum([p > 0 for p in policy]) n_legal_moves = sum([p > 0 for p in policy])
avg_policy = 1.0 / n_legal_moves avg_policy = 1.0 / n_legal_moves
best_move_policy = max(policy) # num legal moves scale? best_move_policy = max(policy) # num legal moves scale?
rsz = self.grid_size * 0.2 rsz = self.grid_size * 0.2
ix = 0 ix = 0
for y in range(board_size-1,-1,-1): for y in range(board_size - 1, -1, -1):
for x in range(board_size): for x in range(board_size):
if policy[ix] > 0: if policy[ix] > 0:
policy_delta = best_move_policy - policy[ix] policy_delta = best_move_policy - policy[ix]
@@ -193,7 +194,7 @@ class BadukPanWidget(Widget):
Rectangle(pos=(self.gridpos_x[x] - rsz / 2, self.gridpos_y[y] - rsz / 2), size=(rsz, rsz)) Rectangle(pos=(self.gridpos_x[x] - rsz / 2, self.gridpos_y[y] - rsz / 2), size=(rsz, rsz))
ix = ix + 1 ix = ix + 1
policy_delta = best_move_policy - policy[ix] policy_delta = best_move_policy - policy[ix]
katrain.controls.pass_btn.face_color = (*self.eval_color(100*policy_delta),1) katrain.board_controls.pass_btn.face_color = (*self.eval_color(100 * policy_delta), 1)
# children of current moves in undo / review # children of current moves in undo / review
undo_coords = set() undo_coords = set()
@@ -234,11 +235,12 @@ class BadukPanWidget(Widget):
else: else:
text = "pass" text = "pass"
Color(0.45, 0.05, 0.45, 0.5) Color(0.45, 0.05, 0.45, 0.5)
center = (self.pos[0] + self.width/2,self.pos[1]+self.height/2) center = (self.pos[0] + self.width / 2, self.pos[1] + self.height / 2)
size = min(self.width, self.height) * 0.22 size = min(self.width, self.height) * 0.22
Ellipse(pos=(center[0] - size/2, center[1] - size/2), size=(size,size)) Ellipse(pos=(center[0] - size / 2, center[1] - size / 2), size=(size, size))
Color(0.15, 0.15, 0.15) Color(0.15, 0.15, 0.15)
draw_text(pos=center, text=text, font_size=size*0.25, halign="center", outline_color=[0.95, 0.95, 0.95]) draw_text(pos=center, text=text, font_size=size * 0.25, halign="center", outline_color=[0.95, 0.95, 0.95])
class BadukPanControls(BoxLayout): class BadukPanControls(BoxLayout):
pass pass
-1
View File
@@ -38,7 +38,6 @@ class Controls(BoxLayout):
def update_evaluation(self): def update_evaluation(self):
current_node = self.parent.game.current_node current_node = self.parent.game.current_node
move = current_node.single_move move = current_node.single_move
self.score.set_prisoners(self.parent.game.prisoner_count)
current_player_is_human_or_both_robots = True # move not self.ai_auto.active(current_node.player) or self.ai_auto.active(1 - current_node.player) # TODO FIX current_player_is_human_or_both_robots = True # move not self.ai_auto.active(current_node.player) or self.ai_auto.active(1 - current_node.player) # TODO FIX
info = "" info = ""
-9
View File
@@ -107,15 +107,6 @@ class CensorableLabel(BoxLayout):
return self.value.text return self.value.text
class CensorableScoreLabel(BoxLayout):
@property
def text(self):
return self.value.text
def set_prisoners(self, bw):
self.black.text = str(bw[1])
self.white.text = str(bw[0])
def draw_text(pos, text, **kw): def draw_text(pos, text, **kw):
label = CoreLabel(text=text, bold=True, **kw) label = CoreLabel(text=text, bold=True, **kw)
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

+17 -3
View File
@@ -16,9 +16,11 @@ from constants import OUTPUT_DEBUG, OUTPUT_ERROR, OUTPUT_EXTRA_DEBUG, OUTPUT_INF
from engine import KataGoEngine from engine import KataGoEngine
from game import Game, IllegalMoveException, KaTrainSGF, Move from game import Game, IllegalMoveException, KaTrainSGF, Move
from gui import * from gui import *
from gui import LabelledSpinner
from gui.popups import NewGamePopup, ConfigPopup from gui.popups import NewGamePopup, ConfigPopup
from kivy.lang import Builder
class KaTrainGui(BoxLayout): class KaTrainGui(BoxLayout):
"""Top level class responsible for tying everything together""" """Top level class responsible for tying everything together"""
@@ -83,6 +85,11 @@ class KaTrainGui(BoxLayout):
self("ai-move", cn) self("ai-move", cn)
if cn.analysis_ready and self.controls.auto_undo.active(cn.next_player): if cn.analysis_ready and self.controls.auto_undo.active(cn.next_player):
self.game.analyze_undo(cn, self.config("trainer")) # not via message loop self.game.analyze_undo(cn, self.config("trainer")) # not via message loop
prisoners = self.game.prisoner_count
self.board_controls.black_prisoners.text = str(prisoners[1])
self.board_controls.white_prisoners.text = str(prisoners[0])
if redraw_board: if redraw_board:
Clock.schedule_once(self.board_gui.draw_board, -1) # main thread needs to do this Clock.schedule_once(self.board_gui.draw_board, -1) # main thread needs to do this
Clock.schedule_once(self.board_gui.draw_board_contents, -1) Clock.schedule_once(self.board_gui.draw_board_contents, -1)
@@ -246,7 +253,6 @@ class KaTrainApp(App):
def on_start(self): def on_start(self):
self.gui.start() self.gui.start()
signal.signal(signal.SIGINT, self.signal_handler)
def on_request_close(self, *args): def on_request_close(self, *args):
self.gui.engine.shutdown() self.gui.engine.shutdown()
@@ -268,4 +274,12 @@ class KaTrainApp(App):
if __name__ == "__main__": if __name__ == "__main__":
KaTrainApp().run() with open("gui.kv", encoding='utf-8') as f: # avoid windows using another encoding
Builder.load_string(f.read())
app = KaTrainApp()
signal.signal(signal.SIGINT, app.signal_handler)
try:
app.run()
except Exception:
app.on_request_close()
raise
+1 -1
View File
@@ -160,7 +160,7 @@ class SGFNode:
def single_move(self) -> Optional[Move]: def single_move(self) -> Optional[Move]:
"""Returns the single move for the node if one exists, or None if no moves (or multiple ones) exist.""" """Returns the single move for the node if one exists, or None if no moves (or multiple ones) exist."""
moves = self.moves moves = self.moves
if len(moves) == 1: # TODO: and not placements? if len(moves) == 1: # TODO: and not placements?
return moves[0] return moves[0]
@property @property