Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next: Support more sgf properties #376

Merged
merged 8 commits into from
Oct 14, 2018

Conversation

zsalch
Copy link
Contributor

@zsalch zsalch commented Oct 3, 2018

Support more sgf properties, such as node properties (TR, SQ, CR, MA, LB, MN and AW/AB/AE of Move) and general properties.

image
image

@OlivierBlanvillain
Copy link
Contributor

@zsalch I just pushed a merge commit to fix the conflicts I introduced in #386. Make sure to pull it before you continue working on this branch...

@zsalch
Copy link
Contributor Author

zsalch commented Oct 7, 2018

Ok, I'll update all unmerge code.

@OlivierBlanvillain
Copy link
Contributor

@zsalch I won't have time to give you a detailed review today (it's coming next ^^'), but I can already tell you that I would like to see some tests for the additional sgf properties you want to support.

@zsalch
Copy link
Contributor Author

zsalch commented Oct 9, 2018

@OlivierBlanvillain
I have added a JUnit test for more sgf properties.

Copy link
Contributor

@OlivierBlanvillain OlivierBlanvillain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @zsalch!

@@ -367,4 +420,158 @@ private static String generateNode(Board board, BoardHistoryNode node) throws IO

return builder.toString();
}

public static boolean isListProperty(String key) {
for (String k : listProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the same as listProps.contains(key). Given that it's so short you might want to remove the method altogether and simply do listProps.contains(key) instead...

Same for isMarkupProperty below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The listProps is a String[]. It seems no contains function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed... What about 'Arrays.asList(listProps).contains(key)`?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think directly loop search should be faster.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not :)
https://gist.github.com/OlivierBlanvillain/266d5176d559a66e47973f321162c770

JVM performance is a complicated subject...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strict! Fixed.

moveY,
LizzieFrame.OpenSansRegularBase,
moves[1],
(float) (stoneRadius * 1.4),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double labelRadius = stoneRadius * 1.4;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

(float) (stoneRadius * 1.4),
(int) (stoneRadius * 1.4));
} else if ("TR".equals(key)) {
// Triangle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove these comments, it's already clear enough from the method name, drawTriangle! (same for the calls below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

public void reopen(int size) {
size = (size == 13 || size == 9) ? size : 19;
if (size != BOARD_SIZE) {
BOARD_SIZE = size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mutate it here it really has to be lower cased: boardSize.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

src/main/java/featurecat/lizzie/rules/SGFParser.java Outdated Show resolved Hide resolved
* @return
*/
public static void addProperties(Map<String, String> props, String propsStr) {
if (propsStr != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment than above, can propsStr ever be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same above

StringBuilder tagBuilder = new StringBuilder();
StringBuilder tagContentBuilder = new StringBuilder();

for (int i = 0; i < propsStr.length(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very low level... Any reason not to use a regular expression?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found a regular expression that can simple process sgf like following.
;CA[gb2312]AB[pe][pq][oq][nq][mq][cp][dq][eq][fp]AW[dc][cf][oc][qo][op][np][mp]
[ep][fq]AP[MultiGo:4.4.4]SZ[19]AB[qd]MULTIGOGM[1]

But maybe can change how to write the "KM[%s]PW[%s]PB[%s]DT[%s]AP[Lizzie: %s]".

}

/**
* Add the properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be useful do document that this done by mutating the props map, same comment for the other added methods in SGFParser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@OlivierBlanvillain
Copy link
Contributor

LGTM, thanks!

@OlivierBlanvillain OlivierBlanvillain merged commit 452fd79 into featurecat:next Oct 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants