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

White/Black rank converter #208

Closed
wants to merge 6 commits into from
Closed

White/Black rank converter #208

wants to merge 6 commits into from

Conversation

Brandf3
Copy link
Contributor

@Brandf3 Brandf3 commented Jan 23, 2021

Fixes #182

@Brandf3 Brandf3 requested a review from a team as a code owner January 23, 2021 07:41
@Brandf3 Brandf3 requested review from a team, artasparks and TrevorPeters and removed request for a team January 23, 2021 07:41
Scope: RootScope,
From: func(n *movetree.Node, prop string, data []string) error {
if len(data) != 1 {
return fmt.Errorf("%s propertie requires exactly 1 value, but had %d", prop, len(data))
Copy link
Member

Choose a reason for hiding this comment

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

nit: properie => property

},
}

func isValid(rank string) error {
Copy link
Member

Choose a reason for hiding this comment

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

I would rename this as isValidRank, since this exists in the package-namespace. So, if another file had isValid, it would confilct

@@ -0,0 +1,220 @@
package prop
Copy link
Member

Choose a reason for hiding this comment

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

Nice tests.

@@ -17,6 +17,10 @@ type GameInfo struct {

// Initial player turn. This is traditionally the player with the black stones
Player color.Color

// Ranks of both players. Between 1-30k/kyu, 1-9d/dan, or 1-9p/pro
WhiteRank string
Copy link
Member

Choose a reason for hiding this comment

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

Comments should have the format
"WhiteRank is the rank of the white player."
"blackRank is the rank of the black player."

Try running golint ./...

if err != nil {
return "", err
}
out.WriteString("BR[" + rank + "]")
Copy link
Member

Choose a reason for hiding this comment

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

nit: string builder is a bit of overkill if you're only constructing the string once.


func isValidRank(rank string) error {
// Check that rank ends with a valid string
r, _ := regexp.Compile("(k|kyu|d|dan|p|pro)\\b")
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend putting this outside the method:

var rankRegexp = regexp.MustCompile(...)

I wonder whether this is overkill though. Well, we can profile later.

},
}

func isValidRank(rank string) error {
Copy link
Member

Choose a reason for hiding this comment

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

I just re-read over the spec. https://www.red-bean.com/sgf/properties.html#BR

BR and WR are just simpletext. There are conventions, but I don't think we can guarantee the format. So, rather than being restrictive, I think we should probably remove the intensive validation and just do the basic validation.

@Brandf3 Brandf3 closed this Apr 5, 2021
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.

Add a converter for Black Rank / White Rank
2 participants