Skip to content

Commit

Permalink
1.12 (#557)
Browse files Browse the repository at this point in the history
* add numpy

* fix rotation on new game

* fix wide root zero

* edit INSTALL.md

* force hints on only if starting pondering

* readme

* edit README.md

* Check that the platform is Windows, and the user32 dll has the SetProcessDpiAwarenessContext function (should exist for all versions >= Vista).

Prevents blurry Kivy windows on high dpi displays. Reference: https://stackoverflow.com/questions/71704354/kivy-app-is-blurry-on-windows-with-high-resolution-screen

* Prevents blurry Kivy windows on high dpi displays.

Check that the platform is Windows, and the user32 dll has the SetProcessDpiAwarenessContext function (should exist for all versions >= Vista).

 Reference: https://stackoverflow.com/questions/71704354/kivy-app-is-blurry-on-windows-with-high-resolution-screen

* Use kivy.platform instead of the platform package.

* Fix bug when the board size is not square.

* Set log level back to "warning" (was changed by mistake in a previous commit).

* change pyinstaller icon file paths from fully qualified to relative, pointing to the ico file in the repository

* add VSVersionInfo metadata to Windows executable file from PyInstaller

* replace importLib modules with path modification and regular imports

* Initial code for analysis in move range (not working yet).

* Initial working code for move range analysis. Work in progress, i18n not done.

* Initial working code for move range analysis. Work in progress, i18n not done.

* Get rid of unnecessary code for getting dialog subwidgets.

* Implemented greyed-out inputs when the move range checkbox is not selected.

* Fix spacing which was changed by accident.

* edit katrain/popups.kv, edit katrain/gui/popups.py

* Fix invocation of game analysis.

* Added i18n for the move range analysis. i18n done for Russian.

* TODO removed for Russian.

* Translated remaining Russian strings which were TODO:.

* French strings for move range analysis.

* Change the way analyze_extra is called when move range is specified.

* scale=0 turns off

* allow 3.10

* edit .github/workflows/test.yaml

* Blended territory display (#556)

* Check that the platform is Windows, and the user32 dll has the SetProcessDpiAwarenessContext function (should exist for all versions >= Vista).

Prevents blurry Kivy windows on high dpi displays. Reference: https://stackoverflow.com/questions/71704354/kivy-app-is-blurry-on-windows-with-high-resolution-screen

* Prevents blurry Kivy windows on high dpi displays.

Check that the platform is Windows, and the user32 dll has the SetProcessDpiAwarenessContext function (should exist for all versions >= Vista).

 Reference: https://stackoverflow.com/questions/71704354/kivy-app-is-blurry-on-windows-with-high-resolution-screen

* Changed territory display to be smoothly blended, for player expected territories and for loss in teaching games.

Added an ownership mark to stones while displaying territory; the color of the mark indicates expected ownership, and the size of the mark is proportional to certainty.

* Fixed bug: blended territory display does not work with rotation.

* Revert "Prevents blurry Kivy windows on high dpi displays."

This reverts commit 1cff741.

* Revert "Check that the platform is Windows, and the user32 dll has the SetProcessDpiAwarenessContext function (should exist for all versions >= Vista)."

This reverts commit c9ae4f6.

* Changed territory display to be smoothly blended, for player expected territories and for loss in teaching games.

Added an ownership mark to stones while displaying territory; the color of the mark indicates expected ownership, and the size of the mark is proportional to certainty.

Rebased blended territory display on the 1.12 branch.

* Fixed bug: blended territory display does not work with rotation.

Fixed for non-square board and rebased.

* Revert "Prevents blurry Kivy windows on high dpi displays."

This reverts commit 1cff741.

* Revert "Check that the platform is Windows, and the user32 dll has the SetProcessDpiAwarenessContext function (should exist for all versions >= Vista)."

This reverts commit c9ae4f6.

* Make blended territory work with non-square boards and their rotations.

* Whitespace.

* Make blended territory work with non-square boards and their rotations.

* Change marks on stones from circles to squares.

* Add Theme settings enabling different types of territory and stone marks displays.

* Add Theme settings enabling different types of territory and stone marks displays.

* Reformatted with black -l 120.

* Documentation for territory display styles and themes.

* Added acknowledgement for game used in screenshots.

* spacing

* Some cleanup of Theme variables.

* Switch default mode back to "blended".

* Added screenshot of blended style - weak stone marks.

* Fix bold text.

Co-authored-by: Jacob Minsky <jacob.minsky@gmail.com>

* fix test yaml

* edit spec/file_version.py, edit katrain/core/game.py and 3 other changes

* edit katrain/core/constants.py

* Fixes and enhancements for the blended territory feature. (#564)

* Fix newly placed stone getting transparency before ownership is updated.

* Set black and white territory colors separately.

* Try dimming board when territory display is active.

* Change tint of the board when in territory estimate mode and style is "blended".

* Fix bug when loading SGF with initial position setup.

* Revert "Change tint of the board when in territory estimate mode and style is "blended"."

This reverts commit d5b46c8.

* Marks on stone should be stone colors, not ownership colors - which look bad.

* Version with new board texture (wood6.jpg from https://github.com/waltheri/wgo.js/tree/master/textures) and changed territory color parameters.

* Added gamma-correction to territory coloring.

* Add acknowledgement for board texture.

Co-authored-by: rzcp66 <jacob.minsky@gm.com>

* Remove numpy (#570)

* Fix newly placed stone getting transparency before ownership is updated.

* Set black and white territory colors separately.

* Try dimming board when territory display is active.

* Change tint of the board when in territory estimate mode and style is "blended".

* Fix bug when loading SGF with initial position setup.

* Revert "Change tint of the board when in territory estimate mode and style is "blended"."

This reverts commit d5b46c8.

* Marks on stone should be stone colors, not ownership colors - which look bad.

* Version with new board texture (wood6.jpg from https://github.com/waltheri/wgo.js/tree/master/textures) and changed territory color parameters.

* Added gamma-correction to territory coloring.

* Eliminates numpy; working version with rotation without numpy.

* Fixed stuff related to hover content and board rotation.

* Bug fix for roi selection without numpy.

* Added comment for rot90 implementation with lists.

* Use reversed() instead of [::-1] for clarity.

Co-authored-by: rzcp66 <jacob.minsky@gm.com>

* Fix region of interest display when board is rotated. (#572)

* themes

Co-authored-by: Sander Land <sander@chatdesk.com>
Co-authored-by: Sander Land <sander.land@cognite.com>
Co-authored-by: Jacob Minsky <jacob.minsky@gmail.com>
Co-authored-by: ulty4life <ulty4life@gmail.com>
Co-authored-by: Jacob Minsky <35696962+jacobm-tech@users.noreply.github.com>
Co-authored-by: rzcp66 <jacob.minsky@gm.com>
  • Loading branch information
7 people authored Nov 20, 2022
1 parent 624b348 commit 695f852
Show file tree
Hide file tree
Showing 47 changed files with 712 additions and 205 deletions.
12 changes: 0 additions & 12 deletions .github/FUNDING.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Many thanks to these additional authors:
* "electricRGB" for help with adding configurable keyboard shortcuts.
* "milescrawford" for work on restyling the territory estimate.
* "Funkenschlag1" for capturing stones sound and implementation, and board rotation.
* "waltheri" for one of the wooden board textures.
* Jacob Minsky ("jacobm-tech") for various contributions including analysis move range and improvements to territory display.

## Translators

Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Simply download and run, everything is included.

If you have a working Python 3.6-3.8 available, you should be able to simply:

* Run `pip3 install -U katrain`
* Run `pip3 install -U katrain` to install or upgrade.
* Run the program by executing `katrain` in a terminal.

### <a name="LinuxSources"></a>Installation from sources
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![License:MIT](http://img.shields.io/pypi/l/katrain)](http://en.wikipedia.org/wiki/MIT_License)
[![GitHub Downloads](http://img.shields.io/github/downloads/sanderland/katrain/total?color=%23336699&label=github%20downloads)](http://github.com/sanderland/katrain/releases)
[![PyPI Downloads](http://pepy.tech/badge/katrain)](http://pepy.tech/project/katrain)
[![Github sponsors](http://img.shields.io/static/v1?label=sponsor&message=%E2%9D%A4&logo=GitHub&color=dcb424&link=http://github.com/sponsors/sanderland/)](http://github.com/sponsors/sanderland)
[![Discord](http://img.shields.io/discord/417022162348802048?logo=discord)](http://discord.com/channels/417022162348802048/629446365688365067)

KaTrain is a tool for analyzing games and playing go with AI feedback from KataGo:
Expand Down Expand Up @@ -167,6 +166,7 @@ Keyboard shortcuts are shown with **[key]**.
* **[i]**: Start insertion mode. Allows you to insert moves, to improve analysis when both players ignore an important exchange or life and death situation. Press again to stop inserting and copy the rest of the branch.
* **[l]**: Play out the game until the end and add as a collapsed branch, to visualize the potential effect of mistakes. This is done in the background, and can be started at several nodes at once when comparing the results at different starting positions.
* **[spacebar]**: Turn continuous analysis on/off. This will continuously improve analysis of the current position, similar to Lizzie's 'pondering', but only when there are no other queries going on.
* **[shift+spacebar]**: As above, but does not turn 'top moves' hints on when it is off.
* **[enter]** AI move. Makes the AI move for the current player regardless of current player selection.
* **[F2]**: Deeper full game analysis. Analyze the entire game to a higher number of visits.
* **[F3]**: Performance report. Show an overview of performance statistics for both players.
Expand Down Expand Up @@ -245,7 +245,7 @@ See [these instructions](THEMES.md) for how to modify the look of any graphics o

* Ideas, feedback, and contributions to code or translations are all very welcome.
* For suggestions and planned improvements, see [open issues](http://github.com/sanderland/katrain/issues) on github to check if the functionality is already planned.
* You can contact me on the [Leela Zero & Friends Discord](http://discord.gg/AjTPFpN) (use the #gui channel) to get help, discuss improvements, or simply show your appreciation.
* You can join the [Computer Go Community Discord (formerly Leela Zero & Friends)](http://discord.gg/AjTPFpN) (use the #gui channel) to get help, discuss improvements, or simply show your appreciation. Please do not use github issues to ask for technical help, this is only for bugs, suggestions and discussing contributions.



28 changes: 28 additions & 0 deletions THEMES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@ Version 1.7 brings basic support for themes, and 1.9 extends it to include keybo
* All resources (including icons, which can not be renamed for now) will be looked up in `<home dir>/.katrain` first, so files with identical names there can be used to override sounds and images.
* If variables are specified in multiple theme files, the *latest* alphabetically takes precedence. That is, each later theme file overwrites the settings from any previous one.

## Expected territory options

* KaTrain supports different styles of display of expected territory:
* Blended style colors the board with an intensity proportional to the likelihood of a player controlling that territory at the end of the game.
* In the Marks style, each point of the board is marked with a square of size which is proportional to ownership likelihood.
* The Blocks style divides the whole board into black, white, and neutral territory, based on a likelihood threshold. This style is appropriate as a counting aid, but may be misleading before endgame if much of the territory is unsettled.
* Marks can also appear on stones to indicate the likelihood of these stones living at the end of the game. Three styles are supported:
* All stones can be marked, with the color of the mark indicating the expected ownership and the size of the mark indicating certainty.
* Weak stones only - marks will appear only on stones which are over 50% likely to die before the end of the game.
* No stone marks.

| <img src="https://raw.githubusercontent.com/jacobm-tech/katrain/blended-territory-display/themes/blended-all.png" width="400px"/><br><span style="font-weight:normal">Blended style, all stones marked</span> | <img src="https://raw.githubusercontent.com/jacobm-tech/katrain/blended-territory-display/themes/marks-weak.png" width="400px"/><br><span style="font-weight:normal">Marks on intersections, weak stones marked</span> |
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| <img src="https://raw.githubusercontent.com/jacobm-tech/katrain/blended-territory-display/themes/blocks-none.png" width="400px"/><br>Territory blocks, no stones marked | <img src="https://raw.githubusercontent.com/jacobm-tech/katrain/blended-territory-display/themes/blended-weak.png" width="400px"/><br>Blended territory, weak stones marked |

<sup>The game used in the screenshots is [Albert Yen vs. Eric Yoder](https://www.usgo.org/news/2022/03/members-edition-midwest-open-round-2-the-broken-ladder-game).</sup>

The stone marks and territory style are independent; the table above presents 4 possible variants out of 9.
The relevant variables are:
```
TERRITORY_DISPLAY = "blended" | "marks" | "blocks"
STONE_MARKS = "all" | "weak" | "none"
OWNERSHIP_MAX_ALPHA = 0.7
BLOCKS_THRESHOLD = 0.6
MARK_SIZE = 0.42 # as fraction of stone size
```

## Installation

* To install a theme, simply unzip the theme.zip to your .katrain folder.
Expand Down
21 changes: 15 additions & 6 deletions katrain/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@

os.environ["KCFG_KIVY_LOG_LEVEL"] = os.environ.get("KCFG_KIVY_LOG_LEVEL", "warning")

from kivy.utils import platform as kivy_platform

if kivy_platform == "win":
from ctypes import windll, c_int64

if hasattr(windll.user32, "SetProcessDpiAwarenessContext"):
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))

import kivy

kivy.require("2.0.0")

# next, icon
from katrain.core.utils import find_package_resource, PATHS
from kivy.config import Config
from kivy.utils import platform

ICON = find_package_resource("katrain/img/icon.ico")
Config.set("kivy", "window_icon", ICON)
Expand Down Expand Up @@ -52,7 +59,6 @@
from kivy.clock import Clock
from kivy.metrics import dp
from katrain.core.ai import generate_ai_move
from kivy.utils import platform as kivy_platform

from katrain.core.lang import DEFAULT_LANGUAGE, i18n
from katrain.core.constants import (
Expand Down Expand Up @@ -156,12 +162,14 @@ def handle_animations(self, *_args):
def play_analyze_mode(self):
return self.play_mode.mode

def toggle_continuous_analysis(self):
def toggle_continuous_analysis(self, quiet=False):
if self.contributing:
self.animate_contributing = not self.animate_contributing
else:
if self.pondering:
self.controls.set_status("", STATUS_INFO)
elif not quiet: # See #549
Clock.schedule_once(self.analysis_controls.hints.activate, 0)
self.pondering = not self.pondering
self.update_state()

Expand Down Expand Up @@ -337,7 +345,7 @@ def _do_new_game(self, move_tree=None, analyze_fast=False, sgf_filename=None):
if (move_tree is not None and mode == MODE_PLAY) or (move_tree is None and mode == MODE_ANALYZE):
self.play_mode.switch_ui_mode() # for new game, go to play, for loaded, analyze
self.board_gui.animating_pv = None
self.board_gui.rotation_degree = 0
self.board_gui.reset_rotation()
self.engine.on_new_game() # clear queries
self.game = Game(
self,
Expand Down Expand Up @@ -401,6 +409,7 @@ def _do_resign(self):
def _do_redo(self, n_times=1):
self.board_gui.animating_pv = None
self.game.redo(n_times)

def _do_rotate(self):
self.board_gui.rotate_gridpos()

Expand All @@ -412,7 +421,7 @@ def _do_switch_branch(self, *args):
self.board_gui.animating_pv = None
self.controls.move_tree.switch_branch(*args)

def _play_stone_sound(self,_dt=None):
def _play_stone_sound(self, _dt=None):
play_sound(random.choice(Theme.STONE_SOUNDS))

def _do_play(self, coords):
Expand Down Expand Up @@ -730,7 +739,7 @@ def _on_keyboard_down(self, _keyboard, keycode, _text, modifiers):
return

if keycode[1] == Theme.KEY_TOGGLE_CONTINUOUS_ANALYSIS:
self.toggle_continuous_analysis()
self.toggle_continuous_analysis(quiet=shift_pressed)
elif keycode[1] == Theme.KEY_TOGGLE_COORDINATES:
self.board_gui.toggle_coordinates()
elif keycode[1] in Theme.KEY_PAUSE_TIMER and not ctrl_pressed:
Expand Down
2 changes: 1 addition & 1 deletion katrain/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"anim_pv_time": 0.5,
"debug_level": 0,
"lang": "en",
"version": "1.11.2",
"version": "1.11.3",
"load_fast_analysis": false,
"load_sgf_rewind": true
},
Expand Down
2 changes: 1 addition & 1 deletion katrain/core/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def set_error(a):
extra_settings=extra_settings,
)
while not (error or analysis):
time.sleep(0.01) # TODO: prevent deadlock if esc, check node in queries?
time.sleep(0.01) # TODO: prevent deadlock if esc, check node in queries?
engine.check_alive(exception_if_dead=True)
return analysis

Expand Down
2 changes: 1 addition & 1 deletion katrain/core/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROGRAM_NAME = "KaTrain"
VERSION = "1.11.2"
VERSION = "1.12.0"
HOMEPAGE = "https://github.com/sanderland/katrain"
CONFIG_MIN_VERSION = "1.11.0" # keep config files from this version
ANALYSIS_FORMAT_VERSION = "1.0"
Expand Down
10 changes: 3 additions & 7 deletions katrain/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,11 @@ def _write_stdin_thread(self): # flush only in a thread since it returns only w
if pq.get(k) != query.get(k)
}
if differences:
# TODO:remove
self.katrain.log(f"Found differences in ponder check: {differences}", OUTPUT_EXTRA_DEBUG)
self.stop_pondering()
query["maxVisits"] = 1_000_000
query["maxVisits"] = 10_000_000
query["reportDuringSearchEvery"] = PONDERING_REPORT_DT
self.ponder_query = query
else:
# TODO:remove
self.katrain.log("Found no differences in ponder check, skipping", OUTPUT_EXTRA_DEBUG)
continue

terminate = query.get("action") == "terminate"
Expand Down Expand Up @@ -434,10 +430,10 @@ def request_analysis(
avoid = []

settings = copy.copy(self.override_settings)
settings["wideRootNoise"] = self.config["wide_root_noise"]
if time_limit:
settings["maxTime"] = self.config["max_time"]
if self.config.get("wide_root_noise", 0.0) > 0.0: # don't send if 0.0, so older versions don't error
settings["wideRootNoise"] = self.config["wide_root_noise"]

query = {
"rules": self.get_rules(analysis_node.ruleset),
"priority": self.base_priority + priority,
Expand Down
22 changes: 18 additions & 4 deletions katrain/core/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,6 @@ def analyze_extra(self, mode, **kwargs):
return

engine = self.engines[cn.next_player]
Clock.schedule_once(self.katrain.analysis_controls.hints.activate, 0)

if mode == "ponder":
cn.analyze(
Expand All @@ -602,6 +601,10 @@ def analyze_extra(self, mode, **kwargs):
if mode == "game":
nodes = self.root.nodes_in_tree
only_mistakes = kwargs.get("mistakes_only", False)
move_range = kwargs.get("move_range", None)
if move_range:
if move_range[1] < move_range[0]:
move_range = reversed(move_range)
threshold = self.katrain.config("trainer/eval_thresholds")[-4]
if "visits" in kwargs:
visits = kwargs["visits"]
Expand All @@ -610,9 +613,20 @@ def analyze_extra(self, mode, **kwargs):
visits = min_visits + engine.config["max_visits"]
for node in nodes:
max_point_loss = max(c.points_lost or 0 for c in [node] + node.children)
if not only_mistakes or max_point_loss > threshold:
node.analyze(engine, visits=visits, priority=-1_000_000, time_limit=False, report_every=None)
self.katrain.controls.set_status(i18n._("game re-analysis").format(visits=visits), STATUS_ANALYSIS)
if only_mistakes and max_point_loss <= threshold:
continue
if move_range and (not node.depth - 1 in range(move_range[0], move_range[1] + 1)):
continue
node.analyze(engine, visits=visits, priority=-1_000_000, time_limit=False, report_every=None)
if not move_range:
self.katrain.controls.set_status(i18n._("game re-analysis").format(visits=visits), STATUS_ANALYSIS)
else:
self.katrain.controls.set_status(
i18n._("move range analysis").format(
start_move=move_range[0], end_move=move_range[1], visits=visits
),
STATUS_ANALYSIS,
)
return

elif mode == "sweep":
Expand Down
2 changes: 1 addition & 1 deletion katrain/core/sgf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def player(self):
def place_handicap_stones(self, n_handicaps, tygem=False):
board_size_x, board_size_y = self.board_size
if min(board_size_x, board_size_y) < 3:
return # No
return # No
near_x = 3 if board_size_x >= 13 else min(2, board_size_x - 1)
near_y = 3 if board_size_y >= 13 else min(2, board_size_y - 1)
far_x = board_size_x - 1 - near_x
Expand Down
1 change: 1 addition & 0 deletions katrain/gui.kv
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@
size_hint: None, 0.7
pos_hint: {'center_y':0.5}
checkbox: checkbox
label: label
ClickableLabel:
id: label
text: root.text
Expand Down
Loading

0 comments on commit 695f852

Please sign in to comment.