Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
f87312f66f | |
![]() |
d4fdc4425c | |
![]() |
186c9e4fe2 | |
![]() |
470e20d50a | |
![]() |
ed2e8c695b |
|
@ -12,7 +12,7 @@ let package = Package(
|
||||||
name: "your-project",
|
name: "your-project",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
...
|
...
|
||||||
.package(url: "https://github.com/y-ich/swift-DDP.git", .branch("master")),
|
.package(url: "https://github.com/y-ich/swift-SGF.git", .branch("master")),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
extension NSTextCheckingResult {
|
public extension NSTextCheckingResult {
|
||||||
func groups(testedString: String) -> [String] {
|
func groups(testedString: String) -> [String] {
|
||||||
return (0 ..< self.numberOfRanges).map {
|
return (0 ..< self.numberOfRanges).map {
|
||||||
(testedString as NSString).substring(with: self.range(at: $0))
|
(testedString as NSString).substring(with: self.range(at: $0))
|
||||||
|
|
|
@ -10,10 +10,10 @@ import Foundation
|
||||||
|
|
||||||
/// Cursor to traverse SGF collection
|
/// Cursor to traverse SGF collection
|
||||||
open class SGFCursor {
|
open class SGFCursor {
|
||||||
let collection: [SGFNode]
|
public let collection: [SGFNode]
|
||||||
var current: SGFNode?
|
public var current: SGFNode?
|
||||||
var history = [SGFNode]()
|
public var history = [SGFNode]()
|
||||||
var moveNumber: Int {
|
public var moveNumber: Int {
|
||||||
get {
|
get {
|
||||||
return history.count
|
return history.count
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ open class SGFCursor {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func toSgf() -> String {
|
open func toSgf() -> String {
|
||||||
var root: SGFNode?
|
var root: SGFNode?
|
||||||
if let copied: SGFNode = history.reduce(nil, { parent, node in
|
if let copied: SGFNode = history.reduce(nil, { parent, node in
|
||||||
let copied = SGFNode()
|
let copied = SGFNode()
|
||||||
|
@ -120,4 +120,11 @@ open class SGFCursor {
|
||||||
}
|
}
|
||||||
return SGFEncoder.encode(collection: [root!])
|
return SGFEncoder.encode(collection: [root!])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open func shallowCopy() -> SGFCursor {
|
||||||
|
let cursor = SGFCursor(collection)
|
||||||
|
cursor.current = current
|
||||||
|
cursor.history = history
|
||||||
|
return cursor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,12 +62,44 @@ public class SGFNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SGFNode: CustomDebugStringConvertible {
|
public extension SGFNode: CustomDebugStringConvertible {
|
||||||
public var debugDescription: String {
|
var debugDescription: String {
|
||||||
return "\(properties), \(children.count) children"
|
return "\(properties), \(children.count) children"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public extension SGFNode {
|
||||||
|
var dimension: (Int, Int)? {
|
||||||
|
get {
|
||||||
|
let sz = self["SZ"]?.first ?? ""
|
||||||
|
let wh = sz.split(separator: ":")
|
||||||
|
switch wh.count {
|
||||||
|
case 0:
|
||||||
|
return (19, 19)
|
||||||
|
case 1:
|
||||||
|
if let size = Int(wh[0]) {
|
||||||
|
return (size, size)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
if let w = Int(wh[0]), let h = Int(wh[1]) {
|
||||||
|
return (w, h)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var komi: Float? {
|
||||||
|
get {
|
||||||
|
return Float(self["KM"]?.first ?? "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
parses a string in SGF
|
parses a string in SGF
|
||||||
- Parameter sgf: SGF string
|
- Parameter sgf: SGF string
|
||||||
|
|
Loading…
Reference in New Issue