load sgf file option

This commit is contained in:
Sander Land committed 2020-02-16 20:23:14 +01:00
1 parent f88183f38e
commit 1ab7256b4b
4 files changed
+25 -8

No files matched your search

+2 -1
View File
@@ -71,7 +71,8 @@ Play
* Analysis
* Copy the SGF into the text box. Note that branches are not supported and will lead to strange results.
* Choose whether or not to turn on `fast` to make the AI weaker but analyze faster.
* Click `Analyze`
* Click `Load`
* Alternatively click `Load` when the text box is empty to get a file chooser dialog.
* Save game
* Click save to get an sgf with comments saved in the sgfout/ directory (and a short version in the text box).
+1 -1
View File
@@ -1,5 +1,5 @@
from datetime import datetime
import os
from datetime import datetime
class IllegalMoveException(Exception):
+19 -3
View File
@@ -1,5 +1,6 @@
import copy
import json
import os
import random
import re
import shlex
@@ -9,9 +10,11 @@ import threading
import time
from queue import Queue
from kivy.storage.jsonstore import JsonStore
from kivy.uix.gridlayout import GridLayout
from kivy.clock import Clock
from kivy.storage.jsonstore import JsonStore
from kivy.uix.filechooser import FileChooserListView
from kivy.uix.gridlayout import GridLayout
from kivy.uix.popup import Popup
from board import Board, IllegalMoveException, Move
@@ -182,8 +185,21 @@ class EngineControls(GridLayout):
def _do_analyze_sgf(self, sgf):
sgfprops = {k: v for k, v in re.findall(r"\b(\w+)\[(.*?)\]", sgf)}
size = int(sgfprops.get("SZ", self.board_size))
self._do_init(size, sgfprops.get("KM"))
sgfmoves = re.findall(r"\b([BW])\[([a-z]{2})\]", sgf)
if not sgfmoves and not sgfprops:
fileselect_popup = Popup(title="Double Click SGF file to analyze", size_hint=(0.8, 0.8))
def readfile(files, mouse):
fileselect_popup.dismiss()
with open(files[0]) as f:
self.action("analyze-sgf", f.read())
fc = FileChooserListView(multiselect=False, path=os.path.expanduser("~"), filters=["*.sgf"])
fc.on_submit = readfile
fileselect_popup.add_widget(fc)
fileselect_popup.open()
return
self._do_init(size, sgfprops.get("KM"))
moves = [Move(player=Move.PLAYERS.index(p.upper()), sgfcoords=(mv, self.board_size)) for p, mv in sgfmoves]
handicap = int(sgfprops.get("HA", 0))
self.board.place_handicap_stones(handicap) # not technically correct, should parse AB/AW
+3 -3
View File
@@ -264,11 +264,11 @@
size_hint: 1, 0.05
StyledButton:
text: 'Save'
size_hint: 0.37, 1
size_hint: 0.5, 1
on_press: info.text = root.output_sgf()
StyledButton:
text: 'Analyze'
size_hint: 0.49, 1
text: 'Load'
size_hint: 0.5, 1
margin: (0,1)
on_press: root.action("analyze-sgf",info.text)
GridLayout: