sgf-0.1.2: SGF (Smart Game Format) parser

Safe HaskellSafe-Inferred

Data.SGF.Types

Contents

Description

Types used to represent an SGF tree. Whenever a data type is used by exactly one other data type, there will be a "see also" link to its containing type.

Synopsis

Game type

data Game Source

See also Collection.

Constructors

Game 

Fields

application :: Maybe (Application, Version)

The name and version number of the application used to create this game. The version number must be in a format that allows ordinary string comparison to tell which version is higher or lower. Neither the application name nor the version number may have newlines. See also http://www.red-bean.com/sgf/properties.html#AP

variationType :: Maybe (VariationType, AutoMarkup)

The first argument tells whether children (False) or siblings (True) are variations; the second argument tells whether or not to show board markup when variations are available. See also http://www.red-bean.com/sgf/properties.html#ST

size :: Maybe (Integer, Integer)

The size of the board. For games with a default board size, this is guaranteed to be a Just. See also http://www.red-bean.com/sgf/properties.html#SZ

tree :: GameTree

The actual game tree.

Instances

data GameTree Source

See also Game.

Constructors

TreeGo TreeGo 
TreeBackgammon TreeBackgammon 
TreeLinesOfAction TreeLinesOfAction 
TreeHex [(ViewerSetting, Bool)] TreeHex

Applications can store and read settings in the first argument here. This got totally shoehorned into the spec by some particular viewer, I'm sure, but it's in the spec now, so there we go. See also http://www.red-bean.com/sgf/hex.html#IS

TreeOcti TreeOcti 
TreeOther GameType TreeOther 

data GameNode move stone ruleSet extraGameInfo extraAnnotation Source

See also GameTree.

Constructors

GameNode 

Fields

gameInfo :: Maybe (GameInfo ruleSet extraGameInfo)

All properties with propertytype game-info. There must be only one Just on any path within a GameTree.

action :: Either (Setup stone) (Move move)

All properties with propertytype setup or move.

annotation :: Annotation extraAnnotation

Positional judgments and comments (as opposed to judgments of particular moves). All properties covered in the "Node annotation" section.

markup :: Markup

How a node should be displayed. All properties covered in the "Markup" and "Miscellaneous" sections.

unknown :: Map String [[Word8]]

Unspecified properties. The keys in the map must contain only the characters A-Z (and must be upper-case). The values in the map may be more or less arbitrary, but any occurrence of the ASCII byte ']' must be preceded by an odd number of copies of the ASCII byte '\'. See also http://www.red-bean.com/sgf/sgf4.html#2.2

Instances

(Eq move, Eq stone, Eq ruleSet, Eq extraGameInfo, Eq extraAnnotation) => Eq (GameNode move stone ruleSet extraGameInfo extraAnnotation) 
(Ord move, Ord stone, Ord ruleSet, Ord extraGameInfo, Ord extraAnnotation) => Ord (GameNode move stone ruleSet extraGameInfo extraAnnotation) 
(Ord stone, Read move, Read stone, Read ruleSet, Read extraGameInfo, Read extraAnnotation) => Read (GameNode move stone ruleSet extraGameInfo extraAnnotation) 
(Show move, Show stone, Show ruleSet, Show extraGameInfo, Show extraAnnotation) => Show (GameNode move stone ruleSet extraGameInfo extraAnnotation) 

data Move move Source

See also GameNode.

Constructors

Move 

Fields

move :: Maybe (Color, move)

The given move should be executed, whether it is illegal or not. See also the B and W properties at http://www.red-bean.com/sgf/properties.html#B

illegal :: FuzzyBool

When set to Definitely, the current move is acknowledged to be illegal. When set to Possibly, the move may be legal or illegal. See also http://www.red-bean.com/sgf/properties.html#KO

number :: Maybe Integer

When Just, set the current move number. See also http://www.red-bean.com/sgf/properties.html#MN

quality :: Maybe Quality

An annotation telling the quality of the current move. This annotation makes no bigger-picture positional judgments; for those, see Annotation. See also the BM, DO, IT, and TE properties at http://www.red-bean.com/sgf/properties.html#BM

timeBlack :: Maybe Rational

Time remaining, in seconds, for the black player after this move was made. See also http://www.red-bean.com/sgf/properties.html#BL

timeWhite :: Maybe Rational

Time remaining, in seconds, for the white player after this move was made. See also http://www.red-bean.com/sgf/properties.html#WL

overtimeMovesBlack :: Maybe Integer

Number of overtime moves left for the black player after this move was made. See also http://www.red-bean.com/sgf/properties.html#OB

overtimeMovesWhite :: Maybe Integer

Number of overtime moves left for the white player after this move was made. See also http://www.red-bean.com/sgf/properties.html#OW

Instances

Eq move => Eq (Move move) 
Ord move => Ord (Move move) 
Read move => Read (Move move) 
Show move => Show (Move move) 

data Setup stone Source

See also GameNode. Setup nodes are distinct from Move nodes in that they need not correspond to any natural part of the game, and game rules (e.g. for capture) are not applied after executing Setup nodes. They can be used for any non-standard changes to the game board or to create illegal board positions. The locations specified in the addBlack, addWhite, and remove fields must be pairwise disjoint.

Constructors

Setup 

Fields

addBlack :: Set stone

This node adds the given black pieces to the board; if the board before this setup node had any pieces at the locations given by this field, they are overridden. See also http://www.red-bean.com/sgf/properties.html#AB

addWhite :: Set stone

This node adds the given white pieces to the board; if the board before this setup node had any pieces at the locations given by this field, they are overridden. See also http://www.red-bean.com/sgf/properties.html#AW

remove :: Set Point

This node specifies locations of the board to clear. See also http://www.red-bean.com/sgf/properties.html#AE

toPlay :: Maybe Color

Specify which player should move next. See also http://www.red-bean.com/sgf/properties.html#PL

Instances

Eq stone => Eq (Setup stone) 
Ord stone => Ord (Setup stone) 
(Ord stone, Read stone) => Read (Setup stone) 
Show stone => Show (Setup stone) 

data Annotation extra Source

See also GameNode.

Constructors

Annotation 

Fields

comment :: Maybe String

Free-form text describing the current node. See also http://www.red-bean.com/sgf/properties.html#C

name :: Maybe String

A very short description of the node. Must not contain newlines. See also http://www.red-bean.com/sgf/properties.html#N

hotspot :: Maybe Emphasis

When Just, this node contains something interesting. Viewers should show a message. See also http://www.red-bean.com/sgf/properties.html#HO

value :: Maybe Rational

A quantitative full-board positional judgment. Positive values are good for black, negative for white. See also http://www.red-bean.com/sgf/properties.html#V

judgment :: Maybe (Judgment, Emphasis)

A qualitative full-board positional judgment. See also the GB, GW, DM, and UC properties at http://www.red-bean.com/sgf/properties.html#DM

otherAnnotation :: extra

Game-specific annotations.

Instances

Eq extra => Eq (Annotation extra) 
Ord extra => Ord (Annotation extra) 
Read extra => Read (Annotation extra) 
Show extra => Show (Annotation extra) 

data Markup Source

See also GameNode. Presumably, no arrow in the arrows field should exactly overlap a line specified in the lines field; however, this is not explicitly made illegal by the SGF spec. Note that some fields are marked "inherit". These inheritances are not explicitly tracked; Nothing values indicate that the correct interpretation depends on the node's ancestors, or on the default if no ancestor has a Just value in this field.

Constructors

Markup 

Fields

marks :: Map Point Mark

See also the CR, MA, SL, SQ, and TR properties at http://www.red-bean.com/sgf/properties.html#CR

labels :: Map Point String

Typically, the Strings will be single letters, but that is not guaranteed. Labels must not contain newlines. See also http://www.red-bean.com/sgf/properties.html#LB

arrows :: Set (Point, Point)

Arrows must not start and end at the same point. See also http://www.red-bean.com/sgf/properties.html#AR

lines :: Set (Point, Point)

Lines must not start and end at the same point. Lines must not be repeated; the parser guarantees this by only including pairs (p, q) in which p < q. See also http://www.red-bean.com/sgf/properties.html#LN

dim :: Maybe (Set Point)

Shade out (exactly) the given points. This property is inherited, defaulting to Set.empty. See also http://www.red-bean.com/sgf/properties.html#DD

visible :: Maybe (Set Point)

Make (exactly) the given points visible; do not draw any of the other points. This property is inherited, defaulting to the entire board, and Set.empty resets to the default. See also http://www.red-bean.com/sgf/properties.html#VW

numbering :: Maybe Numbering

How move numbers should be printed on the board. This property is inherited, defaulting to Numbered. See also http://www.red-bean.com/sgf/properties.html#PM

figure :: Maybe Figure

When Just, a new diagram should begin at this move. See also http://www.red-bean.com/sgf/properties.html#FG

data GameInfo ruleSet extra Source

See also GameNode. Each individual game may have at most one node with associated game info. If it has such a node, it must occur at the first node where that game is distinguishable from all of the other games in the tree.

Constructors

GameInfo 

Fields

rankBlack :: Maybe Rank

The strength of the black player. See also http://www.red-bean.com/sgf/properties.html#BR

rankWhite :: Maybe Rank

The strength of the white player. See also http://www.red-bean.com/sgf/properties.html#WR

date :: Set PartialDate

When the game was played. An empty set indicates that no date information is available. See also http://www.red-bean.com/sgf/properties.html#DT

round :: Maybe Round

The round number (for games played in a tournament). See also http://www.red-bean.com/sgf/properties.html#RO

ruleSet :: Maybe (RuleSet ruleSet)

The ruleset used for this game. See also http://www.red-bean.com/sgf/properties.html#RU

timeLimit :: Maybe Rational

The time limit of the game in seconds. See also http://www.red-bean.com/sgf/properties.html#TM

result :: Maybe GameResult

How the game ended. See also http://www.red-bean.com/sgf/properties.html#RE

freeform :: Map GameInfoType String

Miscellaneous properties with no prescribed format.

otherGameInfo :: extra

Certain game types specify additional informational properties, which are stored here.

Instances

(Eq ruleSet, Eq extra) => Eq (GameInfo ruleSet extra) 
(Ord ruleSet, Ord extra) => Ord (GameInfo ruleSet extra) 
(Read ruleSet, Read extra) => Read (GameInfo ruleSet extra) 
(Show ruleSet, Show extra) => Show (GameInfo ruleSet extra) 

data GameInfoType Source

See also GameInfo, especially the freeform field.

Constructors

TeamName Color

See also the BT and WT properties at http://www.red-bean.com/sgf/properties.html#BT

PlayerName Color

See also the PB and PW properties at http://www.red-bean.com/sgf/properties.html#PB

Annotator

The name of the person who annotated the game. See also http://www.red-bean.com/sgf/properties.html#AN

Source

The name of the source, e.g. the title of the book this game came from. See also http://www.red-bean.com/sgf/properties.html#SO

User

The name of the person or program who entered the game. See also http://www.red-bean.com/sgf/properties.html#US

Copyright

See also http://www.red-bean.com/sgf/properties.html#CP

Context

Background information or a summary of the game. See also http://www.red-bean.com/sgf/properties.html#GC

Location

Where the game was played. See also http://www.red-bean.com/sgf/properties.html#PC

Event

The name of the event or tournament at which the game occurred. Additional information about the game (e.g. that it was in the finals) should appear in the round field, not here. See also http://www.red-bean.com/sgf/properties.html#EV

GameName

An easily-remembered moniker for the game. See also http://www.red-bean.com/sgf/properties.html#GN

Opening

A description of the opening moves using the game's vernacular. See also http://www.red-bean.com/sgf/properties.html#ON

Overtime

The overtime rules. See also http://www.red-bean.com/sgf/properties.html#OT

emptyGameNode :: GameNode move stone ruleSet extraGameInfo ()Source

Game-specific types

Go

data MoveGo Source

See also NodeGo and Game.

Constructors

Pass 
Play Point 

data GameInfoGo Source

See also NodeGo and the otherGameInfo field of GameInfo.

Constructors

GameInfoGo 

Fields

handicap :: Maybe Integer

Specifying this does not automatically add stones to the board; a Setup node with a non-empty addBlack field should be specified before any Move nodes. See also http://red-bean.com/sgf/go.html#HA

komi :: Maybe Rational

See also http://red-bean.com/sgf/go.html#KM

type AnnotationGo = Map Color (Set Point)Source

See also NodeGo and the otherAnnotation field of Annotation. This specifies which points are considered territory for each player. See also the TB and TW properties at http://red-bean.com/sgf/go.html#TB

Backgammon

data RuleSetBackgammon Source

Constructors

Crawford

The Crawford rule is being used.

CrawfordGame

This game is the Crawford game.

Jacoby

The Jacoby rule is being used.

type GameInfoBackgammon = [MatchInfo]Source

See also NodeBackgammon and the otherGameInfo field of GameInfo. An empty list indicates that no match information was specified. The order of the list is not significant, and there should be only one value of any given kind of MatchInfo. See also http://red-bean.com/sgf/backgammon.html#MI

data MatchInfo Source

Constructors

Length Integer

The number of points in this match.

GameNumber Integer

The (1-indexed) number of the game within this match.

StartScore Color Integer

The score at the beginning of the game.

OtherMatchInfo String String

An unknown piece of match information.

Lines of Action

data GameInfoLinesOfAction Source

See also NodeLinesOfAction and the otherGameInfo field of GameInfo.

Constructors

GameInfoLinesOfAction 

Fields

initialPositionLOA :: InitialPosition

When this field is Beginning, the viewer should initially show the board position after setup but before any moves. (When End, the viewer should display the final position.) See also http://www.red-bean.com/sgf/loa.html#IP

invertYAxis :: Bool

When this field is True, the board should be displayed with numbers increasing from the bottom to the top of the screen. (When False, the numbers should be decreasing.) See also http://www.red-bean.com/sgf/loa.html#IY

initialPlacement :: InitialPlacement

The initial placement of pieces and rule variation. See also http://www.red-bean.com/sgf/loa.html#SU

Hex

type NodeHex = GameNode () () Void GameInfoHex ()Source

See also TreeHex and Game.

type GameInfoHex = BoolSource

See also NodeHex and the otherGameInfo field of GameInfo. The specification says that trees representing Hex games will mark which position the viewer should initially show by setting this field to True. I think this is probably an error in the specification; there is an obvious conflict between the requirement to put all game information at the first node where a game is uniquely identifiable and the requirement to have a game-information property at the location you want to view first (whenever these two nodes are not the same node, of course). For this reason, Hex game trees may have paths containing two nodes whose game information is not Nothing. See also http://www.red-bean.com/sgf/hex.html#IP

data ViewerSetting Source

Constructors

Tried

Identify future moves that have been tried?

Marked

Show good/bad move markings?

LastMove

Identify the last cell played?

Headings

Display column/row headings?

Lock

Lock the game against new moves?

Octi

For Octi, Black always refers to the first player and White always refers to the second player, regardless of the colors of the actual pieces used by the first and second players.

data GameInfoOcti Source

See also NodeOcti and the otherGameInfo field of GameInfo.

Constructors

GameInfoOcti 

Fields

squaresWhite :: Set Point

Black should be set up with one empty pod on each of these points. An empty set indicates that this property was not specified. See also http://www.red-bean.com/sgf/octi.html#BO

squaresBlack :: Set Point

White should be set up with one empty pod on each of these points. An empty set indicates that this property was not specified. See also http://www.red-bean.com/sgf/octi.html#WO

prongs :: Integer

How many prongs each player starts with. See also http://www.red-bean.com/sgf/octi.html#NP

reserve :: Integer

How many pods each player has in reserve to start with. See also http://www.red-bean.com/sgf/octi.html#NR

superProngs :: Integer

How many superprongs each player starts with. See also http://www.red-bean.com/sgf/octi.html#NS

Other

type NodeOther = GameNode [Word8] [Word8] Void () ()Source

See also TreeOther and Game.

Type aliases

type Point = (Integer, Integer)Source

0-indexed x/y coordinates that start at the top left

type Application = StringSource

See also Game.

type Version = StringSource

See also Game.

type AutoMarkup = BoolSource

See also Game.

type TreeGo = Tree NodeGoSource

See also GameTree.

Enumerations

data RankScale Source

See also Rank. In addition to the standard "kyu" and "dan" ranks, this also supports the non-standard (but common) "pro" ranks.

Constructors

Kyu 
Dan 
Pro 

data Mark Source

See also Markup. With the exception of Selected, the constructor names describe a shape whose outline should be shown over the given point.

Constructors

Circle 
X 
Selected

The exact appearance of this kind of markup is not specified, though suggestions include darkening the colors on these points or inverting the colors on these points.

Square 
Triangle 

data Numbering Source

See also Markup.

Constructors

Unnumbered

Don't print move numbers.

Numbered

Print move numbers as they are.

Modulo100

Subtract enough multiples of 100 from each move number that the first labeled move is below 100.

data VariationType Source

See also Game.

Constructors

Children

Variations are stored in child nodes.

Siblings

Variations are stored in sibling nodes.

data FigureFlag Source

See also Figure.

Constructors

Coordinates

Show coordinates around the edges of the board.

Name

Show the diagram's name.

HiddenMoves

List moves that can't be shown in the diagram as text.

RemoveCaptures

Remove captured stones from the diagram.

Hoshi

Show hoshi dots.

Miscellaneous

data WinType Source

See also GameResult. Games that end normally use Score if there is a natural concept of score differential for that game and OtherWinType if not.

data GameResult Source

See also GameInfo.

Constructors

Draw 
Void 
Unknown 
Win Color WinType

The first argument is the color of the winner.

data Rank Source

See also GameInfo, especially the rankBlack and rankWhite fields. The Eq and Ord instances are the derived ones, and should not be mistaken for semantic equality or ordering.

Constructors

Ranked Integer RankScale (Maybe Certainty)

Ranked in one of the standard ways. Most SGF generators specify the certainty only when it is Uncertain. Therefore, it may be reasonable to treat Nothing and Just Certain identically.

OtherRank String

Any rank that does not fall in the standard categories. This field must not contain newlines.

Instances

data RuleSet a Source

See also GameInfo. Typical values for the a type variable are RuleSetGo, RuleSetBackgammon, and RuleSetOcti. For games where the valid values of the ruleset field is not specified, the a type variable will be Void to ensure that all rulesets are specified as a String.

Constructors

Known !a 
OtherRuleSet String 

Instances

Eq a => Eq (RuleSet a) 
Ord a => Ord (RuleSet a) 
Read a => Read (RuleSet a) 
Show a => Show (RuleSet a) 

data Round Source

See also GameInfo.

Constructors

SimpleRound Integer

Only a round number is given.

FormattedRound Integer String

Both a round number and a type, like "final", "playoff", or "league".

OtherRound String

Round information in an unknown format.

data PartialDate Source

See also GameInfo.

Constructors

Year 

Fields

year :: Integer
 
Month 

Fields

year :: Integer
 
month :: Integer
 
Day 

Fields

year :: Integer
 
month :: Integer
 
day :: Integer
 

data Figure Source

See also Markup.

Constructors

DefaultFigure

Unnamed figure using the application default settings.

NamedDefaultFigure String

Named figure using the application default settings.

NamedFigure String (FigureFlag -> Bool)

Named figure that overrides the application's figure settings.

data Void Source

A type with no constructors used merely to indicate a lack of data.

Instances