Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
f87312f66f | |
![]() |
d4fdc4425c | |
![]() |
186c9e4fe2 | |
![]() |
470e20d50a | |
![]() |
ed2e8c695b |
|
@ -12,7 +12,7 @@ let package = Package(
|
|||
name: "your-project",
|
||||
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: [
|
||||
.target(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Foundation
|
||||
|
||||
extension NSTextCheckingResult {
|
||||
public extension NSTextCheckingResult {
|
||||
func groups(testedString: String) -> [String] {
|
||||
return (0 ..< self.numberOfRanges).map {
|
||||
(testedString as NSString).substring(with: self.range(at: $0))
|
||||
|
|
|
@ -10,10 +10,10 @@ import Foundation
|
|||
|
||||
/// Cursor to traverse SGF collection
|
||||
open class SGFCursor {
|
||||
let collection: [SGFNode]
|
||||
var current: SGFNode?
|
||||
var history = [SGFNode]()
|
||||
var moveNumber: Int {
|
||||
public let collection: [SGFNode]
|
||||
public var current: SGFNode?
|
||||
public var history = [SGFNode]()
|
||||
public var moveNumber: Int {
|
||||
get {
|
||||
return history.count
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ open class SGFCursor {
|
|||
return c
|
||||
}
|
||||
|
||||
func toSgf() -> String {
|
||||
open func toSgf() -> String {
|
||||
var root: SGFNode?
|
||||
if let copied: SGFNode = history.reduce(nil, { parent, node in
|
||||
let copied = SGFNode()
|
||||
|
@ -120,4 +120,11 @@ open class SGFCursor {
|
|||
}
|
||||
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 var debugDescription: String {
|
||||
public extension SGFNode: CustomDebugStringConvertible {
|
||||
var debugDescription: String {
|
||||
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
|
||||
- Parameter sgf: SGF string
|
||||
|
|
Loading…
Reference in New Issue